diff --git a/.ci/generate-changelog.sh b/.ci/generate-changelog.sh
index e295982..7b13a36 100755
--- a/.ci/generate-changelog.sh
+++ b/.ci/generate-changelog.sh
@@ -1,8 +1,8 @@
#!/bin/bash
if [ "$1" = "" ]; then
- echo "Taking version from binary" >&2
- NEXT_VERSION="$(cargo run --quiet -- --version)"
+ echo "No version provided, using 'Unreleased'" >&2
+ NEXT_VERSION="Unreleased"
else
NEXT_VERSION="$1"
fi
diff --git a/.ci/prepare-version.js b/.ci/prepare-version.js
new file mode 100755
index 0000000..eeb99f2
--- /dev/null
+++ b/.ci/prepare-version.js
@@ -0,0 +1,85 @@
+#!/usr/bin/env node
+
+/// @ts-check
+
+const fs = require("fs");
+const cp = require("child_process");
+const path = require("path");
+const cmd = require("cmd-ts");
+const toml = require("toml");
+
+const CARGO_TOML_PATH = path.join(__dirname, "../Cargo.toml");
+
+const command = cmd.command({
+ name: "prepare-version",
+ description: "Prepare a new fnm version",
+ args: {
+ versionType: cmd.positional({
+ displayName: "version type",
+ type: cmd.oneOf(["patch", "minor", "major"]),
+ }),
+ },
+ async handler({ versionType }) {
+ exec("git pull --ff-only");
+ const nextVersion = updateCargoToml(versionType);
+ exec("cargo build --release");
+ exec("./docs/record_screen.sh");
+ exec(`yarn changelog ${nextVersion}`);
+ },
+});
+
+cmd.run(cmd.binary(command), process.argv);
+
+//////////////////////
+// Helper functions //
+//////////////////////
+
+function updateCargoToml(versionType) {
+ const cargoToml = fs.readFileSync(CARGO_TOML_PATH, "utf8");
+ const cargoTomlContents = toml.parse(cargoToml);
+ const currentVersion = cargoTomlContents.package.version;
+ const nextVersion = changeVersion(
+ versionType,
+ cargoTomlContents.package.version
+ );
+
+ const newToml = cargoToml.replace(
+ `version = "${currentVersion}"`,
+ `version = "${nextVersion}"`
+ );
+
+ if (newToml === cargoToml) {
+ console.error("Cargo.toml didn't change, error!");
+ process.exitCode = 1;
+ return;
+ }
+
+ fs.writeFileSync(CARGO_TOML_PATH, newToml, "utf8");
+
+ return nextVersion;
+}
+
+function exec(command, env) {
+ console.log(`$ ${command}`);
+ return cp.execSync(command, {
+ cwd: path.join(__dirname, '..'), // root of repo
+ stdio: "inherit",
+ env: { ...process.env, ...env },
+ });
+}
+
+/**
+ * @param {"patch" | "minor" | "major"} type
+ * @param {string} version
+ */
+function changeVersion(type, version) {
+ const [major, minor, patch] = version.split(".").map((x) => parseInt(x, 10));
+ switch (type) {
+ case "patch":
+ return [major, minor, patch + 1].join(".");
+ case "minor":
+ return [major, minor + 1, 0].join(".");
+ case "major":
+ return [major + 1, 0, 0].join(".");
+ }
+}
diff --git a/.node-version b/.node-version
new file mode 100644
index 0000000..b65ea2e
--- /dev/null
+++ b/.node-version
@@ -0,0 +1 @@
+v12.6.0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3b9891a..b691955 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,4 @@
-## fnm 1.22.0 (2020-10-07)
+## 1.22.0 (2020-10-07)
#### New Feature 🎉
diff --git a/README.md b/README.md
index 7adebee..9cfbfd0 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@
:rocket: Built with speed in mind
-:thinking: Works with `.nvmrc` and `.node-version` files
+:thinking: Works with `.node-version` and `.nvmrc` files
## Installation
@@ -92,11 +92,11 @@ You can always use `fnm --help` to read the docs:
### `fnm install [VERSION]`
-Installs `[VERSION]`. If no version provided, it will install the version specified in the `.nvmrc` file located in the current working directory.
+Installs `[VERSION]`. If no version provided, it will install the version specified in the `.node-version` or `.nvmrc` files located in the current working directory.
### `fnm use [VERSION]`
-Activates `[VERSION]` as the current Node version. If no version provided, it will activate the version specified in the `.nvmrc` or `.node-version` file located in the current working directory.
+Activates `[VERSION]` as the current Node version. If no version provided, it will activate the version specified in the `.node-version` or `.nvmrc` file located in the current working directory.
### `fnm current`
@@ -129,7 +129,7 @@ Prints the required shell commands in order to configure your shell, Bash compli
- Providing `--multi` will output the multishell support, allowing a different current Node version per shell
- Providing `--shell=fish` will output the Fish-compliant version. Omitting it and `fnm` will try to infer the current shell based on the process tree
- Providing `--node-dist-mirror="https://npm.taobao.org/dist"` will use the Chinese mirror of Node.js
-- Providing `--use-on-cd` will also output a script that will automatically change the node version if a `.nvmrc`/`.node-version` file is found
+- Providing `--use-on-cd` will also output a script that will automatically change the node version if a `.node-version`/`.nvmrc` file is found
- Providing `--fnm-dir="/tmp/fnm"` will install and use versions in `/tmp/fnm` directory
## Future Plans
diff --git a/docs/fnm.svg b/docs/fnm.svg
index 67881a9..782d026 100644
--- a/docs/fnm.svg
+++ b/docs/fnm.svg
@@ -1 +1 @@
-
\ No newline at end of file
+✡✡eval✡eval`fnmenv`✡f✡fn✡fnm✡fnm--versionfnm1.22.0✡cat✡cat.node-versionv12.6.0✡fnminstallInstallingNodev12.6.0✡fnmuseUsingNodev12.6.0✡node✡node-v✡e✡ev✡eva✡eval`✡eval`f✡eval`fn✡eval`fnm✡eval`fnme✡eval`fnmen✡eval`fnmenv✡fnm-✡fnm--✡fnm--v✡fnm--ve✡fnm--ver✡fnm--vers✡fnm--versi✡fnm--versio✡c✡ca✡cat.✡cat.n✡cat.no✡cat.nod✡cat.node✡cat.node-v✡cat.node-ve✡cat.node-ver✡cat.node-vers✡cat.node-versi✡cat.node-versio✡fnmi✡fnmin✡fnmins✡fnminst✡fnminsta✡fnminstal✡fnmu✡fnmus✡n✡no✡nod✡node-
\ No newline at end of file
diff --git a/docs/record_screen.sh b/docs/record_screen.sh
index 892d268..f278e9f 100755
--- a/docs/record_screen.sh
+++ b/docs/record_screen.sh
@@ -1,10 +1,10 @@
#!/bin/bash
-DIRECTORY=`dirname $0`
+DIRECTORY="$(dirname "$0")"
function setup_binary() {
- export TEMP_DIR=$(mktemp -d -t fnm)
- cp _esy/default/build/default/executable/FnmApp.exe $TEMP_DIR/fnm
+ TEMP_DIR="$(mktemp -d -t fnm)"
+ cp ./target/release/fnm "$TEMP_DIR/fnm"
export PATH=$TEMP_DIR:$PATH
export FNM_DIR=$TEMP_DIR/.fnm
}
@@ -13,7 +13,7 @@ setup_binary
RECORDING_PATH=$DIRECTORY/screen_recording
-(rm -rf $RECORDING_PATH &> /dev/null || true)
+(rm -rf "$RECORDING_PATH" &> /dev/null || true)
-asciinema rec -c $DIRECTORY/recorded_screen_script.sh $RECORDING_PATH
-cat $RECORDING_PATH | sed "s@$TEMP_DIR@~@g" | svg-term --window --out $DIRECTORY/fnm.svg --height=17 --width=70
+asciinema rec -c "$DIRECTORY/recorded_screen_script.sh" "$RECORDING_PATH"
+sed "s@$TEMP_DIR@~@g" "$RECORDING_PATH" | svg-term --window --out "$DIRECTORY/fnm.svg" --height=17 --width=70
diff --git a/docs/recorded_screen_script.sh b/docs/recorded_screen_script.sh
index 2a5cf63..9c40eeb 100755
--- a/docs/recorded_screen_script.sh
+++ b/docs/recorded_screen_script.sh
@@ -9,16 +9,14 @@ function type() {
echo $* | pv -qL $[10+(-2 + RANDOM%5)]
}
-cd ./feature_tests/nvmrc
-
type 'eval `fnm env`'
eval `fnm env`
type 'fnm --version'
fnm --version
-type 'cat .nvmrc'
-cat .nvmrc
+type 'cat .node-version'
+cat .node-version
type 'fnm install'
fnm install
@@ -30,4 +28,4 @@ type 'node -v'
node -v
sleep 2
-echo ""
\ No newline at end of file
+echo ""
diff --git a/package.json b/package.json
index 24d1f48..f247329 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,8 @@
"author": "Gal Schlezinger ",
"license": "GPLv3",
"scripts": {
- "changelog": "./.ci/generate-changelog.sh"
+ "changelog": "./.ci/generate-changelog.sh",
+ "version:prepare": "./.ci/prepare-version.js"
},
"changelog": {
"repo": "Schniz/fnm",
@@ -18,7 +19,9 @@
}
},
"devDependencies": {
+ "cmd-ts": "^0.6.4",
"lerna-changelog": "^1.0.1",
- "prettier": "^2.1.2"
+ "prettier": "^2.1.2",
+ "toml": "^3.0.0"
}
}
diff --git a/yarn.lock b/yarn.lock
index 098a949..2ed2928 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -170,6 +170,15 @@ cliui@^6.0.0:
strip-ansi "^6.0.0"
wrap-ansi "^6.2.0"
+cmd-ts@^0.6.4:
+ version "0.6.4"
+ resolved "https://registry.npmjs.org/cmd-ts/-/cmd-ts-0.6.4.tgz#3390ec94d5f9f25fe5745b7dffb34842701b96ae"
+ integrity sha512-z1xFprGcUjFK8qCITdvHymVZtYyuirezqVRO8K+JGv24Lr+hyQrToPTmGlvWtvEZsHPYfyqNt5+Es9FLthCgsQ==
+ dependencies:
+ chalk "^3.0.0"
+ debug "^4.1.1"
+ strip-ansi "^6.0.0"
+
color-convert@^1.9.0:
version "1.9.3"
resolved "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
@@ -227,7 +236,7 @@ cross-spawn@^6.0.0:
shebang-command "^1.2.0"
which "^1.2.9"
-debug@4, debug@^4.1.0:
+debug@4, debug@^4.1.0, debug@^4.1.1:
version "4.2.0"
resolved "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz#7f150f93920e94c58f5574c2fd01a3110effe7f1"
integrity sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==
@@ -980,6 +989,11 @@ thenify-all@^1.0.0:
dependencies:
any-promise "^1.0.0"
+toml@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz#342160f1af1904ec9d204d03a5d61222d762c5ee"
+ integrity sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==
+
unique-filename@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz#1d69769369ada0583103a1e6ae87681b56573230"