From 451201961837625f13b4ddee4bfbfbec20e50648 Mon Sep 17 00:00:00 2001 From: tim-s-ccs Date: Wed, 2 Feb 2022 13:00:38 +0000 Subject: [PATCH] Add check script Add node version file Make scripts executable --- .nvmrc | 1 + bin/build-release.sh | 0 bin/check-nvmrc.js | 41 +++++++++++++++++++++++++++++++++++++++++ bin/publish-release.sh | 0 package.json | 4 +++- 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 .nvmrc mode change 100644 => 100755 bin/build-release.sh create mode 100755 bin/check-nvmrc.js mode change 100644 => 100755 bin/publish-release.sh diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..58a4133 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +16.13.0 diff --git a/bin/build-release.sh b/bin/build-release.sh old mode 100644 new mode 100755 diff --git a/bin/check-nvmrc.js b/bin/check-nvmrc.js new file mode 100755 index 0000000..573f18d --- /dev/null +++ b/bin/check-nvmrc.js @@ -0,0 +1,41 @@ +#! /usr/bin/env node + +'use strict' + +var fs = require('fs') +var path = require('path') + +fs.readFile(path.join(__dirname, '../.nvmrc'), 'utf8', function (error, data) { + if (error) throw error + var expectedVersion = data.trim() + var currentVersion = process.version.replace('v', '') + + var versionMatchesExactly = expectedVersion === currentVersion + var versionMatchesMajor = expectedVersion.split('.')[0] === currentVersion.split('.')[0] + + if (versionMatchesExactly) { + process.exit() + } + + var nvmInstallText = 'To do this you can install nvm (https://github.com/creationix/nvm) then run `nvm install`.' + + if (versionMatchesMajor) { + console.log('' + + 'Warning: You are using Node.js version ' + currentVersion + ' which we do not use. ' + + '\n\n' + + 'You may encounter issues, consider installing Node.js version ' + expectedVersion + '.' + + '\n\n' + + nvmInstallText + + '') + process.exit() + } + + console.log('' + + 'You are using Node.js version ' + currentVersion + ' which we do not support. ' + + '\n\n' + + 'Please install Node.js version ' + expectedVersion + ' and try again.' + + '\n\n' + + nvmInstallText + + '') + process.exit(1) // exit with a failure mode +}) diff --git a/bin/publish-release.sh b/bin/publish-release.sh old mode 100644 new mode 100755 diff --git a/package.json b/package.json index e058538..591d675 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "scripts": { "build": "rm -rf ./dist/ && tsc", "prepare": "npm run build", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "build-release": "node bin/check-nvmrc.js && ./bin/build-release.sh", + "publish-release": "node bin/check-nvmrc.js && ./bin/publish-release.sh" }, "keywords": [], "author": "",