Skip to content
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packages/botonic-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/botonic-cli/src/botonicAPIService.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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<any> {
Expand Down
59 changes: 33 additions & 26 deletions packages/botonic-cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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()
}
}

Expand All @@ -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()
})
}

Expand Down Expand Up @@ -122,19 +123,18 @@ 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
if (nextBots) {
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)
}
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -276,6 +276,7 @@ Uploading...
)
)
track('Deploy Botonic Zip Error')
removeSync(BOTONIC_BUNDLE_FILE)
return
}
}
Expand All @@ -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
)
Expand All @@ -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
}
}
Expand All @@ -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
}
}
Expand All @@ -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 })
Expand All @@ -344,6 +347,7 @@ Uploading...

async deploy() {
try {
this.botonicApiService.beforeExit()
let build_out = await this.botonicApiService.buildIfChanged(
force,
npmCommand
Expand All @@ -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')
Expand Down
8 changes: 5 additions & 3 deletions packages/botonic-cli/src/commands/new.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command } from '@oclif/command'

import { resolve, join } from 'path'
import { copySync, moveSync } from 'fs-extra'
import { prompt } from 'inquirer'
Expand Down Expand Up @@ -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) => {
Expand All @@ -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({
Expand Down
17 changes: 2 additions & 15 deletions packages/botonic-cli/src/commands/serve.ts
Original file line number Diff line number Diff line change
@@ -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}`)
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-cli/templates/blank/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"dependencies": {
"@botonic/react": "0.9.0"
"@botonic/react": "0.9.0-alpha.7"
},
"devDependencies": {
"babel-jest": "^24.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-cli/templates/childs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"dependencies": {
"@botonic/react": "0.9.0"
"@botonic/react": "0.9.0-alpha.7"
},
"devDependencies": {
"babel-jest": "^24.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-cli/templates/custom_webchat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"dependencies": {
"@botonic/react": "0.9.0",
"@botonic/react": "0.9.0-alpha.7",
"isomorphic-fetch": "^2.2.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-cli/templates/handoff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"dependencies": {
"@botonic/react": "0.9.0"
"@botonic/react": "0.9.0-alpha.7"
},
"devDependencies": {
"babel-jest": "^24.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-cli/templates/intent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"dependencies": {
"@botonic/react": "0.9.0"
"@botonic/react": "0.9.0-alpha.7"
},
"devDependencies": {
"babel-jest": "^24.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-cli/templates/tutorial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"dependencies": {
"@botonic/react": "0.9.0"
"@botonic/react": "0.9.0-alpha.7"
},
"devDependencies": {
"babel-jest": "^24.1.0",
Expand Down