feat: global installation and update check (#6795)

* Add global installation option

* Add update check for global install
This commit is contained in:
Saad Irfan ⚡️
2021-07-15 04:02:30 +05:00
committed by GitHub
parent f10d370759
commit 643d7d7977
2 changed files with 27 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ const ora = require('ora');
const pkg = require('../package.json');
const checkRequirements = require('./check-requirements');
const checkForUpdate = require('update-check');
const program = new commander.Command(pkg.name);
@@ -94,5 +95,25 @@ async function create(directory) {
process.exit(1);
}
let update;
try {
update = await checkForUpdate(pkg);
} catch (err) {
// eslint-disable-next-line no-console
console.log(`Error: ${err.stderr}`);
}
if (update) {
// eslint-disable-next-line no-console
console.log();
// eslint-disable-next-line no-console
console.log(chalk.yellow.bold(`A new version of \`${pkg.name}\` is available!`));
// eslint-disable-next-line no-console
console.log('You can update by running: ' + chalk.cyan(`npm i -g ${pkg.name}@latest`));
// eslint-disable-next-line no-console
console.log();
}
process.exit(0);
}

View File

@@ -3,7 +3,10 @@
"version": "9.0.0-rc.84",
"description": "A small installer util that will create a directory, add boilerplate folders, and install Directus through npm.",
"main": "lib/index.js",
"bin": "./lib/index.js",
"bin": {
"create-directus-project": "./lib/index.js",
"cdp": "./lib/index.js"
},
"keywords": [
"directus",
"installer"
@@ -15,7 +18,8 @@
"commander": "^8.0.0",
"execa": "^5.1.1",
"fs-extra": "^10.0.0",
"ora": "^5.4.0"
"ora": "^5.4.0",
"update-check": "^1.5.4"
},
"gitHead": "24621f3934dc77eb23441331040ed13c676ceffd"
}