Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/improve telemetry #1305

Merged
merged 7 commits into from Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/botonic-cli/README.md
Expand Up @@ -21,7 +21,7 @@ $ npm install -g @botonic/cli
$ botonic COMMAND
running command...
$ botonic (-v|--version|version)
@botonic/cli/0.18.0 darwin-x64 node-v12.20.1
@botonic/cli/0.18.1 darwin-x64 node-v12.20.1
$ botonic --help [COMMAND]
USAGE
$ botonic COMMAND
Expand Down Expand Up @@ -64,7 +64,7 @@ EXAMPLE
🚀 Bot deployed!
```

_See code: [lib/commands/deploy.js](https://github.com/hubtype/botonic/blob/v0.18.0/lib/commands/deploy.js)_
_See code: [lib/commands/deploy.js](https://github.com/hubtype/botonic/blob/v0.18.1/lib/commands/deploy.js)_

## `botonic help [COMMAND]`

Expand All @@ -81,7 +81,7 @@ OPTIONS
--all see all commands in CLI
```

_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.1/src/commands/help.ts)_
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.2/src/commands/help.ts)_

## `botonic login`

Expand All @@ -95,7 +95,7 @@ OPTIONS
-p, --path=path Path to botonic project. Defaults to current dir.
```

_See code: [lib/commands/login.js](https://github.com/hubtype/botonic/blob/v0.18.0/lib/commands/login.js)_
_See code: [lib/commands/login.js](https://github.com/hubtype/botonic/blob/v0.18.1/lib/commands/login.js)_

## `botonic logout`

Expand All @@ -109,7 +109,7 @@ OPTIONS
-p, --path=path Path to botonic project. Defaults to current dir.
```

