-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): various cli improvements (#144)
* chore(nlu-cli): download is a subcommand of lang * chore(nlu-cli): move default values outside of cli * chore(nlu-cli): extract yargs parameters in separate files * feat(nlu-cli): all cli arguments can be passed as env variables * feat(nlu-cli): config file with schema for both nlu and lang server (#143) * progress * feat(nlu-cli): config file with schema for both nlu and lang server * chore(nlu-server): remove support for NLU_SERVER_CONFIG env var * chore: write config schemas in appdata cache * minor fix * fix github workflows * fix default nlu server config * chore: default config now has doc = false
- Loading branch information
1 parent
e5be6fe
commit 4f53fae
Showing
32 changed files
with
536 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,4 +75,4 @@ jspm_packages/ | |
dist/ | ||
|
||
|
||
config.json | ||
*.config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
const gulp = require('gulp') | ||
const package = require('./scripts/gulp.package') | ||
const config = require('./scripts/gulp.config') | ||
const release = require('./scripts/gulp.release') | ||
|
||
gulp.task('default', (cb) => { | ||
console.log(` | ||
Development Cheat Sheet | ||
================================== | ||
yarn cmd package Packages Application in binaries | ||
yarn cmd config Upsert new NLU server config file | ||
yarn cmd bump Bump version and update change log | ||
yarn cmd changelog Print change log | ||
`) | ||
cb() | ||
}) | ||
|
||
gulp.task('package', package.package) | ||
gulp.task('config', config.upsertConfigFile) | ||
gulp.task('bump', release.bumpVersion) | ||
gulp.task('changelog', release.printChangeLog) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { LoggerLevel } from '@botpress/logger' | ||
import path from 'path' | ||
import { getAppDataPath } from './app-data' | ||
import { LangServerOptions, DownloadOptions, LangArgv, DownloadArgv } from './typings' | ||
|
||
const DEFAULT_LANG_DIR = () => { | ||
const appDataPath = getAppDataPath() | ||
return path.join(appDataPath, 'embeddings') | ||
} | ||
|
||
const DEFAULT_SERVER_OPTIONS = (): LangServerOptions => ({ | ||
port: 3100, | ||
host: 'localhost', | ||
langDir: DEFAULT_LANG_DIR(), | ||
authToken: undefined, | ||
adminToken: undefined, | ||
limit: 0, | ||
limitWindow: '1h', | ||
metadataLocation: 'https://nyc3.digitaloceanspaces.com/botpress-public/embeddings/index.json', | ||
offline: false, | ||
dim: 100, | ||
domain: 'bp', | ||
verbose: LoggerLevel.Info, | ||
logFilter: undefined | ||
}) | ||
|
||
const DEFAULT_DOWNLOAD_OPTIONS = (lang: string): DownloadOptions => ({ | ||
langDir: DEFAULT_LANG_DIR(), | ||
metadataLocation: 'https://nyc3.digitaloceanspaces.com/botpress-public/embeddings/index.json', | ||
dim: 100, | ||
domain: 'bp', | ||
lang | ||
}) | ||
|
||
export const getLangServerConfig = (argv: LangArgv): LangServerOptions => { | ||
return { ...DEFAULT_SERVER_OPTIONS(), ...argv } | ||
} | ||
|
||
export const getDownloadConfig = (argv: DownloadArgv): DownloadOptions => { | ||
return { ...DEFAULT_DOWNLOAD_OPTIONS(argv.lang), ...argv } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
export const run: (argv: { | ||
interface CommonOptions { | ||
langDir: string | ||
metadataLocation: string | ||
dim: number | ||
domain: string | ||
} | ||
|
||
export interface LangServerOptions extends CommonOptions { | ||
port: number | ||
host: string | ||
limit: number | ||
limitWindow: string | ||
langDir?: string | ||
authToken?: string | ||
adminToken?: string | ||
metadataLocation: string | ||
offline: boolean | ||
dim: number | ||
domain: string | ||
verbose: number | ||
logFilter: string[] | undefined | ||
}) => Promise<void> | ||
logFilter?: string[] | ||
} | ||
|
||
export const download: (argv: { | ||
langDir?: string | ||
export interface DownloadOptions extends CommonOptions { | ||
lang: string | ||
dim: number | ||
domain: string | ||
metadataLocation: string | ||
}) => Promise<void> | ||
} | ||
|
||
export type LangArgv = Partial<LangServerOptions> | ||
export type DownloadArgv = Partial<CommonOptions> & { lang: string } | ||
|
||
export const version: string | ||
export const run: (argv: LangArgv) => Promise<void> | ||
export const download: (argv: DownloadArgv) => Promise<void> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import path from 'path' | ||
|
||
export function getAppDataPath() { | ||
const homeDir = process.env.APP_DATA_PATH || process.env.HOME || process.env.APPDATA | ||
if (homeDir) { | ||
if (process.platform === 'darwin') { | ||
return path.join(homeDir, 'Library', 'Application Support', 'botpress') | ||
} | ||
|
||
return path.join(homeDir, 'botpress') | ||
} | ||
|
||
const errorMsg = `Could not determine your HOME directory. | ||
Please set the environment variable "APP_DATA_PATH", then start Botpress` | ||
throw new Error(errorMsg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import fse from 'fs-extra' | ||
import { validate } from 'json-schema' | ||
import { YargsSchema, YargsArgv } from '../yargs-utils' | ||
import { generateSchema } from './schema' | ||
|
||
interface WriteConfigFileProps<S extends YargsSchema> { | ||
schemaLocation: string | ||
fileLocation: string | ||
yargSchema: S | ||
} | ||
|
||
interface ReadConfigFileProps<S extends YargsSchema> { | ||
fileLocation: string | ||
yargSchema: S | ||
} | ||
|
||
export const writeConfigFile = async <S extends YargsSchema>(props: WriteConfigFileProps<S>): Promise<void> => { | ||
const { yargSchema, schemaLocation, fileLocation } = props | ||
const schema = generateSchema(yargSchema) | ||
const jsonConfig = { $schema: schemaLocation } | ||
await fse.writeFile(schemaLocation, JSON.stringify(schema, null, 2)) | ||
await fse.writeFile(fileLocation, JSON.stringify(jsonConfig, null, 2)) | ||
} | ||
|
||
export const readConfigFile = async <S extends YargsSchema>(props: ReadConfigFileProps<S>): Promise<YargsArgv<S>> => { | ||
const { fileLocation, yargSchema } = props | ||
const configFileContent = await fse.readFile(fileLocation, 'utf8') | ||
const { $schema, ...parsedConfigFile } = JSON.parse(configFileContent) | ||
const schema = generateSchema(yargSchema) | ||
const validationResult = validate(parsedConfigFile, schema) | ||
const { valid, errors } = validationResult | ||
if (!valid) { | ||
const errorMsg = errors.map((err) => `${err.property} ${err.message}`).join('\n') | ||
throw new Error(errorMsg) | ||
} | ||
return parsedConfigFile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { JSONSchema7, JSONSchema7Definition } from 'json-schema' | ||
import { Dictionary } from 'lodash' | ||
import { YargsSchema } from '../yargs-utils' | ||
|
||
export const generateSchema = (yargSchema: YargsSchema): JSONSchema7 => { | ||
const properties: Dictionary<JSONSchema7Definition> = {} | ||
for (const param in yargSchema) { | ||
const yargProp = yargSchema[param] | ||
properties[param] = { | ||
type: yargProp.type | ||
} | ||
} | ||
|
||
const schema: JSONSchema7 = { | ||
type: 'object', | ||
properties | ||
} | ||
return schema | ||
} |
Oops, something went wrong.