- Notifications
You must be signed in to change notification settings - Fork328
Install node and nvm#968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletionpgml-apps/cargo-pgml-components/Cargo.lock
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
2 changes: 1 addition & 1 deletionpgml-apps/cargo-pgml-components/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletionspgml-apps/cargo-pgml-components/src/frontend/javascript.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletionspgml-apps/cargo-pgml-components/src/frontend/nvm.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
export NVM_DIR="$HOME/.nvm" | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | ||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion | ||
${@} |
5 changes: 3 additions & 2 deletionspgml-apps/cargo-pgml-components/src/frontend/sass.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
91 changes: 82 additions & 9 deletionspgml-apps/cargo-pgml-components/src/frontend/tools.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,102 @@ | ||
//! Tools required by us to build stuff. | ||
use crate::util::{debug1, error, execute_command, unwrap_or_exit, warn}; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::process::{exit, Command}; | ||
/// Required tools. | ||
static TOOLS: &[&str] = &["sass", "rollup"]; | ||
static NVM_EXEC: &'static str = "/tmp/pgml-components-nvm.sh"; | ||
static NVM_SOURCE: &'static str = "https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh"; | ||
static NVM_SOURCE_DOWNLOADED: &'static str = "/tmp/pgml-components-nvm-source.sh"; | ||
/// Install any missing tools. | ||
pub fn install() { | ||
install_nvm_entrypoint(); | ||
debug!("installed node entrypoint"); | ||
install_node(); | ||
debug!("installed node"); | ||
for tool in TOOLS { | ||
matchexecute_with_nvm(Command::new(tool).arg("--version")) { | ||
Ok(_) => (), | ||
Err(err) => { | ||
debug1!(err); | ||
warn(&format!("installing {}", tool)); | ||
unwrap_or_exit!(execute_with_nvm( | ||
Command::new("npm").arg("install").arg("-g").arg(tool) | ||
)); | ||
} | ||
} | ||
} | ||
} | ||
/// Execute a command making sure that nvm is available. | ||
pub fn execute_with_nvm(command: &mut Command) -> std::io::Result<String> { | ||
let mut cmd = Command::new(NVM_EXEC); | ||
cmd.arg(command.get_program()); | ||
for arg in command.get_args() { | ||
cmd.arg(arg); | ||
} | ||
execute_command(&mut cmd) | ||
} | ||
/// Install the nvm entrypoint we provide into /tmp | ||
fn install_nvm_entrypoint() { | ||
let mut file = unwrap_or_exit!(File::create(NVM_EXEC)); | ||
unwrap_or_exit!(writeln!(&mut file, "{}", include_str!("nvm.sh"))); | ||
drop(file); | ||
unwrap_or_exit!(execute_command( | ||
Command::new("chmod").arg("+x").arg(NVM_EXEC) | ||
)); | ||
} | ||
/// Install node using nvm | ||
fn install_node() { | ||
debug!("installing node"); | ||
// Node is already installed. | ||
if let Ok(_) = execute_with_nvm(Command::new("node").arg("--version")) { | ||
debug!("node is available"); | ||
return; | ||
} | ||
warn("installing node using nvm"); | ||
debug!("node is not available"); | ||
if let Err(err) = execute_command(Command::new("nvm").arg("--version")) { | ||
debug!("nvm is not available"); | ||
debug1!(err); | ||
// Install Node Version Manager. | ||
if let Err(err) = execute_command( | ||
Command::new("curl") | ||
.arg("-Ls") | ||
.arg(NVM_SOURCE) | ||
.arg("-o") | ||
.arg(NVM_SOURCE_DOWNLOADED), | ||
) { | ||
debug!("curl is not available"); | ||
error("couldn't not download nvm from Github, please do so manually before proceeding"); | ||
debug1!(err); | ||
exit(1); | ||
} else { | ||
if let Err(err) = execute_command(Command::new("bash").arg(NVM_SOURCE_DOWNLOADED)) { | ||
error("couldn't install nvm, please do so manually before proceeding"); | ||
debug1!(err); | ||
exit(1); | ||
} else { | ||
warn("installed nvm"); | ||
} | ||
} | ||
} | ||
if let Err(err) = execute_with_nvm(Command::new("nvm").arg("install").arg("stable")) { | ||
error("couldn't install Node, please do so manually before proceeding"); | ||
debug1!(err); | ||
exit(1); | ||
} else { | ||
warn("installed node") | ||
} | ||
} |
30 changes: 20 additions & 10 deletionspgml-apps/cargo-pgml-components/src/main.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
19 changes: 14 additions & 5 deletionspgml-apps/cargo-pgml-components/src/util.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.