diff --git a/package.json b/package.json index 3f06aea65b..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" diff --git a/packages/botonic-cli/package.json b/packages/botonic-cli/package.json index a93bfd81ea..a4d1fae1f2 100644 --- a/packages/botonic-cli/package.json +++ b/packages/botonic-cli/package.json @@ -18,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", @@ -56,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 6f7f56da2d..41deb6c764 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') @@ -163,7 +163,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 76c6bdafbb..f647ecfee7 100644 --- a/packages/botonic-cli/src/commands/deploy.ts +++ b/packages/botonic-cli/src/commands/deploy.ts @@ -5,14 +5,14 @@ import { join } from 'path' import { copySync, removeSync } from 'fs-extra' import { zip } from 'zip-a-folder' -const fs = require('fs') -const ora = require('ora') - import { BotonicAPIService } from '../botonicAPIService' -import { track, sleep } from '../utils' +import { sleep, track } from '../utils' -var force = false -var npmCommand: string | undefined +const fs = require('fs-extra') +const ora = require('ora') + +let force = false +let npmCommand: string | undefined const BOTONIC_BUNDLE_FILE = 'botonic_bundle.zip' export default class Run extends Command { @@ -40,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 @@ -52,8 +52,10 @@ Uploading... if (!this.botonicApiService.oauth) await this.signupFlow() else if (botName) { - this.deployBotFromFlag(botName) - } else await this.deployBotFlow() + await this.deployBotFromFlag(botName) + } else { + await this.deployBotFlow() + } } async deployBotFromFlag(botName: string) { @@ -64,13 +66,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) - this.deploy() } } @@ -85,11 +87,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() - else return this.askSignup() + return inp.signupConfirmation === choices[1] ? this.askLogin() : this.askSignup() }) } @@ -122,8 +123,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,10 +133,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) } } @@ -188,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() @@ -276,6 +276,7 @@ Uploading... ) ) track('Deploy Botonic Zip Error') + removeSync(BOTONIC_BUNDLE_FILE) return } } @@ -286,7 +287,7 @@ Uploading... spinner: 'bouncingBar' }).start() try { - var deploy = await this.botonicApiService.deployBot( + let deploy = await this.botonicApiService.deployBot( join(process.cwd(), BOTONIC_BUNDLE_FILE), force ) @@ -313,6 +314,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 }) + removeSync(BOTONIC_BUNDLE_FILE) return } } @@ -322,6 +324,7 @@ Uploading... console.log(colors.red('There was a problem in the deploy:')) console.log(err) track('Deploy Botonic Error', { error: err }) + removeSync(BOTONIC_BUNDLE_FILE) return } } @@ -334,7 +337,7 @@ Uploading... let links = `Now, you can integrate a channel in:\nhttps://app.hubtype.com/bots/${this.botonicApiService.bot.id}/integrations?access_token=${this.botonicApiService.oauth.access_token}` console.log(links) } else { - this.displayProviders(providers) + await this.displayProviders(providers) } } catch (e) { track('Deploy Botonic Provider Error', { error: e }) @@ -344,6 +347,7 @@ Uploading... async deploy() { try { + this.botonicApiService.beforeExit() let build_out = await this.botonicApiService.buildIfChanged( force, npmCommand @@ -357,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/new.ts b/packages/botonic-cli/src/commands/new.ts index a228e1fb29..c60fc45569 100644 --- a/packages/botonic-cli/src/commands/new.ts +++ b/packages/botonic-cli/src/commands/new.ts @@ -1,4 +1,5 @@ import { Command } from '@oclif/command' + import { resolve, join } from 'path' import { copySync, moveSync } from 'fs-extra' import { prompt } from 'inquirer' @@ -71,7 +72,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) => { @@ -86,15 +87,16 @@ Creating... if (botExists.length) { template = args.templateName } else { - let template_names = this.templates.map((t: any) => t.name) + 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 } } + let botPath = resolve(template) let templatePath = join(__dirname, '..', '..', 'templates', template) let spinner = new ora({ diff --git a/packages/botonic-cli/src/commands/serve.ts b/packages/botonic-cli/src/commands/serve.ts index 4cc4ffb7eb..882a926715 100644 --- a/packages/botonic-cli/src/commands/serve.ts +++ b/packages/botonic-cli/src/commands/serve.ts @@ -1,29 +1,16 @@ -import { Command, flags } from '@oclif/command' +import { Command } from '@oclif/command' import { track } from '../utils' import * as colors from 'colors' - 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 { - const serve = spawn('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}`) 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", 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",