Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Iru89 committed Mar 11, 2024
1 parent 1690391 commit 182390d
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 50 deletions.
4 changes: 4 additions & 0 deletions examples/blank/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
dist/
package-lock.json
.DS_Store
8 changes: 4 additions & 4 deletions examples/blank/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blank",
"version": "0.25.0",
"name": "@botonic/example-blank",
"version": "0.25.0-alpha.0",
"scripts": {
"build": "webpack --env target=all --mode=production",
"start": "webpack-dev-server --env target=dev --mode=development",
Expand All @@ -9,10 +9,10 @@
},
"dependencies": {
"@babel/runtime": "^7.23.9",
"@botonic/react": "0.25.0-alpha.5"
"@botonic/react": "0.25.0-alpha.6"
},
"devDependencies": {
"@botonic/dx": "0.25.0-alpha.5"
"@botonic/dx": "0.25.0-alpha.7"
},
"engines": {
"node": ">=20.0.0"
Expand Down
34 changes: 28 additions & 6 deletions package-lock.json

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

16 changes: 8 additions & 8 deletions packages/botonic-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $ npm install -g @botonic/cli
$ botonic COMMAND
running command...
$ botonic (-v|--version|version)
@botonic/cli/0.25.0-alpha.1 darwin-arm64 node-v20.11.1
@botonic/cli/0.25.0-alpha.7 darwin-arm64 node-v20.11.1
$ botonic --help [COMMAND]
USAGE
$ botonic COMMAND
Expand Down Expand Up @@ -66,7 +66,7 @@ EXAMPLES
Deploying to AWS...
```

_See code: [lib/commands/deploy.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.1/lib/commands/deploy.js)_
_See code: [lib/commands/deploy.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.7/lib/commands/deploy.js)_

## `botonic destroy [PROVIDER]`

Expand All @@ -81,7 +81,7 @@ EXAMPLE
Destroying AWS stack...
```

_See code: [lib/commands/destroy.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.1/lib/commands/destroy.js)_
_See code: [lib/commands/destroy.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.7/lib/commands/destroy.js)_

## `botonic help [COMMAND]`

Expand Down Expand Up @@ -112,7 +112,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.25.0-alpha.1/lib/commands/login.js)_
_See code: [lib/commands/login.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.7/lib/commands/login.js)_

## `botonic logout`

Expand All @@ -126,7 +126,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.25.0-alpha.1/lib/commands/logout.js)_
_See code: [lib/commands/logout.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.7/lib/commands/logout.js)_

## `botonic new NAME [PROJECTNAME]`

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

_See code: [lib/commands/new.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.1/lib/commands/new.js)_
_See code: [lib/commands/new.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.7/lib/commands/new.js)_

## `botonic serve`

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

_See code: [lib/commands/serve.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.1/lib/commands/serve.js)_
_See code: [lib/commands/serve.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.7/lib/commands/serve.js)_

## `botonic test`