_See code: [lib/commands/logout.js](https://github.com/hubtype/botonic/blob/v0.18.0/lib/commands/logout.js)_
_See code: [lib/commands/logout.js](https://github.com/hubtype/botonic/blob/v0.18.1/lib/commands/logout.js)_

## `botonic new NAME [PROJECTNAME]`

Expand All @@ -129,7 +129,7 @@ EXAMPLE
✨ test_bot was successfully created!
```

_See code: [lib/commands/new.js](https://github.com/hubtype/botonic/blob/v0.18.0/lib/commands/new.js)_
_See code: [lib/commands/new.js](https://github.com/hubtype/botonic/blob/v0.18.1/lib/commands/new.js)_

## `botonic serve`

Expand All @@ -144,7 +144,7 @@ EXAMPLE
> Project is running at http://localhost:8080/
```

_See code: [lib/commands/serve.js](https://github.com/hubtype/botonic/blob/v0.18.0/lib/commands/serve.js)_
_See code: [lib/commands/serve.js](https://github.com/hubtype/botonic/blob/v0.18.1/lib/commands/serve.js)_

## `botonic test`

Expand All @@ -171,7 +171,7 @@ EXAMPLE
Ran all test suites.
```

_See code: [lib/commands/test.js](https://github.com/hubtype/botonic/blob/v0.18.0/lib/commands/test.js)_
_See code: [lib/commands/test.js](https://github.com/hubtype/botonic/blob/v0.18.1/lib/commands/test.js)_

## `botonic train`

Expand All @@ -189,5 +189,5 @@ EXAMPLE
TRAINING MODEL FOR {LANGUAGE}...
```

_See code: [lib/commands/train.js](https://github.com/hubtype/botonic/blob/v0.18.0/lib/commands/train.js)_
_See code: [lib/commands/train.js](https://github.com/hubtype/botonic/blob/v0.18.1/lib/commands/train.js)_
<!-- commandsstop -->
2 changes: 1 addition & 1 deletion packages/botonic-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions packages/botonic-cli/package.json
@@ -1,16 +1,16 @@
{
"name": "@botonic/cli",
"description": "Build Chatbots Using React",
"version": "0.18.0",
"version": "0.18.1",
"license": "MIT",
"bin": {
"botonic": "./bin/run"
},
"bugs": "https://github.com/hubtype/botonic/issues",
"dependencies": {
"@oclif/command": "^1.5.19",
"@oclif/config": "^1.14.0",
"@oclif/plugin-help": "^3.1.0",
"@oclif/command": "^1.8.0",
"@oclif/config": "^1.17.0",
"@oclif/plugin-help": "^3.2.2",
"@types/rimraf": "^3.0.0",
"analytics-node": "^3.4.0-beta.1",
"axios": "^0.21.0",
Expand All @@ -27,7 +27,7 @@
"zip-a-folder": "0.0.12"
},
"devDependencies": {
"@oclif/dev-cli": "^1.22.2",
"@oclif/dev-cli": "^1.26.0",
"@types/analytics-node": "^3.1.3",
"@types/inquirer": "^7.3.1",
"globby": "^11.0.0"
Expand Down
152 changes: 83 additions & 69 deletions packages/botonic-cli/src/commands/new.ts
Expand Up @@ -41,85 +41,99 @@ Creating...
private botonicApiService = new BotonicAPIService()

async run(): Promise<void> {
const { args } = this.parse(Run)
const userProjectName = args.name
let selectedProjectName = ''
if (!args.projectName) {
await this.selectBotName().then(resp => {
selectedProjectName = this.examples.filter(
p => p.description === resp.botName
)[0].name
return
})
} else {
const botExists = this.examples.filter(p => p.name === args.projectName)
if (botExists.length) {
selectedProjectName = args.projectName
track('Created Botonic Bot CLI')
try {
const { args } = this.parse(Run)
const userProjectName = args.name
let selectedProjectName = ''
if (!args.projectName) {
await this.selectBotName().then(resp => {
selectedProjectName = this.examples.filter(
p => p.description === resp.botName
)[0].name
return
})
} else {
const projectNames = this.examples.map(p => p.name)
console.log(
colors.red(
`Example ${args.projectName} does not exist, please choose one of ${projectNames}.`
const botExists = this.examples.filter(p => p.name === args.projectName)
if (botExists.length) {
selectedProjectName = args.projectName
} else {
const projectNames = this.examples.map(p => p.name)
console.log(
colors.red(
`Example ${args.projectName} does not exist, please choose one of ${projectNames}.`
)
)
)
return
return
}
}
track('Created Botonic Bot CLI', {
selected_project_name: selectedProjectName,
})
if (existsSync(userProjectName)) {
rimraf.sync(userProjectName)
}
}
track('Created Botonic Bot CLI', {
selected_project_name: selectedProjectName,
})
if (existsSync(userProjectName)) {
rimraf.sync(userProjectName)
}

let spinner = ora({
text: 'Downloading files...',
spinner: 'bouncingBar',
}).start()
let spinner = ora({
text: 'Downloading files...',
spinner: 'bouncingBar',
}).start()

const selectedProject = this.examples.filter(
project => project.name === selectedProjectName
)[0]
const selectedProject = this.examples.filter(
project => project.name === selectedProjectName
)[0]

try {
await fetchRepoDir({
src: selectedProject.uri,
dir: userProjectName,
})
} catch (e) {
const error = `Downloading Project: ${selectedProjectName}: ${String(e)}`
trackError(error)
throw new Error(error)
}
spinner.succeed()
process.chdir(args.name)
spinner = ora({
text: 'Installing dependencies...',
spinner: 'bouncingBar',
}).start()
const dependencyCommand = `npm install`
try {
await exec(dependencyCommand)
try {
await fetchRepoDir({
src: selectedProject.uri,
dir: userProjectName,
})
} catch (e) {
const error = `Downloading Project: ${selectedProjectName}: ${String(
e
)}`
trackError(error)
throw new Error(error)
}
spinner.succeed()
process.chdir(args.name)
spinner = ora({
text: 'Installing dependencies...',
spinner: 'bouncingBar',
}).start()
const dependencyCommand = `npm install`
try {
await exec(dependencyCommand)
} catch (e) {
const error = `Installing dependencies: ${String(e)}`
trackError(error)
throw new Error(error)
}
spinner.succeed()
this.botonicApiService.beforeExit()
moveSync(
join('..', '.botonic.json'),
join(process.cwd(), '.botonic.json')
)
const chdirCmd = colors.bold(`cd ${args.name}`)
const trainCmd =
selectedProjectName === 'nlu'
? colors.bold(`\nbotonic train`)
: undefined
const serveCmd = colors.bold('botonic serve')
const deployCmd = colors.bold('botonic deploy')
console.log(
`\n✨ Bot ${colors.bold(
args.name
)} was successfully created!\n\nNext steps:\n${chdirCmd}\n${serveCmd}${
trainCmd || ''
} (test your bot locally from the browser)\n${deployCmd} (publish your bot to the world!)`
)
} catch (e) {
const error = `Installing dependencies: ${String(e)}`
const error = `botonic new error: ${String(e)}`
trackError(error)
throw new Error(error)
}
spinner.succeed()
this.botonicApiService.beforeExit()
moveSync(join('..', '.botonic.json'), join(process.cwd(), '.botonic.json'))
const chdirCmd = colors.bold(`cd ${args.name}`)
const trainCmd =
selectedProjectName === 'nlu' ? colors.bold(`\nbotonic train`) : undefined
const serveCmd = colors.bold('botonic serve')
const deployCmd = colors.bold('botonic deploy')
console.log(
`\n✨ Bot ${colors.bold(
args.name
)} was successfully created!\n\nNext steps:\n${chdirCmd}\n${serveCmd}${
trainCmd || ''
} (test your bot locally from the browser)\n${deployCmd} (publish your bot to the world!)`
)
}

selectBotName(): Promise<{ botName: string }> {
Expand Down
16 changes: 13 additions & 3 deletions packages/botonic-cli/src/utils.ts
Expand Up @@ -54,9 +54,13 @@ if (isAnalyticsEnabled()) {
analytics = new Analytics('YD0jpJHNGW12uhLNbgB4wbdTRQ4Cy1Zu')
}

function getBotonicCliVersion(): string {
function isWindows() {
return os.platform() === 'win32'
}

function execCommand(command: string) {
try {
return String(execSync('botonic --version')).trim()
return String(execSync(command)).trim()
} catch (e) {
return String(e)
}
Expand All @@ -80,7 +84,13 @@ function getSystemInformation() {
arch: os.arch(),
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
timestamp: new Date().toISOString(),
botonic_cli_version: getBotonicCliVersion(),
is_tty: process.stdout.isTTY,
framework_path: __dirname,
system_path: isWindows()
? execCommand('echo %PATH%')
: execCommand('echo $PATH'),
node_version: execCommand('node --version'),
botonic_cli_version: execCommand('botonic --version'),
botonic_dependencies: getBotonicDependencies(),
}
}
Expand Down