Skip to content
Snippets Groups Projects
Commit e0aee236 authored by Moul's avatar Moul
Browse files

[enh] #1426: Allow a wider range of Node.js versions

Introduce https://crates.io/crates/version-compare
Allow Node.js version between 10.18.0 and 11.0.0
https://nodejs.org/en/download/releases/
parent 28fa91de
No related branches found
No related tags found
No related merge requests found
...@@ -3392,6 +3392,12 @@ version = "0.8.2" ...@@ -3392,6 +3392,12 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version-compare"
version = "0.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c18c859eead79d8b95d09e4678566e8d70105c4e7b251f707a03df32442661b"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.3" version = "0.9.3"
...@@ -3548,6 +3554,7 @@ dependencies = [ ...@@ -3548,6 +3554,7 @@ dependencies = [
"anyhow", "anyhow",
"run_script", "run_script",
"structopt", "structopt",
"version-compare",
"version_check", "version_check",
] ]
......
...@@ -17,3 +17,4 @@ anyhow = "1.0.32" ...@@ -17,3 +17,4 @@ anyhow = "1.0.32"
run_script = "0.6.3" run_script = "0.6.3"
structopt = "0.3.18" structopt = "0.3.18"
version_check = "0.9.2" version_check = "0.9.2"
version-compare = "0.0.11"
...@@ -13,12 +13,16 @@ ...@@ -13,12 +13,16 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
extern crate version_compare;
use anyhow::Result; use anyhow::Result;
use std::process::{Command, Output}; use std::process::{Command, Output};
use structopt::StructOpt; use structopt::StructOpt;
use version_compare::{Version};
const MIN_RUST_VERSION: &str = "1.51.0"; const MIN_RUST_VERSION: &str = "1.51.0";
const NODE_VERSION: &str = "10.22.1"; const MIN_NODE_VERSION: &str = "10.18.0";
const MAX_NODE_VERSION: &str = "11.0.0";
#[derive(StructOpt)] #[derive(StructOpt)]
struct DuniterXTask { struct DuniterXTask {
...@@ -54,18 +58,20 @@ fn main() -> Result<()> { ...@@ -54,18 +58,20 @@ fn main() -> Result<()> {
if !args.skip_npm { if !args.skip_npm {
println!("Check node version …"); println!("Check node version …");
if exec_and_get_stdout(Command::new("node").arg("-v")) let node_vers: String = exec_and_get_stdout(Command::new("node").arg("-v"))
.unwrap_or_default() .unwrap_or_default();
.trim_end() let node_vers_cut: version_compare::Version = Version::from(&node_vers[1..node_vers.len()]).unwrap();
!= format!("v{}", NODE_VERSION) let min_node_vers: version_compare::Version = Version::from(MIN_NODE_VERSION).unwrap();
let max_node_vers: version_compare::Version = Version::from(MAX_NODE_VERSION).unwrap();
if node_vers_cut < min_node_vers || max_node_vers <= node_vers_cut
{ {
eprintln!( eprintln!(
"Duniter requires node v{} exactly. Please install node v{} (you can use nvm).", "Duniter requires node between v{} and v{}. Please install a correct node version (you can use nvm). Current version {}",
NODE_VERSION, NODE_VERSION MIN_NODE_VERSION, MAX_NODE_VERSION, node_vers
); );
std::process::exit(1); std::process::exit(1);
} else { } else {
println!("Node v{} already installed ✔", NODE_VERSION); println!("Node {} installed compatible version ✔", node_vers);
} }
} }
match args.command { match args.command {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment