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 5 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
8 changes: 4 additions & 4 deletions packages/botonic-cli/package.json
Expand Up @@ -8,9 +8,9 @@
},
"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
19 changes: 16 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 process.platform === 'win32'
vanbasten17 marked this conversation as resolved.
Show resolved Hide resolved
}

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,16 @@ function getSystemInformation() {
arch: os.arch(),
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
timestamp: new Date().toISOString(),
botonic_cli_version: getBotonicCliVersion(),
is_tty: process.stdout.isTTY,
binary_path: isWindows()
? execCommand('where botonic')
: execCommand('which botonic'),
vanbasten17 marked this conversation as resolved.
Show resolved Hide resolved
system_path: isWindows()
? execCommand('echo %PATH%')
: execCommand('echo $PATH'),
framework_path: isWindows() ? execCommand('cd') : execCommand('pwd'),
node_version: execCommand('node --version'),
botonic_cli_version: execCommand('botonic --version'),
botonic_dependencies: getBotonicDependencies(),
}
}
Expand Down