Expand All @@ -191,5 +191,5 @@ EXAMPLE
Ran all test suites.
```

_See code: [lib/commands/test.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.1/lib/commands/test.js)_
_See code: [lib/commands/test.js](https://github.com/hubtype/botonic/blob/v0.25.0-alpha.7/lib/commands/test.js)_
<!-- commandsstop -->
14 changes: 8 additions & 6 deletions packages/botonic-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@botonic/cli",
"description": "Build Chatbots Using React",
"version": "0.25.0-alpha.1",
"version": "0.25.0-alpha.7",
"license": "MIT",
"bin": {
"botonic": "./bin/run"
Expand All @@ -28,14 +28,15 @@
"axios": "^1.6.7",
"colors": "^1.4.0",
"concurrently": "^6.2.1",
"fetch-repo-dir": "^1.0.4",
"form-data": "^3.0.0",
"fs-extra": "^10.0.0",
"fetch-repo-dir": "^1.0.6",
"form-data": "^3.0.1",
"fs-extra": "^10.1.0",
"inquirer": "^7.3.3",
"kill-port": "^1.6.1",
"localtunnel": "^2.0.1",
"ora": "^5.4.0",
"localtunnel": "^2.0.2",
"ora": "^5.4.1",
"qs": "^6.11.2",
"tar": "^6.2.0",
"tslib": "^2.6.2",
"uuid": "^8.3.2",
"zip-a-folder": "3.1.6"
Expand All @@ -47,6 +48,7 @@
"@types/fs-extra": "^9.0.11",
"@types/inquirer": "^7.3.1",
"@types/localtunnel": "^2.0.1",
"@types/tar": "^6.1.11",
"@types/uuid": "^8.3.0",
"globby": "^11.0.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-cli/src/analytics/credentials-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class GlobalCredentialsHandler extends CredentialsHandler {

getAnonymousId(): string | undefined {
const content = this.load()
return content?.analytics.anonymous_id
return content?.analytics?.anonymous_id
}

hasAnonymousId(): boolean {
Expand Down
24 changes: 11 additions & 13 deletions packages/botonic-cli/src/botonic-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ import path from 'path'

import { BotonicProject } from './interfaces'

const GITHUB_EXAMPLES_PATH = 'hubtype/botonic-examples'

export const EXAMPLES: BotonicProject[] = [
{
name: 'blank',
description: 'Blank: A minimal template to start from scratch',
uri: `${GITHUB_EXAMPLES_PATH}/blank`,
version: '0.25.0-alpha.0',
localTestPath: path.resolve(__dirname, '../../../examples/blank'),
},
{
name: 'blank-typescript',
description: 'Blank (TypeScript): A minimal template to start from scratch',
uri: `${GITHUB_EXAMPLES_PATH}/blank-typescript`,
version: '0.25.0-alpha.0',
localTestPath: path.resolve(
__dirname,
'../../../examples/blank-typescript'
Expand All @@ -24,58 +22,58 @@ export const EXAMPLES: BotonicProject[] = [
name: 'booking-platform',
description:
'Booking Platform: Use custom messages and webviews in order to book a reservation in a hotel',
uri: `${GITHUB_EXAMPLES_PATH}/booking-platform`,
version: '0.25.0-alpha.0',
localTestPath: '../../../examples/booking-platform',
},
{
name: 'childs',
description: 'Childs: Understand how childRoutes works',
uri: `${GITHUB_EXAMPLES_PATH}/childs`,
version: '0.25.0-alpha.0',
localTestPath: '../../../examples/childs',
},
{
name: 'custom-webchat',
description: 'Custom Webchat: See how it looks like a custom webchat',
uri: `${GITHUB_EXAMPLES_PATH}/custom-webchat`,
version: '0.25.0-alpha.0',
localTestPath: '../../../examples/custom-webchat',
},
{
name: 'dynamic-carousel',
description: 'Dynamic Carousel: See a dynamic carousel for Facebook',
uri: `${GITHUB_EXAMPLES_PATH}/dynamic-carousel`,
version: '0.25.0-alpha.0',
localTestPath: '../../../examples/dynamic-carousel',
},
{
name: 'dynamodb',
description: 'DynamoDB: Using AWS DynamoDB to track events.',
uri: `${GITHUB_EXAMPLES_PATH}/dynamodb`,
version: '0.25.0-alpha.0',
localTestPath: '../../../examples/dynamodb',
},
{
name: 'handoff',
description:
'Handoff: Test how to transfer a conversation into Hubtype Desk',
uri: `${GITHUB_EXAMPLES_PATH}/handoff`,
version: '0.25.0-alpha.0',
localTestPath: '../../../examples/handoff',
},
{
name: 'intent',
description: 'Bot that uses external AI like DialogFlow.',
uri: `${GITHUB_EXAMPLES_PATH}/intent`,
version: '0.25.0-alpha.0',
localTestPath: '../../../examples/intent',
},
{
name: 'telco-offers',
description:
'Telco Offers: Flow to acquire an Internet or a cell phone rate using buttons and replies',
uri: `${GITHUB_EXAMPLES_PATH}/telco-offers`,
version: '0.25.0-alpha.0',
localTestPath: '../../../examples/teleco-offers',
},
{
name: 'tutorial',
description:
'Tutorial: An example with different examples that help you get started fast',
uri: `${GITHUB_EXAMPLES_PATH}/tutorial`,
version: '0.25.0-alpha.0',
localTestPath: '../../../examples/tutorial',
},
]
38 changes: 29 additions & 9 deletions packages/botonic-cli/src/commands/new.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { Command } from '@oclif/command'
import { exec as childProcessExec } from 'child_process'
import { bold, red } from 'colors'
import fetchRepoDir from 'fetch-repo-dir'
// import fetchRepoDir from 'fetch-repo-dir'
import { moveSync } from 'fs-extra'
// eslint-disable-next-line import/named
import { prompt } from 'inquirer'
import ora from 'ora'
import { platform } from 'os'
import { join } from 'path'
import path, { join } from 'path'
import { promisify } from 'util'

import { Telemetry } from '../analytics/telemetry'
import { BotonicAPIService } from '../botonic-api-service'
import { EXAMPLES } from '../botonic-examples'
import { BotonicProject } from '../interfaces'
import {
downloadSelectedProject,
editPackageJsonName,
extractTarGz,
renameFolder,
} from '../util/download-gzip'
import { pathExists, removeRecursively } from '../util/file-system'

// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -78,8 +84,13 @@ Creating...
)
process.chdir(userProjectDirName)
const devPlatform = platform()
if (devPlatform === 'win32') await this.installDependencies()
else await this.installDependencies('CXXFLAGS="--std=c++14" npm install') // Solve issue with node-sass and higher versions of Node. Ref: https://github.com/nodejs/node/issues/38367#issuecomment-1025343439)
if (devPlatform === 'win32') {
await this.installDependencies()
} else {
// Solve issue with node-sass and higher versions of Node.
// Ref: https://github.com/nodejs/node/issues/38367#issuecomment-1025343439)
await this.installDependencies('CXXFLAGS="--std=c++14" npm install')
}
this.botonicApiService.beforeExit()
moveSync(
join('..', '.botonic.json'),
Expand Down Expand Up @@ -116,18 +127,27 @@ Creating...

async downloadSelectedProjectIntoPath(
selectedProject: BotonicProject,
path: string
userProjectDirName: string
): Promise<void> {
if (pathExists(path)) removeRecursively(path)
if (pathExists(userProjectDirName)) removeRecursively(userProjectDirName)
const spinner = ora({
text: 'Downloading files...',
spinner: 'bouncingBar',
}).start()
try {
await fetchRepoDir({
src: selectedProject.uri,
dir: path,
const pathToCreateExample = path.join('.')
console.log({ pathToCreateExample })
await downloadSelectedProject({
exampleName: selectedProject.name,
exampleVersion: selectedProject.version,
})
await extractTarGz({
projectPath: pathToCreateExample,
exampleName: selectedProject.name,
exampleVersion: selectedProject.version,
})
await renameFolder(userProjectDirName)
await editPackageJsonName(pathToCreateExample, userProjectDirName)
spinner.succeed()
} catch (e) {
spinner.fail()
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-cli/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface BotonicProject {
name: string
description: string
uri: string
version: string
localTestPath: string
}

Expand Down
Loading

0 comments on commit 182390d

Please sign in to comment.