Skip to content

Commit

Permalink
feat: added "update" CLI command
Browse files Browse the repository at this point in the history
  • Loading branch information
slvnperron committed May 1, 2018
1 parent d96c62a commit f9c3143
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
12 changes: 3 additions & 9 deletions packages/core/botpress/package.json
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -159,9 +155,7 @@
},
"watch": {
"compile": {
"patterns": [
"src"
],
"patterns": ["src"],
"extensions": "js,jsx,scss,json,html"
}
}
Expand Down
9 changes: 8 additions & 1 deletion packages/core/botpress/src/cli/index.js
Expand Up @@ -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'
Expand Down Expand Up @@ -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 <fromVersion>')
.description('Migrates the current bot from version X')
Expand All @@ -82,7 +89,7 @@ program

program
.command('cloud-pair <api-token>')
.description('')
.description('Pairs your local bot with the Botpress Cloud (supercharges your bot)')
.option(
'--endpoint <endpoint-url>',
`Change the Botpress Cloud server endpoint. Default: "${defaultBotpressCloudEndpoint}"`,
Expand Down
37 changes: 37 additions & 0 deletions 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!}`)
}
}
8 changes: 8 additions & 0 deletions packages/core/botpress/yarn.lock
Expand Up @@ -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"
Expand Down

0 comments on commit f9c3143

Please sign in to comment.