Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ tmp/
.yalc/
yalc.lock
.eslintcache

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: 3 additions & 1 deletion packages/botonic-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
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 @@ -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<any> {
Expand Down
72 changes: 39 additions & 33 deletions packages/botonic-cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import { Command, flags } from '@oclif/command'
import { prompt } from 'inquirer'
import * as colors from 'colors'

const fs = require('fs')
const ora = require('ora')
const util = require('util')
const exec = util.promisify(require('child_process').exec)

import { BotonicAPIService } from '../botonicAPIService'
import { track, sleep } from '../utils'
import { sleep, track } from '../utils'

const fs = require('fs-extra')
const ora = require('ora')
const zip = require('bestzip')

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'
Expand All @@ -38,10 +37,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 @@ -50,7 +49,7 @@ Uploading...

if (!this.botonicApiService.oauth) await this.signupFlow()
else if (botName) {
this.deployBotFromFlag(botName)
await this.deployBotFromFlag(botName)
} else await this.deployBotFlow()
}

Expand All @@ -62,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)
this.deploy()
}
}

Expand All @@ -83,11 +82,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 @@ -120,19 +118,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 @@ -268,8 +265,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(colors.red(err))
return
}
const zip_stats = fs.statSync('botonic_bundle.zip')
spinner.succeed()
if (zip_stats.size >= 10 * 10 ** 6) {
Expand All @@ -280,15 +284,15 @@ Uploading...
)
)
track('Deploy Botonic Zip Error')
await exec('rm botonic_bundle.zip')
fs.remove('botonic_bundle.zip').catch(err => console.log(colors.red(err)))
return
}
spinner = new ora({
text: 'Deploying...',
spinner: 'bouncingBar'
}).start()
try {
var deploy = await this.botonicApiService.deployBot(
let deploy = await this.botonicApiService.deployBot(
'botonic_bundle.zip',
force
)
Expand All @@ -315,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 exec('rm botonic_bundle.zip')
await fs.remove('botonic_bundle.zip')
return
}
}
Expand All @@ -325,7 +329,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')
fs.remove('botonic_bundle.zip').catch(err => console.log(colors.red(err)))
return
}
try {
Expand All @@ -339,15 +343,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 fs.remove('botonic_bundle.zip')
} catch(err) {
console.log(colors.red(err))
}
this.botonicApiService.beforeExit()
}
}
26 changes: 17 additions & 9 deletions packages/botonic-cli/src/commands/new.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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'

const util = require('util')
const ora = require('ora')
const exec = util.promisify(require('child_process').exec)
const fs = require('fs-extra')

export default class Run extends Command {
static description = 'Create a new Botonic project'
Expand Down Expand Up @@ -70,7 +70,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 @@ -85,23 +85,26 @@ 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 = `${__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 fs.copy(`${templatePath}`, `${args.name}`)
} catch (err) {
console.log(colors.red(err))
return
}
spinner.succeed()
process.chdir(args.name)
spinner = new ora({
Expand All @@ -113,7 +116,12 @@ Creating...
spinner.succeed()
await this.botonicApiService.buildIfChanged(false)
this.botonicApiService.beforeExit()
await exec('mv ../.botonic.json .')
try {
await fs.move('../.botonic.json', './.botonic.json')
} catch (err) {
console.log(colors.red(err))
return
}
let cd_cmd = colors.bold(`cd ${args.name}`)
let run_cmd = colors.bold('botonic serve')
let deploy_cmd = colors.bold('botonic deploy')
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/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