From f9c31434d7d5441d71cdee20447ddab6c9124241 Mon Sep 17 00:00:00 2001 From: Sylvain Perron Date: Tue, 1 May 2018 13:51:05 -0400 Subject: [PATCH] feat: added "update" CLI command --- packages/core/botpress/package.json | 12 ++------ packages/core/botpress/src/cli/index.js | 9 +++++- packages/core/botpress/src/cli/update.js | 37 ++++++++++++++++++++++++ packages/core/botpress/yarn.lock | 8 +++++ 4 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 packages/core/botpress/src/cli/update.js diff --git a/packages/core/botpress/package.json b/packages/core/botpress/package.json index 5dd7bd9033f..e3636a84bc8 100644 --- a/packages/core/botpress/package.json +++ b/packages/core/botpress/package.json @@ -15,7 +15,7 @@ "babel-polyfill": "^6.23.0", "bluebird": "^3.4.6", "body-parser": "^1.15.2", - "chalk": "^1.1.3", + "chalk": "^2.4.1", "commander": "^2.9.0", "compression": "^1.7.1", "dotenv": "^4.0.0", @@ -145,11 +145,7 @@ "license": "AGPL-3.0", "main": "lib/node.bundle.js", "repository": "git+https://github.com/botpress/botpress.git", - "os": [ - "darwin", - "linux", - "win32" - ], + "os": ["darwin", "linux", "win32"], "scripts": { "prepublishOnly": "npm run compile-prod", "compile": "./build.sh", @@ -159,9 +155,7 @@ }, "watch": { "compile": { - "patterns": [ - "src" - ], + "patterns": ["src"], "extensions": "js,jsx,scss,json,html" } } diff --git a/packages/core/botpress/src/cli/index.js b/packages/core/botpress/src/cli/index.js index 1fd463b2e76..7401cfcddb9 100644 --- a/packages/core/botpress/src/cli/index.js +++ b/packages/core/botpress/src/cli/index.js @@ -3,6 +3,7 @@ import program from 'commander' import init from './init' import start from './start' import create from './create' +import update from './update' import migrate from './migrate' import list from './list' import { login, logout } from './auth' @@ -56,6 +57,12 @@ program .description('Create a new module for development or distribution') .action(create) +program + .command('update [version]') + .alias('up') + .description('Updates your bot and all the modules to a specific version') + .action(update) + program .command('migrate ') .description('Migrates the current bot from version X') @@ -82,7 +89,7 @@ program program .command('cloud-pair ') - .description('') + .description('Pairs your local bot with the Botpress Cloud (supercharges your bot)') .option( '--endpoint ', `Change the Botpress Cloud server endpoint. Default: "${defaultBotpressCloudEndpoint}"`, diff --git a/packages/core/botpress/src/cli/update.js b/packages/core/botpress/src/cli/update.js new file mode 100644 index 00000000000..911ee457810 --- /dev/null +++ b/packages/core/botpress/src/cli/update.js @@ -0,0 +1,37 @@ +import Confirm from 'prompt-confirm' +import chalk from 'chalk' +import path from 'path' +import fs from 'fs' +import { execSync } from 'child_process' + +import { print } from '../util' +import createModules from '../modules' + +module.exports = async version => { + version = version || 'latest' + + const modulesManager = createModules(null, './', null) + const packages = ['botpress', ...modulesManager.listInstalled()] + + let cmdRest = '' + + for (const pkg of packages) { + const confirm = await new Confirm(chalk` +Do you want to update {yellow "${pkg}"} to version {underline ${version}}?`).run() + if (confirm) { + cmdRest += `${pkg}@${version} ` + } + } + + if (cmdRest.length) { + console.log(chalk`===> {underline Installing dependencies, please wait...}`) + + if (fs.existsSync(path.resolve('./yarn.lock'))) { + execSync(`yarn add ${cmdRest}`) + } else { + execSync(`npm install --save ${cmdRest}`) + } + + console.log(chalk`{green.bold Done!}`) + } +} diff --git a/packages/core/botpress/yarn.lock b/packages/core/botpress/yarn.lock index 30aa2902d95..d4b159b9068 100644 --- a/packages/core/botpress/yarn.lock +++ b/packages/core/botpress/yarn.lock @@ -1622,6 +1622,14 @@ chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.1: escape-string-regexp "^1.0.5" supports-color "^5.3.0" +chalk@^2.4.1: + version "2.4.1" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e" + dependencies: + ansi-styles "^3.2.1" + escape-string-regexp "^1.0.5" + supports-color "^5.3.0" + choices-separator@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/choices-separator/-/choices-separator-2.0.0.tgz#92fd1763182d79033f5c5c51d0ba352e5567c696"