From 7265cae8dda71478f0e602d231c9d066d9d1c86a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Sep 2019 16:47:23 +0200 Subject: [PATCH 1/7] Complete refactoring --- .gitignore | 1 + package.json | 5 +- packages/botonic-cli/package.json | 4 +- packages/botonic-cli/src/botonicAPIService.ts | 4 +- packages/botonic-cli/src/commands/deploy.ts | 56 +++++++++++-------- packages/botonic-cli/src/commands/new.ts | 22 +++++--- .../templates/tutorial/package.json | 2 +- 7 files changed, 60 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 0bcdd033d2..3efdf816a0 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ tmp/ .yalc/ yalc.lock .eslintcache + diff --git a/package.json b/package.json index 3f06aea65b..30fdf5566d 100644 --- a/package.json +++ b/package.json @@ -19,5 +19,8 @@ }, "workspaces": [ "packages/*" - ] + ], + "dependencies": { + "rimraf": "^3.0.0" + } } diff --git a/packages/botonic-cli/package.json b/packages/botonic-cli/package.json index 1dbb84b42c..7ac98e6b35 100644 --- a/packages/botonic-cli/package.json +++ b/packages/botonic-cli/package.json @@ -11,9 +11,11 @@ "@oclif/config": "^1", "@oclif/plugin-help": "^2", "analytics-node": "^3.3.0", + "bestzip": "^2.1.4", "colors": "^1.2.1", "folder-hash": "^3.0.0", "form-data": "^2.3.2", + "fs-extra": "^8.1.0", "inquirer": "^6.3.1", "ora": "^3.0.0", "tslib": "^1" @@ -54,7 +56,7 @@ }, "repository": "hubtype/botonic", "scripts": { - "build": "rm -rf lib && tsc", + "build": "rimraf lib && tsc", "postpack": "rm -f oclif.manifest.json npm-shrinkwrap.json", "posttest": "tslint -p test -t stylish", "prepack": "oclif-dev manifest && oclif-dev readme && npm shrinkwrap", diff --git a/packages/botonic-cli/src/botonicAPIService.ts b/packages/botonic-cli/src/botonicAPIService.ts index 1db4e4b34c..7010ffef9a 100644 --- a/packages/botonic-cli/src/botonicAPIService.ts +++ b/packages/botonic-cli/src/botonicAPIService.ts @@ -1,7 +1,7 @@ import { join, resolve } from 'path' import * as fs from 'fs' import { homedir } from 'os' -import axios from 'axios' +import axios, {Method} from 'axios' import * as colors from 'colors' const FormData = require('form-data') const util = require('util') @@ -152,7 +152,7 @@ export class BotonicAPIService { async api( path: string, body: any = null, - method: string = 'get', + method: Method = 'get', headers: any | null = null, params: any = null ): Promise { diff --git a/packages/botonic-cli/src/commands/deploy.ts b/packages/botonic-cli/src/commands/deploy.ts index 3ef192e2f5..257dfa3793 100644 --- a/packages/botonic-cli/src/commands/deploy.ts +++ b/packages/botonic-cli/src/commands/deploy.ts @@ -3,15 +3,17 @@ import { prompt } from 'inquirer' import * as colors from 'colors' const fs = require('fs') +const fsExtra = require('fs-extra') const ora = require('ora') const util = require('util') +const zip = require('bestzip') const exec = util.promisify(require('child_process').exec) import { BotonicAPIService } from '../botonicAPIService' -import { track, sleep } from '../utils' +import { sleep, track } from '../utils' -var force = false -var npmCommand: string | undefined +let force = false +let npmCommand: string | undefined export default class Run extends Command { static description = 'Deploy Botonic project to hubtype.com' @@ -38,10 +40,10 @@ Uploading... static args = [{ name: 'bot_name' }] - private botonicApiService: BotonicAPIService = new BotonicAPIService() + private readonly botonicApiService: BotonicAPIService = new BotonicAPIService() async run() { - const { args, flags } = this.parse(Run) + const { flags } = this.parse(Run) track('Deployed Botonic CLI') force = flags.force ? flags.force : false @@ -50,7 +52,7 @@ Uploading... if (!this.botonicApiService.oauth) await this.signupFlow() else if (botName) { - this.deployBotFromFlag(botName) + await this.deployBotFromFlag(botName) } else await this.deployBotFlow() } @@ -62,13 +64,13 @@ Uploading... await this.botonicApiService.getMoreBots(bots, nextBots) } let bot = bots.filter(b => b.name === botName)[0] - if (bot == undefined) { + if (bot === undefined) { console.log(colors.red(`Bot ${botName} doesn't exist.`)) console.log('\nThese are the available options:') bots.map(b => console.log(` > ${b.name}`)) } else { this.botonicApiService.setCurrentBot(bot) - this.deploy() + await this.deploy() } } @@ -83,10 +85,10 @@ Uploading... name: 'signupConfirmation', message: 'You need to login before deploying your bot.\nDo you have a Hubtype account already?', - choices: choices + choices } ]).then((inp: any) => { - if (inp.signupConfirmation == choices[1]) return this.askLogin() + if (inp.signupConfirmation === choices[1]) return this.askLogin() else return this.askSignup() }) } @@ -120,8 +122,9 @@ Uploading... } async deployBotFlow() { - if (!this.botonicApiService.bot) return this.newBotFlow() - else { + if (!this.botonicApiService.bot) { + return this.newBotFlow() + } else { let resp = await this.botonicApiService.getBots() let nextBots = resp.data.next let bots = resp.data.results @@ -131,7 +134,7 @@ Uploading... // Show the current bot in credentials at top of the list let first_id = this.botonicApiService.bot.id bots.sort(function(x, y) { - return x.id == first_id ? -1 : y.id == first_id ? 1 : 0 + return x.id === first_id ? -1 : y.id === first_id ? 1 : 0 }) return this.selectExistentBot(bots) } @@ -268,8 +271,15 @@ Uploading... text: 'Creating bundle...', spinner: 'bouncingBar' }).start() - let zip_cmd = `zip -r botonic_bundle.zip dist` - let zip_out = await exec(zip_cmd) + try { + await zip({ + source: 'dist/*', + destination: './botonic_bundle.zip' + }) + } catch(err) { + console.log(err) + return + } const zip_stats = fs.statSync('botonic_bundle.zip') spinner.succeed() if (zip_stats.size >= 10 * 10 ** 6) { @@ -280,7 +290,7 @@ Uploading... ) ) track('Deploy Botonic Zip Error') - await exec('rm botonic_bundle.zip') + fsExtra.remove('botonic_bundle.zip').catch(err => console.log(err)) return } spinner = new ora({ @@ -288,7 +298,7 @@ Uploading... spinner: 'bouncingBar' }).start() try { - var deploy = await this.botonicApiService.deployBot( + let deploy = await this.botonicApiService.deployBot( 'botonic_bundle.zip', force ) @@ -315,7 +325,7 @@ Uploading... console.log(colors.red('There was a problem in the deploy:')) console.log(deploy_status.data.error) track('Deploy Botonic Error', { error: deploy_status.data.error }) - await exec('rm botonic_bundle.zip') + await fsExtra.remove('botonic_bundle.zip') return } } @@ -325,7 +335,7 @@ Uploading... console.log(colors.red('There was a problem in the deploy:')) console.log(err) track('Deploy Botonic Error', { error: err }) - await exec('rm botonic_bundle.zip') + fsExtra.remove('botonic_bundle.zip').catch(err => console.log(err)) return } try { @@ -339,15 +349,17 @@ Uploading... }` console.log(links) } else { - this.displayProviders(providers) + await this.displayProviders(providers) } } catch (e) { track('Deploy Botonic Provider Error', { error: e }) console.log(colors.red(`There was an error getting the providers: ${e}`)) } try { - await exec('rm botonic_bundle.zip') - } catch (e) {} + await fsExtra.remove('botonic_bundle.zip') + } catch(err) { + console.log(err) + } this.botonicApiService.beforeExit() } } diff --git a/packages/botonic-cli/src/commands/new.ts b/packages/botonic-cli/src/commands/new.ts index 934a56ff1f..19912fbd32 100644 --- a/packages/botonic-cli/src/commands/new.ts +++ b/packages/botonic-cli/src/commands/new.ts @@ -1,7 +1,7 @@ import { Command } from '@oclif/command' import { resolve } from 'path' -import { prompt } from 'inquirer' import * as colors from 'colors' +import { prompt } from 'inquirer' import { BotonicAPIService } from '../botonicAPIService' import { track } from '../utils' @@ -9,6 +9,7 @@ import { track } from '../utils' const util = require('util') const ora = require('ora') const exec = util.promisify(require('child_process').exec) +const fsExtra = require('fs-extra') export default class Run extends Command { static description = 'Create a new Botonic project' @@ -70,7 +71,7 @@ Creating... async run() { track('Created Botonic Bot CLI') - const { args, flags } = this.parse(Run) + const { args } = this.parse(Run) let template = '' if (!args.templateName) { await this.selectBotName().then((resp: any) => { @@ -85,7 +86,6 @@ Creating... if (botExists.length) { template = args.templateName } else { - let template_names = this.templates.map((t: any) => t.name) console.log( colors.red( 'Template ${args.templateName} does not exist, please choose one of ${template_names}.' @@ -94,14 +94,17 @@ Creating... return } } - let botPath = resolve(template) let templatePath = `${__dirname}/../../templates/${template}` let spinner = new ora({ text: 'Copying files...', spinner: 'bouncingBar' }).start() - let copyFolderCommand = `cp -r ${templatePath} ${args.name}` - let copy_out = await exec(copyFolderCommand) + try { + await fsExtra.copy(`${templatePath}`, `${args.name}`) + } catch (err) { + console.log(err) + return + } spinner.succeed() process.chdir(args.name) spinner = new ora({ @@ -113,7 +116,12 @@ Creating... spinner.succeed() await this.botonicApiService.buildIfChanged(false) this.botonicApiService.beforeExit() - await exec('mv ../.botonic.json .') + try { + await fsExtra.move('../.botonic.json', './botonic.json') + } catch (err) { + console.log(err) + return + } let cd_cmd = colors.bold(`cd ${args.name}`) let run_cmd = colors.bold('botonic serve') let deploy_cmd = colors.bold('botonic deploy') diff --git a/packages/botonic-cli/templates/tutorial/package.json b/packages/botonic-cli/templates/tutorial/package.json index 998d5f9cba..c9665283a1 100644 --- a/packages/botonic-cli/templates/tutorial/package.json +++ b/packages/botonic-cli/templates/tutorial/package.json @@ -15,7 +15,7 @@ } }, "dependencies": { - "@botonic/react": "0.9.0" + "@botonic/react": "0.9.0-alpha.7" }, "devDependencies": { "babel-jest": "^24.1.0", From 960b8b95785c096a9df9332e2b37b8d31614d41c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Sep 2019 17:02:44 +0200 Subject: [PATCH 2/7] Error messages - display in red --- packages/botonic-cli/src/commands/deploy.ts | 8 ++++---- packages/botonic-cli/src/commands/new.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/botonic-cli/src/commands/deploy.ts b/packages/botonic-cli/src/commands/deploy.ts index 257dfa3793..291d9ae63a 100644 --- a/packages/botonic-cli/src/commands/deploy.ts +++ b/packages/botonic-cli/src/commands/deploy.ts @@ -277,7 +277,7 @@ Uploading... destination: './botonic_bundle.zip' }) } catch(err) { - console.log(err) + console.log(colors.red(err)) return } const zip_stats = fs.statSync('botonic_bundle.zip') @@ -290,7 +290,7 @@ Uploading... ) ) track('Deploy Botonic Zip Error') - fsExtra.remove('botonic_bundle.zip').catch(err => console.log(err)) + fsExtra.remove('botonic_bundle.zip').catch(err => console.log(colors.red(err))) return } spinner = new ora({ @@ -335,7 +335,7 @@ Uploading... console.log(colors.red('There was a problem in the deploy:')) console.log(err) track('Deploy Botonic Error', { error: err }) - fsExtra.remove('botonic_bundle.zip').catch(err => console.log(err)) + fsExtra.remove('botonic_bundle.zip').catch(err => console.log(colors.red(err))) return } try { @@ -358,7 +358,7 @@ Uploading... try { await fsExtra.remove('botonic_bundle.zip') } catch(err) { - console.log(err) + console.log(colors.red(err)) } this.botonicApiService.beforeExit() } diff --git a/packages/botonic-cli/src/commands/new.ts b/packages/botonic-cli/src/commands/new.ts index 19912fbd32..eed431fe7a 100644 --- a/packages/botonic-cli/src/commands/new.ts +++ b/packages/botonic-cli/src/commands/new.ts @@ -102,7 +102,7 @@ Creating... try { await fsExtra.copy(`${templatePath}`, `${args.name}`) } catch (err) { - console.log(err) + console.log(colors.red(err)) return } spinner.succeed() @@ -119,7 +119,7 @@ Creating... try { await fsExtra.move('../.botonic.json', './botonic.json') } catch (err) { - console.log(err) + console.log(colors.red(err)) return } let cd_cmd = colors.bold(`cd ${args.name}`) From a5ebdca86032ac6446f0d07dbe3c0d81a1720895 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Sep 2019 11:55:13 +0200 Subject: [PATCH 3/7] Refactoring after code review + correctly display error info --- package.json | 8 ++--- packages/botonic-cli/src/commands/deploy.ts | 36 +++++++++------------ packages/botonic-cli/src/commands/new.ts | 10 +++--- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 30fdf5566d..6db5422359 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "lerna": "^3.4.0", "ts-node": "5", "tslib": "^1.9.0", - "typescript": "^3.5.3" + "typescript": "^3.5.3", + "rimraf": "^3.0.0" }, "engines": { "node": ">=8.0.0" @@ -19,8 +20,5 @@ }, "workspaces": [ "packages/*" - ], - "dependencies": { - "rimraf": "^3.0.0" - } + ] } diff --git a/packages/botonic-cli/src/commands/deploy.ts b/packages/botonic-cli/src/commands/deploy.ts index 291d9ae63a..5e4180c5f6 100644 --- a/packages/botonic-cli/src/commands/deploy.ts +++ b/packages/botonic-cli/src/commands/deploy.ts @@ -2,16 +2,13 @@ import { Command, flags } from '@oclif/command' import { prompt } from 'inquirer' import * as colors from 'colors' -const fs = require('fs') -const fsExtra = require('fs-extra') -const ora = require('ora') -const util = require('util') -const zip = require('bestzip') -const exec = util.promisify(require('child_process').exec) - import { BotonicAPIService } from '../botonicAPIService' import { sleep, track } from '../utils' +const fs = require('fs-extra') +const ora = require('ora') +const zip = require('bestzip') + let force = false let npmCommand: string | undefined @@ -64,13 +61,13 @@ Uploading... await this.botonicApiService.getMoreBots(bots, nextBots) } let bot = bots.filter(b => b.name === botName)[0] - if (bot === undefined) { + if (bot) { + this.botonicApiService.setCurrentBot(bot) + await this.deploy() + } else { console.log(colors.red(`Bot ${botName} doesn't exist.`)) console.log('\nThese are the available options:') bots.map(b => console.log(` > ${b.name}`)) - } else { - this.botonicApiService.setCurrentBot(bot) - await this.deploy() } } @@ -88,8 +85,7 @@ Uploading... choices } ]).then((inp: any) => { - if (inp.signupConfirmation === choices[1]) return this.askLogin() - else return this.askSignup() + return inp.signupConfirmation === choices[1] ? this.askLogin() : this.askSignup() }) } @@ -132,10 +128,8 @@ Uploading... await this.botonicApiService.getMoreBots(bots, nextBots) } // Show the current bot in credentials at top of the list - let first_id = this.botonicApiService.bot.id - bots.sort(function(x, y) { - return x.id === first_id ? -1 : y.id === first_id ? 1 : 0 - }) + let firstId = this.botonicApiService.bot.id + bots.sort((x, y) => x.id === firstId ? -1 : y.id === firstId ? 1 : 0) return this.selectExistentBot(bots) } } @@ -290,7 +284,7 @@ Uploading... ) ) track('Deploy Botonic Zip Error') - fsExtra.remove('botonic_bundle.zip').catch(err => console.log(colors.red(err))) + fs.remove('botonic_bundle.zip').catch(err => console.log(colors.red(err))) return } spinner = new ora({ @@ -325,7 +319,7 @@ Uploading... console.log(colors.red('There was a problem in the deploy:')) console.log(deploy_status.data.error) track('Deploy Botonic Error', { error: deploy_status.data.error }) - await fsExtra.remove('botonic_bundle.zip') + await fs.remove('botonic_bundle.zip') return } } @@ -335,7 +329,7 @@ Uploading... console.log(colors.red('There was a problem in the deploy:')) console.log(err) track('Deploy Botonic Error', { error: err }) - fsExtra.remove('botonic_bundle.zip').catch(err => console.log(colors.red(err))) + fs.remove('botonic_bundle.zip').catch(err => console.log(colors.red(err))) return } try { @@ -356,7 +350,7 @@ Uploading... console.log(colors.red(`There was an error getting the providers: ${e}`)) } try { - await fsExtra.remove('botonic_bundle.zip') + await fs.remove('botonic_bundle.zip') } catch(err) { console.log(colors.red(err)) } diff --git a/packages/botonic-cli/src/commands/new.ts b/packages/botonic-cli/src/commands/new.ts index eed431fe7a..888cf61470 100644 --- a/packages/botonic-cli/src/commands/new.ts +++ b/packages/botonic-cli/src/commands/new.ts @@ -1,5 +1,4 @@ import { Command } from '@oclif/command' -import { resolve } from 'path' import * as colors from 'colors' import { prompt } from 'inquirer' @@ -9,7 +8,7 @@ import { track } from '../utils' const util = require('util') const ora = require('ora') const exec = util.promisify(require('child_process').exec) -const fsExtra = require('fs-extra') +const fs = require('fs-extra') export default class Run extends Command { static description = 'Create a new Botonic project' @@ -86,9 +85,10 @@ Creating... if (botExists.length) { template = args.templateName } else { + const templateNames = this.templates.map(t => t.name) console.log( colors.red( - 'Template ${args.templateName} does not exist, please choose one of ${template_names}.' + `Template ${args.templateName} does not exist, please choose one of ${templateNames}.` ) ) return @@ -100,7 +100,7 @@ Creating... spinner: 'bouncingBar' }).start() try { - await fsExtra.copy(`${templatePath}`, `${args.name}`) + await fs.copy(`${templatePath}`, `${args.name}`) } catch (err) { console.log(colors.red(err)) return @@ -117,7 +117,7 @@ Creating... await this.botonicApiService.buildIfChanged(false) this.botonicApiService.beforeExit() try { - await fsExtra.move('../.botonic.json', './botonic.json') + await fs.move('../.botonic.json', './.botonic.json') } catch (err) { console.log(colors.red(err)) return From 83b133d00fbf290360f8ba5e63d9ec13da1f5aa9 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Sep 2019 12:06:57 +0200 Subject: [PATCH 4/7] Choose proper @botonic/react version --- packages/botonic-cli/templates/blank/package.json | 2 +- packages/botonic-cli/templates/handoff/package.json | 2 +- packages/botonic-cli/templates/intent/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/botonic-cli/templates/blank/package.json b/packages/botonic-cli/templates/blank/package.json index 998d5f9cba..c9665283a1 100644 --- a/packages/botonic-cli/templates/blank/package.json +++ b/packages/botonic-cli/templates/blank/package.json @@ -15,7 +15,7 @@ } }, "dependencies": { - "@botonic/react": "0.9.0" + "@botonic/react": "0.9.0-alpha.7" }, "devDependencies": { "babel-jest": "^24.1.0", diff --git a/packages/botonic-cli/templates/handoff/package.json b/packages/botonic-cli/templates/handoff/package.json index 8a4da6748f..c924c511f9 100644 --- a/packages/botonic-cli/templates/handoff/package.json +++ b/packages/botonic-cli/templates/handoff/package.json @@ -15,7 +15,7 @@ } }, "dependencies": { - "@botonic/react": "0.9.0" + "@botonic/react": "0.9.0-alpha.7" }, "devDependencies": { "babel-jest": "^24.1.0", diff --git a/packages/botonic-cli/templates/intent/package.json b/packages/botonic-cli/templates/intent/package.json index 998d5f9cba..c9665283a1 100644 --- a/packages/botonic-cli/templates/intent/package.json +++ b/packages/botonic-cli/templates/intent/package.json @@ -15,7 +15,7 @@ } }, "dependencies": { - "@botonic/react": "0.9.0" + "@botonic/react": "0.9.0-alpha.7" }, "devDependencies": { "babel-jest": "^24.1.0", From 08751a80b0fb93f0154f701728b484884d4faa38 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Sep 2019 12:06:57 +0200 Subject: [PATCH 5/7] Choose proper @botonic/react version --- packages/botonic-cli/templates/blank/package.json | 2 +- packages/botonic-cli/templates/childs/package.json | 2 +- packages/botonic-cli/templates/custom_webchat/package.json | 2 +- packages/botonic-cli/templates/dynamic_carousel/package.json | 2 +- packages/botonic-cli/templates/handoff/package.json | 2 +- packages/botonic-cli/templates/intent/package.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/botonic-cli/templates/blank/package.json b/packages/botonic-cli/templates/blank/package.json index 998d5f9cba..c9665283a1 100644 --- a/packages/botonic-cli/templates/blank/package.json +++ b/packages/botonic-cli/templates/blank/package.json @@ -15,7 +15,7 @@ } }, "dependencies": { - "@botonic/react": "0.9.0" + "@botonic/react": "0.9.0-alpha.7" }, "devDependencies": { "babel-jest": "^24.1.0", diff --git a/packages/botonic-cli/templates/childs/package.json b/packages/botonic-cli/templates/childs/package.json index 998d5f9cba..c9665283a1 100644 --- a/packages/botonic-cli/templates/childs/package.json +++ b/packages/botonic-cli/templates/childs/package.json @@ -15,7 +15,7 @@ } }, "dependencies": { - "@botonic/react": "0.9.0" + "@botonic/react": "0.9.0-alpha.7" }, "devDependencies": { "babel-jest": "^24.1.0", diff --git a/packages/botonic-cli/templates/custom_webchat/package.json b/packages/botonic-cli/templates/custom_webchat/package.json index 9af6ac0e6b..6773df0048 100644 --- a/packages/botonic-cli/templates/custom_webchat/package.json +++ b/packages/botonic-cli/templates/custom_webchat/package.json @@ -4,7 +4,7 @@ "start": "webpack-dev-server --env.target=dev" }, "dependencies": { - "@botonic/react": "0.9.0" + "@botonic/react": "0.9.0-alpha.7" }, "devDependencies": { "terser": "^3.14.1", diff --git a/packages/botonic-cli/templates/dynamic_carousel/package.json b/packages/botonic-cli/templates/dynamic_carousel/package.json index 5f3d60ab7d..bfc6afefd4 100644 --- a/packages/botonic-cli/templates/dynamic_carousel/package.json +++ b/packages/botonic-cli/templates/dynamic_carousel/package.json @@ -15,7 +15,7 @@ } }, "dependencies": { - "@botonic/react": "0.9.0", + "@botonic/react": "0.9.0-alpha.7", "isomorphic-fetch": "^2.2.1" }, "devDependencies": { diff --git a/packages/botonic-cli/templates/handoff/package.json b/packages/botonic-cli/templates/handoff/package.json index 8a4da6748f..c924c511f9 100644 --- a/packages/botonic-cli/templates/handoff/package.json +++ b/packages/botonic-cli/templates/handoff/package.json @@ -15,7 +15,7 @@ } }, "dependencies": { - "@botonic/react": "0.9.0" + "@botonic/react": "0.9.0-alpha.7" }, "devDependencies": { "babel-jest": "^24.1.0", diff --git a/packages/botonic-cli/templates/intent/package.json b/packages/botonic-cli/templates/intent/package.json index 998d5f9cba..c9665283a1 100644 --- a/packages/botonic-cli/templates/intent/package.json +++ b/packages/botonic-cli/templates/intent/package.json @@ -15,7 +15,7 @@ } }, "dependencies": { - "@botonic/react": "0.9.0" + "@botonic/react": "0.9.0-alpha.7" }, "devDependencies": { "babel-jest": "^24.1.0", From 9d1939f9fcca5406b7a3e28815f64df65dd69dd0 Mon Sep 17 00:00:00 2001 From: Pawel Walczak Date: Wed, 25 Sep 2019 11:16:56 +0200 Subject: [PATCH 6/7] Refactoring after updating branch --- packages/botonic-cli/package.json | 3 +-- packages/botonic-cli/src/commands/deploy.ts | 16 ++++++++-------- packages/botonic-cli/src/commands/serve.ts | 13 ++----------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/packages/botonic-cli/package.json b/packages/botonic-cli/package.json index c4b987cc8b..a4d1fae1f2 100644 --- a/packages/botonic-cli/package.json +++ b/packages/botonic-cli/package.json @@ -11,7 +11,6 @@ "@oclif/config": "^1", "@oclif/plugin-help": "^2", "analytics-node": "^3.3.0", - "bestzip": "^2.1.4", "colors": "^1.2.1", "folder-hash": "^3.0.0", "form-data": "^2.3.2", @@ -19,7 +18,7 @@ "inquirer": "^6.3.1", "ora": "^3.0.0", "tslib": "^1", - "zip-a-folder": "0.0.9" + "zip-a-folder": "^0.0.9" }, "devDependencies": { "@oclif/dev-cli": "^1", diff --git a/packages/botonic-cli/src/commands/deploy.ts b/packages/botonic-cli/src/commands/deploy.ts index aa8ab53aaf..f647ecfee7 100644 --- a/packages/botonic-cli/src/commands/deploy.ts +++ b/packages/botonic-cli/src/commands/deploy.ts @@ -10,7 +10,6 @@ import { sleep, track } from '../utils' const fs = require('fs-extra') const ora = require('ora') -const zip = require('bestzip') let force = false let npmCommand: string | undefined @@ -54,7 +53,9 @@ Uploading... if (!this.botonicApiService.oauth) await this.signupFlow() else if (botName) { await this.deployBotFromFlag(botName) - } else await this.deployBotFlow() + } else { + await this.deployBotFlow() + } } async deployBotFromFlag(botName: string) { @@ -187,7 +188,7 @@ Uploading... let nextBots = resp.data.next let bots = resp.data.results if (nextBots) { - let new_bots = await this.botonicApiService.getMoreBots(bots, nextBots) + await this.botonicApiService.getMoreBots(bots, nextBots) } if (!bots.length) { return this.createNewBot() @@ -346,11 +347,7 @@ Uploading... async deploy() { try { - removeSync(BOTONIC_BUNDLE_FILE) - } catch(err) { - console.log(colors.red(err)) - } - this.botonicApiService.beforeExit() + this.botonicApiService.beforeExit() let build_out = await this.botonicApiService.buildIfChanged( force, npmCommand @@ -364,6 +361,9 @@ Uploading... await this.deployBundle() await this.displayDeployResults() } catch (e) { + console.log( + colors.red(e) + ) } finally { removeSync(BOTONIC_BUNDLE_FILE) removeSync('tmp') diff --git a/packages/botonic-cli/src/commands/serve.ts b/packages/botonic-cli/src/commands/serve.ts index 4cc4ffb7eb..ab70260ccb 100644 --- a/packages/botonic-cli/src/commands/serve.ts +++ b/packages/botonic-cli/src/commands/serve.ts @@ -3,7 +3,7 @@ import { Command, flags } from '@oclif/command' import { track } from '../utils' import * as colors from 'colors' -import { spawn } from 'child_process' +import { spawn, exec } from 'child_process' export default class Run extends Command { static description = 'Serve your bot in your localhost' @@ -23,17 +23,8 @@ export default class Run extends Command { const { args, flags } = this.parse(Run) try { - const serve = spawn('npm', ['run', 'start']) + exec('npm run start']) console.log(colors.blue('\nServing Botonic...')) - serve.stdout.on('data', out => { - console.log(`${out}`) - }) - serve.stderr.on('data', stderr => { - console.log(colors.red(`${stderr}`)) - }) - serve.on('close', code => { - console.log(colors.red(`child process exited with code ${code}`)) - }) } catch (e) { console.log(e) } From e0c03ca796888928ac91fa7dde04819d75c48c80 Mon Sep 17 00:00:00 2001 From: Pawel Walczak Date: Wed, 25 Sep 2019 12:36:16 +0200 Subject: [PATCH 7/7] Refactor serve command to work on windows --- packages/botonic-cli/src/commands/serve.ts | 28 ++++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/botonic-cli/src/commands/serve.ts b/packages/botonic-cli/src/commands/serve.ts index ab70260ccb..882a926715 100644 --- a/packages/botonic-cli/src/commands/serve.ts +++ b/packages/botonic-cli/src/commands/serve.ts @@ -1,30 +1,26 @@ -import { Command, flags } from '@oclif/command' +import { Command } from '@oclif/command' import { track } from '../utils' import * as colors from 'colors' - -import { spawn, exec } from 'child_process' +import { spawn } from 'child_process' export default class Run extends Command { - static description = 'Serve your bot in your localhost' - - static examples = [ - `$ botonic serve\n> Project is running at http://localhost:8080/` - ] - - static flags = {} - - static args = [] - - private botonic: any async run() { track('Served Botonic CLI') - const { args, flags } = this.parse(Run) try { - exec('npm run start']) + const serve = spawn('npm', ['run', 'start'], {shell: true}) console.log(colors.blue('\nServing Botonic...')) + serve.stdout.on('data', out => { + console.log(`${out}`) + }) + serve.stderr.on('data', stderr => { + console.log(colors.red(`${stderr}`)) + }) + serve.on('close', code => { + console.log(colors.red(`child process exited with code ${code}`)) + }) } catch (e) { console.log(e) }