@botpress/cli 4.27.1 → 4.27.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +11 -11
- package/dist/code-generation/bot-implementation/bot-typings/index.js +2 -1
- package/dist/code-generation/bot-implementation/bot-typings/index.js.map +2 -2
- package/dist/code-generation/module.js +1 -1
- package/dist/code-generation/module.js.map +2 -2
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js +3 -2
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js.map +2 -2
- package/dist/code-generation/strings.d.ts +1 -0
- package/dist/code-generation/strings.js +3 -0
- package/dist/code-generation/strings.js.map +2 -2
- package/dist/command-implementations/add-command.js +4 -2
- package/dist/command-implementations/add-command.js.map +2 -2
- package/dist/command-implementations/global-command.d.ts +1 -1
- package/dist/command-implementations/global-command.js +11 -6
- package/dist/command-implementations/global-command.js.map +2 -2
- package/dist/command-implementations/init-command.js +6 -4
- package/dist/command-implementations/init-command.js.map +2 -2
- package/dist/command-implementations/project-command.js +8 -3
- package/dist/command-implementations/project-command.js.map +2 -2
- package/dist/utils/cache-utils.js +6 -1
- package/dist/utils/cache-utils.js.map +2 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +2 -2
- package/dist/utils/json-utils.d.ts +8 -0
- package/dist/utils/json-utils.js +37 -0
- package/dist/utils/json-utils.js.map +7 -0
- package/dist/utils/pkgjson-utils.d.ts +8 -0
- package/dist/utils/pkgjson-utils.js +20 -2
- package/dist/utils/pkgjson-utils.js.map +2 -2
- package/dist/worker/child-entrypoint.js +9 -1
- package/dist/worker/child-entrypoint.js.map +2 -2
- package/package.json +2 -2
- package/templates/empty-bot/package.json +1 -1
- package/templates/empty-integration/package.json +1 -1
- package/templates/empty-plugin/package.json +1 -1
- package/templates/hello-world/package.json +1 -1
- package/templates/webhook-message/package.json +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/cli@4.27.
|
|
2
|
+
> @botpress/cli@4.27.3 build /home/runner/work/botpress/botpress/packages/cli
|
|
3
3
|
> pnpm run build:types && pnpm run bundle && pnpm run template:gen
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @botpress/cli@4.27.
|
|
6
|
+
> @botpress/cli@4.27.3 build:types /home/runner/work/botpress/botpress/packages/cli
|
|
7
7
|
> tsc -p ./tsconfig.build.json
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
> @botpress/cli@4.27.
|
|
10
|
+
> @botpress/cli@4.27.3 bundle /home/runner/work/botpress/botpress/packages/cli
|
|
11
11
|
> ts-node -T build.ts
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
> @botpress/cli@4.27.
|
|
14
|
+
> @botpress/cli@4.27.3 template:gen /home/runner/work/botpress/botpress/packages/cli
|
|
15
15
|
> pnpm -r --stream -F @bp-templates/* exec bp gen
|
|
16
16
|
|
|
17
|
-
🤖 Botpress CLI v4.27.
|
|
17
|
+
🤖 Botpress CLI v4.27.3
|
|
18
18
|
● Checking if cli is up to date
|
|
19
|
-
🤖 Botpress CLI v4.27.
|
|
19
|
+
🤖 Botpress CLI v4.27.3
|
|
20
20
|
● Checking if cli is up to date
|
|
21
|
-
🤖 Botpress CLI v4.27.
|
|
21
|
+
🤖 Botpress CLI v4.27.3
|
|
22
22
|
● Checking if cli is up to date
|
|
23
|
-
🤖 Botpress CLI v4.27.
|
|
23
|
+
🤖 Botpress CLI v4.27.3
|
|
24
24
|
● Checking if cli is up to date
|
|
25
25
|
● Checking if sdk is up to date
|
|
26
26
|
● Checking if sdk is up to date
|
|
27
27
|
● Checking if sdk is up to date
|
|
28
28
|
● Checking if sdk is up to date
|
|
29
29
|
○ Generating typings for bot...
|
|
30
|
+
○ Generating typings for integration hello-world...
|
|
30
31
|
✓ Typings available at .botpress
|
|
31
32
|
|
|
32
33
|
○ Generating typings for integration empty-integration...
|
|
33
34
|
✓ Typings available at .botpress
|
|
34
35
|
|
|
35
|
-
○ Generating typings for plugin empty-plugin...
|
|
36
36
|
✓ Typings available at .botpress
|
|
37
37
|
|
|
38
|
-
○ Generating typings for
|
|
38
|
+
○ Generating typings for plugin empty-plugin...
|
|
39
39
|
✓ Typings available at .botpress
|
|
40
40
|
|
|
41
|
-
🤖 Botpress CLI v4.27.
|
|
41
|
+
🤖 Botpress CLI v4.27.3
|
|
42
42
|
● Checking if cli is up to date
|
|
43
43
|
● Checking if sdk is up to date
|
|
44
44
|
○ Generating typings for integration webhook-message...
|
|
@@ -34,6 +34,7 @@ module.exports = __toCommonJS(bot_typings_exports);
|
|
|
34
34
|
var consts = __toESM(require("../../consts"));
|
|
35
35
|
var import_integration_typings = require("../../integration-implementation/integration-typings");
|
|
36
36
|
var import_module = require("../../module");
|
|
37
|
+
var strings = __toESM(require("../../strings"));
|
|
37
38
|
var import_actions_module = require("./actions-module");
|
|
38
39
|
var import_events_module = require("./events-module");
|
|
39
40
|
var import_states_module = require("./states-module");
|
|
@@ -46,7 +47,7 @@ class BotIntegrationsModule extends import_module.ReExportTypeModule {
|
|
|
46
47
|
});
|
|
47
48
|
for (const [alias, integration] of Object.entries(bot.integrations ?? {})) {
|
|
48
49
|
const integrationModule = new import_integration_typings.IntegrationTypingsModule(integration.definition).setCustomTypeName(alias);
|
|
49
|
-
integrationModule.unshift(alias);
|
|
50
|
+
integrationModule.unshift(strings.dirName(alias));
|
|
50
51
|
this.pushDep(integrationModule);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/code-generation/bot-implementation/bot-typings/index.ts"],
|
|
4
|
-
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as consts from '../../consts'\nimport { IntegrationTypingsModule } from '../../integration-implementation/integration-typings'\nimport { Module, ReExportTypeModule } from '../../module'\nimport { ActionsModule } from './actions-module'\nimport { EventsModule } from './events-module'\nimport { StatesModule } from './states-module'\nimport { TablesModule } from './tables-module'\nimport { WorkflowsModule } from './workflows-module'\n\nclass BotIntegrationsModule extends ReExportTypeModule {\n public constructor(bot: sdk.BotDefinition) {\n super({\n exportName: 'Integrations',\n })\n\n for (const [alias, integration] of Object.entries(bot.integrations ?? {})) {\n const integrationModule = new IntegrationTypingsModule(integration.definition).setCustomTypeName(alias)\n integrationModule.unshift(alias)\n this.pushDep(integrationModule)\n }\n }\n}\n\ntype BotTypingsIndexDependencies = {\n integrationsModule: BotIntegrationsModule\n eventsModule: EventsModule\n statesModule: StatesModule\n actionsModule: ActionsModule\n tablesModule: TablesModule\n workflowsModule: WorkflowsModule\n}\n\nexport class BotTypingsModule extends Module {\n private _dependencies: BotTypingsIndexDependencies\n\n public constructor(bot: sdk.BotDefinition) {\n super({\n exportName: 'TBot',\n path: consts.INDEX_FILE,\n })\n\n const integrationsModule = new BotIntegrationsModule(bot)\n integrationsModule.unshift('integrations')\n this.pushDep(integrationsModule)\n\n const eventsModule = new EventsModule(bot.withPlugins.events ?? {})\n eventsModule.unshift('events')\n this.pushDep(eventsModule)\n\n const statesModule = new StatesModule(bot.withPlugins.states ?? {})\n statesModule.unshift('states')\n this.pushDep(statesModule)\n\n const tablesModule = new TablesModule(bot.withPlugins.tables ?? {})\n tablesModule.unshift('tables')\n this.pushDep(tablesModule)\n\n const actionsModule = new ActionsModule(bot.withPlugins.actions ?? {})\n actionsModule.unshift('actions')\n this.pushDep(actionsModule)\n\n const workflowsModule = new WorkflowsModule(bot.withPlugins.workflows ?? {})\n workflowsModule.unshift('workflows')\n this.pushDep(workflowsModule)\n\n this._dependencies = {\n integrationsModule,\n eventsModule,\n statesModule,\n actionsModule,\n tablesModule,\n workflowsModule,\n }\n }\n\n public async getContent() {\n const { integrationsModule, eventsModule, statesModule, actionsModule, tablesModule, workflowsModule } =\n this._dependencies\n\n const integrationsImport = integrationsModule.import(this)\n const eventsImport = eventsModule.import(this)\n const statesImport = statesModule.import(this)\n const actionsImport = actionsModule\n const tablesImport = tablesModule.import(this)\n const workflowsImport = workflowsModule\n\n return [\n consts.GENERATED_HEADER,\n `import * as ${integrationsModule.name} from './${integrationsImport}'`,\n `import * as ${eventsModule.name} from './${eventsModule.name}'`,\n `import * as ${statesModule.name} from './${statesModule.name}'`,\n `import * as ${actionsModule.name} from './${actionsImport.name}'`,\n `import * as ${tablesModule.name} from './${tablesImport}'`,\n `import * as ${workflowsModule.name} from './${workflowsImport.name}'`,\n '',\n `export * as ${integrationsModule.name} from './${integrationsImport}'`,\n `export * as ${eventsModule.name} from './${eventsImport}'`,\n `export * as ${statesModule.name} from './${statesImport}'`,\n `export * as ${actionsModule.name} from './${actionsImport.name}'`,\n `export * as ${tablesModule.name} from './${tablesImport}'`,\n `export * as ${workflowsModule.name} from './${workflowsImport.name}'`,\n '',\n 'export type TBot = {',\n ` integrations: ${integrationsModule.name}.${integrationsModule.exportName}`,\n ` events: ${eventsModule.name}.${eventsModule.exportName}`,\n ` states: ${statesModule.name}.${statesModule.exportName}`,\n ` actions: ${actionsModule.name}.${actionsModule.exportName}`,\n ` tables: ${tablesModule.name}.${tablesModule.exportName}`,\n ` workflows: ${workflowsModule.name}.${workflowsModule.exportName}`,\n '}',\n ].join('\\n')\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,aAAwB;AACxB,iCAAyC;AACzC,oBAA2C;AAC3C,4BAA8B;AAC9B,2BAA6B;AAC7B,2BAA6B;AAC7B,2BAA6B;AAC7B,8BAAgC;AAEhC,MAAM,8BAA8B,iCAAmB;AAAA,EAC9C,YAAY,KAAwB;AACzC,UAAM;AAAA,MACJ,YAAY;AAAA,IACd,CAAC;AAED,eAAW,CAAC,OAAO,WAAW,KAAK,OAAO,QAAQ,IAAI,gBAAgB,CAAC,CAAC,GAAG;AACzE,YAAM,oBAAoB,IAAI,oDAAyB,YAAY,UAAU,EAAE,kBAAkB,KAAK;AACtG,wBAAkB,QAAQ,KAAK;
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as consts from '../../consts'\nimport { IntegrationTypingsModule } from '../../integration-implementation/integration-typings'\nimport { Module, ReExportTypeModule } from '../../module'\nimport * as strings from '../../strings'\nimport { ActionsModule } from './actions-module'\nimport { EventsModule } from './events-module'\nimport { StatesModule } from './states-module'\nimport { TablesModule } from './tables-module'\nimport { WorkflowsModule } from './workflows-module'\n\nclass BotIntegrationsModule extends ReExportTypeModule {\n public constructor(bot: sdk.BotDefinition) {\n super({\n exportName: 'Integrations',\n })\n\n for (const [alias, integration] of Object.entries(bot.integrations ?? {})) {\n const integrationModule = new IntegrationTypingsModule(integration.definition).setCustomTypeName(alias)\n integrationModule.unshift(strings.dirName(alias))\n this.pushDep(integrationModule)\n }\n }\n}\n\ntype BotTypingsIndexDependencies = {\n integrationsModule: BotIntegrationsModule\n eventsModule: EventsModule\n statesModule: StatesModule\n actionsModule: ActionsModule\n tablesModule: TablesModule\n workflowsModule: WorkflowsModule\n}\n\nexport class BotTypingsModule extends Module {\n private _dependencies: BotTypingsIndexDependencies\n\n public constructor(bot: sdk.BotDefinition) {\n super({\n exportName: 'TBot',\n path: consts.INDEX_FILE,\n })\n\n const integrationsModule = new BotIntegrationsModule(bot)\n integrationsModule.unshift('integrations')\n this.pushDep(integrationsModule)\n\n const eventsModule = new EventsModule(bot.withPlugins.events ?? {})\n eventsModule.unshift('events')\n this.pushDep(eventsModule)\n\n const statesModule = new StatesModule(bot.withPlugins.states ?? {})\n statesModule.unshift('states')\n this.pushDep(statesModule)\n\n const tablesModule = new TablesModule(bot.withPlugins.tables ?? {})\n tablesModule.unshift('tables')\n this.pushDep(tablesModule)\n\n const actionsModule = new ActionsModule(bot.withPlugins.actions ?? {})\n actionsModule.unshift('actions')\n this.pushDep(actionsModule)\n\n const workflowsModule = new WorkflowsModule(bot.withPlugins.workflows ?? {})\n workflowsModule.unshift('workflows')\n this.pushDep(workflowsModule)\n\n this._dependencies = {\n integrationsModule,\n eventsModule,\n statesModule,\n actionsModule,\n tablesModule,\n workflowsModule,\n }\n }\n\n public async getContent() {\n const { integrationsModule, eventsModule, statesModule, actionsModule, tablesModule, workflowsModule } =\n this._dependencies\n\n const integrationsImport = integrationsModule.import(this)\n const eventsImport = eventsModule.import(this)\n const statesImport = statesModule.import(this)\n const actionsImport = actionsModule\n const tablesImport = tablesModule.import(this)\n const workflowsImport = workflowsModule\n\n return [\n consts.GENERATED_HEADER,\n `import * as ${integrationsModule.name} from './${integrationsImport}'`,\n `import * as ${eventsModule.name} from './${eventsModule.name}'`,\n `import * as ${statesModule.name} from './${statesModule.name}'`,\n `import * as ${actionsModule.name} from './${actionsImport.name}'`,\n `import * as ${tablesModule.name} from './${tablesImport}'`,\n `import * as ${workflowsModule.name} from './${workflowsImport.name}'`,\n '',\n `export * as ${integrationsModule.name} from './${integrationsImport}'`,\n `export * as ${eventsModule.name} from './${eventsImport}'`,\n `export * as ${statesModule.name} from './${statesImport}'`,\n `export * as ${actionsModule.name} from './${actionsImport.name}'`,\n `export * as ${tablesModule.name} from './${tablesImport}'`,\n `export * as ${workflowsModule.name} from './${workflowsImport.name}'`,\n '',\n 'export type TBot = {',\n ` integrations: ${integrationsModule.name}.${integrationsModule.exportName}`,\n ` events: ${eventsModule.name}.${eventsModule.exportName}`,\n ` states: ${statesModule.name}.${statesModule.exportName}`,\n ` actions: ${actionsModule.name}.${actionsModule.exportName}`,\n ` tables: ${tablesModule.name}.${tablesModule.exportName}`,\n ` workflows: ${workflowsModule.name}.${workflowsModule.exportName}`,\n '}',\n ].join('\\n')\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,aAAwB;AACxB,iCAAyC;AACzC,oBAA2C;AAC3C,cAAyB;AACzB,4BAA8B;AAC9B,2BAA6B;AAC7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,IAAI,IAAI,aAAa,UAAU;AAAA,MACzD,gBAAgB,gBAAgB,IAAI,IAAI,gBAAgB,UAAU;AAAA,MAClE;AAAA,IACF,EAAE,KAAK,IAAI;AAAA,EACb;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -74,7 +74,7 @@ class Module {
|
|
|
74
74
|
return this._customTypeName ?? this.name;
|
|
75
75
|
}
|
|
76
76
|
get importAlias() {
|
|
77
|
-
return this.typeName.split(
|
|
77
|
+
return this.typeName.split(/\\|\//).map(strings.importAlias).join("__");
|
|
78
78
|
}
|
|
79
79
|
setCustomTypeName(alias) {
|
|
80
80
|
this._customTypeName = alias;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/code-generation/module.ts"],
|
|
4
|
-
"sourcesContent": ["import { posix as pathlib } from 'path'\nimport * as utils from '../utils'\nimport * as consts from './consts'\nimport * as strings from './strings'\nimport { File } from './typings'\n\nexport type ModuleProps = {\n path: string\n exportName: string\n}\n\nexport abstract class Module {\n private _localDependencies: Module[] = []\n private _customTypeName: string | undefined\n\n public get path(): string {\n return this._def.path.split(pathlib.sep).map(strings.fileName).join(pathlib.sep)\n }\n\n /**\n * @returns module name (equivalent to unescaped file name without extension)\n */\n public get name(): string {\n const path = this._def.path\n const basename = pathlib.basename(path)\n if (basename === consts.INDEX_FILE || basename === consts.INDEX_DECLARATION_FILE) {\n const dirPath = pathlib.dirname(path)\n const dirname = pathlib.basename(dirPath)\n return dirname\n }\n const withoutExtension = utils.path.rmExtension(basename)\n return withoutExtension\n }\n\n public get isDefaultExport(): boolean {\n return this._def.exportName === consts.DEFAULT_EXPORT_NAME\n }\n\n public get exportName(): string {\n return this._def.exportName\n }\n\n public get deps(): Module[] {\n return [...this._localDependencies]\n }\n\n public get typeName(): string {\n return this._customTypeName ?? this.name\n }\n\n public get importAlias(): string {\n return this.typeName.split(
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;AACjC,YAAuB;AACvB,aAAwB;AACxB,cAAyB;AAQlB,MAAe,OAAO;AAAA,EA2CjB,YAAoB,MAAmB;AAAnB;AAAA,EAAoB;AAAA,EA1C1C,qBAA+B,CAAC;AAAA,EAChC;AAAA,EAER,IAAW,OAAe;AACxB,WAAO,KAAK,KAAK,KAAK,MAAM,YAAAA,MAAQ,GAAG,EAAE,IAAI,QAAQ,QAAQ,EAAE,KAAK,YAAAA,MAAQ,GAAG;AAAA,EACjF;AAAA;AAAA;AAAA;AAAA,EAKA,IAAW,OAAe;AACxB,UAAM,OAAO,KAAK,KAAK;AACvB,UAAM,WAAW,YAAAA,MAAQ,SAAS,IAAI;AACtC,QAAI,aAAa,OAAO,cAAc,aAAa,OAAO,wBAAwB;AAChF,YAAM,UAAU,YAAAA,MAAQ,QAAQ,IAAI;AACpC,YAAM,UAAU,YAAAA,MAAQ,SAAS,OAAO;AACxC,aAAO;AAAA,IACT;AACA,UAAM,mBAAmB,MAAM,KAAK,YAAY,QAAQ;AACxD,WAAO;AAAA,EACT;AAAA,EAEA,IAAW,kBAA2B;AACpC,WAAO,KAAK,KAAK,eAAe,OAAO;AAAA,EACzC;AAAA,EAEA,IAAW,aAAqB;AAC9B,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAEA,IAAW,OAAiB;AAC1B,WAAO,CAAC,GAAG,KAAK,kBAAkB;AAAA,EACpC;AAAA,EAEA,IAAW,WAAmB;AAC5B,WAAO,KAAK,mBAAmB,KAAK;AAAA,EACtC;AAAA,EAEA,IAAW,cAAsB;AAC/B,WAAO,KAAK,SAAS,MAAM,
|
|
4
|
+
"sourcesContent": ["import { posix as pathlib } from 'path'\nimport * as utils from '../utils'\nimport * as consts from './consts'\nimport * as strings from './strings'\nimport { File } from './typings'\n\nexport type ModuleProps = {\n path: string\n exportName: string\n}\n\nexport abstract class Module {\n private _localDependencies: Module[] = []\n private _customTypeName: string | undefined\n\n public get path(): string {\n return this._def.path.split(pathlib.sep).map(strings.fileName).join(pathlib.sep)\n }\n\n /**\n * @returns module name (equivalent to unescaped file name without extension)\n */\n public get name(): string {\n const path = this._def.path\n const basename = pathlib.basename(path)\n if (basename === consts.INDEX_FILE || basename === consts.INDEX_DECLARATION_FILE) {\n const dirPath = pathlib.dirname(path)\n const dirname = pathlib.basename(dirPath)\n return dirname\n }\n const withoutExtension = utils.path.rmExtension(basename)\n return withoutExtension\n }\n\n public get isDefaultExport(): boolean {\n return this._def.exportName === consts.DEFAULT_EXPORT_NAME\n }\n\n public get exportName(): string {\n return this._def.exportName\n }\n\n public get deps(): Module[] {\n return [...this._localDependencies]\n }\n\n public get typeName(): string {\n return this._customTypeName ?? this.name\n }\n\n public get importAlias(): string {\n return this.typeName.split(/\\\\|\\//).map(strings.importAlias).join('__')\n }\n\n protected constructor(private _def: ModuleProps) {}\n\n public abstract getContent(): Promise<string>\n\n public setCustomTypeName(alias: string): this {\n this._customTypeName = alias\n return this\n }\n\n public pushDep(...dependencies: Module[]): this {\n this._localDependencies.push(...dependencies)\n return this\n }\n\n public unshift(...basePath: string[]): this {\n this._def = {\n ...this._def,\n path: pathlib.join(...basePath, this._def.path),\n }\n this._localDependencies = this._localDependencies.map((d) => d.unshift(...basePath))\n return this\n }\n\n public async toFile(): Promise<File> {\n return {\n path: this.path,\n content: await this.getContent(),\n }\n }\n\n public async flatten(): Promise<File[]> {\n const self = await this.toFile()\n const allFiles: File[] = [self]\n for (const dep of this._localDependencies) {\n const depFiles = await dep.flatten()\n allFiles.push(...depFiles)\n }\n return allFiles\n }\n\n public import(base: Module): string {\n let relativePath = pathlib.relative(pathlib.dirname(base.path), this.path)\n relativePath = pathlib.join('.', relativePath)\n return utils.path.rmExtension(relativePath)\n }\n}\n\nexport class ReExportTypeModule extends Module {\n protected constructor(def: { exportName: string }) {\n super({\n ...def,\n path: consts.INDEX_FILE,\n })\n }\n\n public async getContent(): Promise<string> {\n let content = consts.GENERATED_HEADER\n\n for (const m of this.deps) {\n const { importAlias } = m\n const importFrom = m.import(this)\n content += `import * as ${importAlias} from \"./${importFrom}\";\\n`\n content += `export * as ${importAlias} from \"./${importFrom}\";\\n`\n }\n\n content += '\\n'\n\n content += `export type ${this.exportName} = {\\n`\n for (const { importAlias, typeName, exportName: exports } of this.deps) {\n content += ` \"${typeName}\": ${importAlias}.${exports};\\n`\n }\n content += '}'\n\n content += '\\n'\n\n return content\n }\n}\n\nexport class ReExportVariableModule extends Module {\n private _extraProps: Record<string, string> = {}\n\n protected constructor(def: { exportName: string; extraProps?: Record<string, string> }) {\n super({\n ...def,\n path: consts.INDEX_FILE,\n })\n this._extraProps = def.extraProps ?? {}\n }\n\n public async getContent(): Promise<string> {\n let content = consts.GENERATED_HEADER\n\n for (const m of this.deps) {\n const { importAlias } = m\n const importFrom = m.import(this)\n content += `import * as ${importAlias} from \"./${importFrom}\";\\n`\n content += `export * as ${importAlias} from \"./${importFrom}\";\\n`\n }\n\n content += '\\n'\n\n const depProps: Record<string, string> = Object.fromEntries(\n this.deps.map(({ name, exportName, importAlias }) => [name, `${importAlias}.${exportName}`])\n )\n\n const allProps = { ...depProps, ...this._extraProps }\n\n content += `export const ${this.exportName} = {\\n`\n for (const [key, value] of Object.entries(allProps)) {\n content += ` \"${key}\": ${value},\\n`\n }\n content += '}'\n\n content += '\\n'\n\n return content\n }\n}\n\nexport class SingleFileModule extends Module {\n private _content: string\n public constructor(def: ModuleProps & { content: string }) {\n super(def)\n this._content = def.content\n }\n\n public async getContent(): Promise<string> {\n return this._content\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;AACjC,YAAuB;AACvB,aAAwB;AACxB,cAAyB;AAQlB,MAAe,OAAO;AAAA,EA2CjB,YAAoB,MAAmB;AAAnB;AAA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import_integration_typings = require("../../integration-implementation/integration-typings");
|
|
36
36
|
var import_interface_implementation = require("../../interface-implementation");
|
|
37
37
|
var import_module = require("../../module");
|
|
38
|
+
var strings = __toESM(require("../../strings"));
|
|
38
39
|
var import_actions_module = require("./actions-module");
|
|
39
40
|
var import_configuration_module = require("./configuration-module");
|
|
40
41
|
var import_events_module = require("./events-module");
|
|
@@ -48,7 +49,7 @@ class PluginIntegrationsModule extends import_module.ReExportTypeModule {
|
|
|
48
49
|
});
|
|
49
50
|
for (const [alias, integration] of Object.entries(plugin.integrations ?? {})) {
|
|
50
51
|
const integrationModule = new import_integration_typings.IntegrationTypingsModule(integration.definition);
|
|
51
|
-
integrationModule.unshift(alias);
|
|
52
|
+
integrationModule.unshift(strings.dirName(alias));
|
|
52
53
|
this.pushDep(integrationModule);
|
|
53
54
|
}
|
|
54
55
|
}
|
|
@@ -60,7 +61,7 @@ class PluginInterfacesModule extends import_module.ReExportTypeModule {
|
|
|
60
61
|
});
|
|
61
62
|
for (const [alias, intrface] of Object.entries(plugin.interfaces ?? {})) {
|
|
62
63
|
const interfaceModule = new import_interface_implementation.InterfaceTypingsModule(intrface.definition);
|
|
63
|
-
interfaceModule.unshift(alias);
|
|
64
|
+
interfaceModule.unshift(strings.dirName(alias));
|
|
64
65
|
this.pushDep(interfaceModule);
|
|
65
66
|
}
|
|
66
67
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/code-generation/plugin-implementation/plugin-typings/index.ts"],
|
|
4
|
-
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as utils from '../../../utils'\nimport * as consts from '../../consts'\nimport { IntegrationTypingsModule } from '../../integration-implementation/integration-typings'\nimport { InterfaceTypingsModule } from '../../interface-implementation'\nimport { Module, ReExportTypeModule, SingleFileModule } from '../../module'\nimport { ActionsModule } from './actions-module'\nimport { DefaultConfigurationModule } from './configuration-module'\nimport { EventsModule } from './events-module'\nimport { StatesModule } from './states-module'\nimport { TablesModule } from './tables-module'\nimport { WorkflowsModule } from './workflows-module'\n\nclass PluginIntegrationsModule extends ReExportTypeModule {\n public constructor(plugin: sdk.PluginDefinition) {\n super({\n exportName: 'Integrations',\n })\n\n for (const [alias, integration] of Object.entries(plugin.integrations ?? {})) {\n const integrationModule = new IntegrationTypingsModule(integration.definition)\n integrationModule.unshift(alias)\n this.pushDep(integrationModule)\n }\n }\n}\n\nclass PluginInterfacesModule extends ReExportTypeModule {\n public constructor(plugin: sdk.PluginDefinition) {\n super({\n exportName: 'Interfaces',\n })\n\n for (const [alias, intrface] of Object.entries(plugin.interfaces ?? {})) {\n const interfaceModule = new InterfaceTypingsModule(intrface.definition)\n interfaceModule.unshift(alias)\n this.pushDep(interfaceModule)\n }\n }\n}\n\ntype PluginTypingsIndexDependencies = {\n integrationsModule: PluginIntegrationsModule\n interfacesModule: PluginInterfacesModule\n defaultConfigModule: DefaultConfigurationModule\n eventsModule: EventsModule\n statesModule: StatesModule\n actionsModule: ActionsModule\n tablesModule: TablesModule\n workflowsModule: WorkflowsModule\n}\n\ntype _assertPropsInPluginDefinition = utils.types.AssertKeyOf<'props', sdk.PluginDefinition>\nconst _isLocalPluginDefinition = (\n plugin: sdk.PluginDefinition | sdk.PluginPackage['definition']\n): plugin is sdk.PluginDefinition => {\n return 'props' in plugin\n}\n\nexport class PluginTypingsModule extends Module {\n private _dependencies: PluginTypingsIndexDependencies\n\n public constructor(private _plugin: sdk.PluginDefinition | sdk.PluginPackage['definition']) {\n super({\n exportName: 'TPlugin',\n path: consts.INDEX_FILE,\n })\n\n const integrationsModule = _isLocalPluginDefinition(_plugin)\n ? new PluginIntegrationsModule(_plugin)\n : new SingleFileModule({\n path: consts.INDEX_FILE,\n exportName: 'Integrations',\n content: 'export type Integrations = {}',\n })\n integrationsModule.unshift('integrations')\n this.pushDep(integrationsModule)\n\n const interfacesModule = _isLocalPluginDefinition(_plugin)\n ? new PluginInterfacesModule(_plugin)\n : new SingleFileModule({\n path: consts.INDEX_FILE,\n exportName: 'Interfaces',\n content: 'export type Interfaces = {}',\n })\n interfacesModule.unshift('interfaces')\n this.pushDep(interfacesModule)\n\n const defaultConfigModule = new DefaultConfigurationModule(_plugin.configuration)\n defaultConfigModule.unshift('configuration')\n this.pushDep(defaultConfigModule)\n\n const eventsModule = new EventsModule(_plugin.events ?? {})\n eventsModule.unshift('events')\n this.pushDep(eventsModule)\n\n const statesModule = new StatesModule(_plugin.states ?? {})\n statesModule.unshift('states')\n this.pushDep(statesModule)\n\n const actionsModule = new ActionsModule(_plugin.actions ?? {})\n actionsModule.unshift('actions')\n this.pushDep(actionsModule)\n\n const tablesModule = new TablesModule(_plugin.tables ?? {})\n tablesModule.unshift('tables')\n this.pushDep(tablesModule)\n\n const workflowsModule = new WorkflowsModule(_plugin.workflows ?? {})\n workflowsModule.unshift('workflows')\n this.pushDep(workflowsModule)\n\n this._dependencies = {\n integrationsModule,\n interfacesModule,\n defaultConfigModule,\n eventsModule,\n statesModule,\n actionsModule,\n tablesModule,\n workflowsModule,\n }\n }\n\n public async getContent() {\n const {\n integrationsModule,\n interfacesModule,\n defaultConfigModule,\n eventsModule,\n statesModule,\n actionsModule,\n tablesModule,\n workflowsModule,\n } = this._dependencies\n\n const integrationsImport = integrationsModule.import(this)\n const interfacesImport = interfacesModule.import(this)\n const defaultConfigImport = defaultConfigModule.import(this)\n const eventsImport = eventsModule.import(this)\n const statesImport = statesModule.import(this)\n const actionsImport = actionsModule\n const tablesImport = tablesModule.import(this)\n const workflowsImport = workflowsModule\n\n return [\n consts.GENERATED_HEADER,\n `import * as ${integrationsModule.name} from './${integrationsImport}'`,\n `import * as ${interfacesModule.name} from './${interfacesImport}'`,\n `import * as ${defaultConfigModule.name} from './${defaultConfigImport}'`,\n `import * as ${eventsModule.name} from './${eventsModule.name}'`,\n `import * as ${statesModule.name} from './${statesModule.name}'`,\n `import * as ${actionsModule.name} from './${actionsImport.name}'`,\n `import * as ${tablesModule.name} from './${tablesImport}'`,\n `import * as ${workflowsModule.name} from './${workflowsImport.name}'`,\n '',\n `export * as ${integrationsModule.name} from './${integrationsImport}'`,\n `export * as ${interfacesModule.name} from './${interfacesImport}'`,\n `export * as ${defaultConfigModule.name} from './${defaultConfigImport}'`,\n `export * as ${eventsModule.name} from './${eventsImport}'`,\n `export * as ${statesModule.name} from './${statesImport}'`,\n `export * as ${actionsModule.name} from './${actionsImport.name}'`,\n `export * as ${tablesModule.name} from './${tablesImport}'`,\n `export * as ${workflowsModule.name} from './${workflowsImport.name}'`,\n '',\n 'export type TPlugin = {',\n ` name: \"${this._plugin.name}\"`,\n ` version: \"${this._plugin.version}\"`,\n ` integrations: ${integrationsModule.name}.${integrationsModule.exportName}`,\n ` interfaces: ${interfacesModule.name}.${interfacesModule.exportName}`,\n ` configuration: ${defaultConfigModule.name}.${defaultConfigModule.exportName}`,\n ` events: ${eventsModule.name}.${eventsModule.exportName}`,\n ` states: ${statesModule.name}.${statesModule.exportName}`,\n ` actions: ${actionsModule.name}.${actionsModule.exportName}`,\n ` tables: ${tablesModule.name}.${tablesModule.exportName}`,\n ` workflows: ${workflowsModule.name}.${workflowsModule.exportName}`,\n '}',\n ].join('\\n')\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,aAAwB;AACxB,iCAAyC;AACzC,sCAAuC;AACvC,oBAA6D;AAC7D,4BAA8B;AAC9B,kCAA2C;AAC3C,2BAA6B;AAC7B,2BAA6B;AAC7B,2BAA6B;AAC7B,8BAAgC;AAEhC,MAAM,iCAAiC,iCAAmB;AAAA,EACjD,YAAY,QAA8B;AAC/C,UAAM;AAAA,MACJ,YAAY;AAAA,IACd,CAAC;AAED,eAAW,CAAC,OAAO,WAAW,KAAK,OAAO,QAAQ,OAAO,gBAAgB,CAAC,CAAC,GAAG;AAC5E,YAAM,oBAAoB,IAAI,oDAAyB,YAAY,UAAU;AAC7E,wBAAkB,QAAQ,KAAK;
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as utils from '../../../utils'\nimport * as consts from '../../consts'\nimport { IntegrationTypingsModule } from '../../integration-implementation/integration-typings'\nimport { InterfaceTypingsModule } from '../../interface-implementation'\nimport { Module, ReExportTypeModule, SingleFileModule } from '../../module'\nimport * as strings from '../../strings'\nimport { ActionsModule } from './actions-module'\nimport { DefaultConfigurationModule } from './configuration-module'\nimport { EventsModule } from './events-module'\nimport { StatesModule } from './states-module'\nimport { TablesModule } from './tables-module'\nimport { WorkflowsModule } from './workflows-module'\n\nclass PluginIntegrationsModule extends ReExportTypeModule {\n public constructor(plugin: sdk.PluginDefinition) {\n super({\n exportName: 'Integrations',\n })\n\n for (const [alias, integration] of Object.entries(plugin.integrations ?? {})) {\n const integrationModule = new IntegrationTypingsModule(integration.definition)\n integrationModule.unshift(strings.dirName(alias))\n this.pushDep(integrationModule)\n }\n }\n}\n\nclass PluginInterfacesModule extends ReExportTypeModule {\n public constructor(plugin: sdk.PluginDefinition) {\n super({\n exportName: 'Interfaces',\n })\n\n for (const [alias, intrface] of Object.entries(plugin.interfaces ?? {})) {\n const interfaceModule = new InterfaceTypingsModule(intrface.definition)\n interfaceModule.unshift(strings.dirName(alias))\n this.pushDep(interfaceModule)\n }\n }\n}\n\ntype PluginTypingsIndexDependencies = {\n integrationsModule: PluginIntegrationsModule\n interfacesModule: PluginInterfacesModule\n defaultConfigModule: DefaultConfigurationModule\n eventsModule: EventsModule\n statesModule: StatesModule\n actionsModule: ActionsModule\n tablesModule: TablesModule\n workflowsModule: WorkflowsModule\n}\n\ntype _assertPropsInPluginDefinition = utils.types.AssertKeyOf<'props', sdk.PluginDefinition>\nconst _isLocalPluginDefinition = (\n plugin: sdk.PluginDefinition | sdk.PluginPackage['definition']\n): plugin is sdk.PluginDefinition => {\n return 'props' in plugin\n}\n\nexport class PluginTypingsModule extends Module {\n private _dependencies: PluginTypingsIndexDependencies\n\n public constructor(private _plugin: sdk.PluginDefinition | sdk.PluginPackage['definition']) {\n super({\n exportName: 'TPlugin',\n path: consts.INDEX_FILE,\n })\n\n const integrationsModule = _isLocalPluginDefinition(_plugin)\n ? new PluginIntegrationsModule(_plugin)\n : new SingleFileModule({\n path: consts.INDEX_FILE,\n exportName: 'Integrations',\n content: 'export type Integrations = {}',\n })\n integrationsModule.unshift('integrations')\n this.pushDep(integrationsModule)\n\n const interfacesModule = _isLocalPluginDefinition(_plugin)\n ? new PluginInterfacesModule(_plugin)\n : new SingleFileModule({\n path: consts.INDEX_FILE,\n exportName: 'Interfaces',\n content: 'export type Interfaces = {}',\n })\n interfacesModule.unshift('interfaces')\n this.pushDep(interfacesModule)\n\n const defaultConfigModule = new DefaultConfigurationModule(_plugin.configuration)\n defaultConfigModule.unshift('configuration')\n this.pushDep(defaultConfigModule)\n\n const eventsModule = new EventsModule(_plugin.events ?? {})\n eventsModule.unshift('events')\n this.pushDep(eventsModule)\n\n const statesModule = new StatesModule(_plugin.states ?? {})\n statesModule.unshift('states')\n this.pushDep(statesModule)\n\n const actionsModule = new ActionsModule(_plugin.actions ?? {})\n actionsModule.unshift('actions')\n this.pushDep(actionsModule)\n\n const tablesModule = new TablesModule(_plugin.tables ?? {})\n tablesModule.unshift('tables')\n this.pushDep(tablesModule)\n\n const workflowsModule = new WorkflowsModule(_plugin.workflows ?? {})\n workflowsModule.unshift('workflows')\n this.pushDep(workflowsModule)\n\n this._dependencies = {\n integrationsModule,\n interfacesModule,\n defaultConfigModule,\n eventsModule,\n statesModule,\n actionsModule,\n tablesModule,\n workflowsModule,\n }\n }\n\n public async getContent() {\n const {\n integrationsModule,\n interfacesModule,\n defaultConfigModule,\n eventsModule,\n statesModule,\n actionsModule,\n tablesModule,\n workflowsModule,\n } = this._dependencies\n\n const integrationsImport = integrationsModule.import(this)\n const interfacesImport = interfacesModule.import(this)\n const defaultConfigImport = defaultConfigModule.import(this)\n const eventsImport = eventsModule.import(this)\n const statesImport = statesModule.import(this)\n const actionsImport = actionsModule\n const tablesImport = tablesModule.import(this)\n const workflowsImport = workflowsModule\n\n return [\n consts.GENERATED_HEADER,\n `import * as ${integrationsModule.name} from './${integrationsImport}'`,\n `import * as ${interfacesModule.name} from './${interfacesImport}'`,\n `import * as ${defaultConfigModule.name} from './${defaultConfigImport}'`,\n `import * as ${eventsModule.name} from './${eventsModule.name}'`,\n `import * as ${statesModule.name} from './${statesModule.name}'`,\n `import * as ${actionsModule.name} from './${actionsImport.name}'`,\n `import * as ${tablesModule.name} from './${tablesImport}'`,\n `import * as ${workflowsModule.name} from './${workflowsImport.name}'`,\n '',\n `export * as ${integrationsModule.name} from './${integrationsImport}'`,\n `export * as ${interfacesModule.name} from './${interfacesImport}'`,\n `export * as ${defaultConfigModule.name} from './${defaultConfigImport}'`,\n `export * as ${eventsModule.name} from './${eventsImport}'`,\n `export * as ${statesModule.name} from './${statesImport}'`,\n `export * as ${actionsModule.name} from './${actionsImport.name}'`,\n `export * as ${tablesModule.name} from './${tablesImport}'`,\n `export * as ${workflowsModule.name} from './${workflowsImport.name}'`,\n '',\n 'export type TPlugin = {',\n ` name: \"${this._plugin.name}\"`,\n ` version: \"${this._plugin.version}\"`,\n ` integrations: ${integrationsModule.name}.${integrationsModule.exportName}`,\n ` interfaces: ${interfacesModule.name}.${interfacesModule.exportName}`,\n ` configuration: ${defaultConfigModule.name}.${defaultConfigModule.exportName}`,\n ` events: ${eventsModule.name}.${eventsModule.exportName}`,\n ` states: ${statesModule.name}.${statesModule.exportName}`,\n ` actions: ${actionsModule.name}.${actionsModule.exportName}`,\n ` tables: ${tablesModule.name}.${tablesModule.exportName}`,\n ` workflows: ${workflowsModule.name}.${workflowsModule.exportName}`,\n '}',\n ].join('\\n')\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,aAAwB;AACxB,iCAAyC;AACzC,sCAAuC;AACvC,oBAA6D;A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A,MAC9E,aAAa,aAAa,IAAI,IAAI,aAAa,UAAU;AAAA,MACzD,aAAa,aAAa,IAAI,IAAI,aAAa,UAAU;AAAA,MACzD,cAAc,cAAc,IAAI,IAAI,cAAc,UAAU;AAAA,MAC5D,aAAa,aAAa,IAAI,IAAI,aAAa,UAAU;AAAA,MACzD,gBAAgB,gBAAgB,IAAI,IAAI,gBAAgB,UAAU;AAAA,MAClE;AAAA,IACF,EAAE,KAAK,IAAI;AAAA,EACb;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,3 +2,4 @@ export declare const typeName: (name: string) => string;
|
|
|
2
2
|
export declare const importAlias: (name: string) => string;
|
|
3
3
|
export declare const varName: (name: string) => string;
|
|
4
4
|
export declare const fileName: (name: string) => string;
|
|
5
|
+
export declare const dirName: (name: string) => string;
|
|
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var strings_exports = {};
|
|
30
30
|
__export(strings_exports, {
|
|
31
|
+
dirName: () => dirName,
|
|
31
32
|
fileName: () => fileName,
|
|
32
33
|
importAlias: () => importAlias,
|
|
33
34
|
typeName: () => typeName,
|
|
@@ -110,8 +111,10 @@ const typeName = (name) => apply(name, utils.casing.to.pascalCase);
|
|
|
110
111
|
const importAlias = (name) => apply(name, utils.casing.to.camelCase, escapeTypescriptReserved);
|
|
111
112
|
const varName = (name) => apply(name, utils.casing.to.camelCase, escapeTypescriptReserved);
|
|
112
113
|
const fileName = (name) => apply(name, escapeFileNameSpecialChars);
|
|
114
|
+
const dirName = fileName;
|
|
113
115
|
// Annotate the CommonJS export names for ESM import in node:
|
|
114
116
|
0 && (module.exports = {
|
|
117
|
+
dirName,
|
|
115
118
|
fileName,
|
|
116
119
|
importAlias,
|
|
117
120
|
typeName,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/code-generation/strings.ts"],
|
|
4
|
-
"sourcesContent": ["import * as utils from '../utils'\ntype StrTransform = (str: string) => string\n\nconst TYPESCRIPT_RESERVED_TOKENS = new Set([\n 'break',\n 'as',\n 'any',\n 'case',\n 'implements',\n 'boolean',\n 'catch',\n 'interface',\n 'constructor',\n 'class',\n 'let',\n 'declare',\n 'const',\n 'package',\n 'get',\n 'continue',\n 'private',\n 'module',\n 'debugger',\n 'protected',\n 'require',\n 'default',\n 'public',\n 'number',\n 'delete',\n 'static',\n 'set',\n 'do',\n 'yield',\n 'string',\n 'else',\n 'symbol',\n 'enum',\n 'type',\n 'export',\n 'from',\n 'extends',\n 'of',\n 'false',\n 'finally',\n 'for',\n 'function',\n 'if',\n 'import',\n 'in',\n 'instanceof',\n 'new',\n 'null',\n 'return',\n 'super',\n 'switch',\n 'this',\n 'throw',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'while',\n 'with',\n])\n\nconst SPECIAL_FILE_NAME_CHARS = /[^a-zA-Z0-9_\\-\\.]/g\n\nconst escapeTypescriptReserved = (str: string): string => {\n if (TYPESCRIPT_RESERVED_TOKENS.has(str)) {\n return `_${str}`\n }\n return str\n}\n\nconst escapeFileNameSpecialChars = (str: string): string => str.replace(SPECIAL_FILE_NAME_CHARS, '-')\n\nconst apply = (str: string, ...transforms: StrTransform[]) => transforms.reduce((acc, transform) => transform(acc), str)\n\nexport const typeName = (name: string) => apply(name, utils.casing.to.pascalCase)\nexport const importAlias = (name: string) => apply(name, utils.casing.to.camelCase, escapeTypescriptReserved)\nexport const varName = (name: string) => apply(name, utils.casing.to.camelCase, escapeTypescriptReserved)\nexport const fileName = (name: string) => apply(name, escapeFileNameSpecialChars)\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AAGvB,MAAM,6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B,MAAM,MAAM,0BAA0B;",
|
|
4
|
+
"sourcesContent": ["import * as utils from '../utils'\ntype StrTransform = (str: string) => string\n\nconst TYPESCRIPT_RESERVED_TOKENS = new Set([\n 'break',\n 'as',\n 'any',\n 'case',\n 'implements',\n 'boolean',\n 'catch',\n 'interface',\n 'constructor',\n 'class',\n 'let',\n 'declare',\n 'const',\n 'package',\n 'get',\n 'continue',\n 'private',\n 'module',\n 'debugger',\n 'protected',\n 'require',\n 'default',\n 'public',\n 'number',\n 'delete',\n 'static',\n 'set',\n 'do',\n 'yield',\n 'string',\n 'else',\n 'symbol',\n 'enum',\n 'type',\n 'export',\n 'from',\n 'extends',\n 'of',\n 'false',\n 'finally',\n 'for',\n 'function',\n 'if',\n 'import',\n 'in',\n 'instanceof',\n 'new',\n 'null',\n 'return',\n 'super',\n 'switch',\n 'this',\n 'throw',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'while',\n 'with',\n])\n\nconst SPECIAL_FILE_NAME_CHARS = /[^a-zA-Z0-9_\\-\\.]/g\n\nconst escapeTypescriptReserved = (str: string): string => {\n if (TYPESCRIPT_RESERVED_TOKENS.has(str)) {\n return `_${str}`\n }\n return str\n}\n\nconst escapeFileNameSpecialChars = (str: string): string => str.replace(SPECIAL_FILE_NAME_CHARS, '-')\n\nconst apply = (str: string, ...transforms: StrTransform[]) => transforms.reduce((acc, transform) => transform(acc), str)\n\nexport const typeName = (name: string) => apply(name, utils.casing.to.pascalCase)\nexport const importAlias = (name: string) => apply(name, utils.casing.to.camelCase, escapeTypescriptReserved)\nexport const varName = (name: string) => apply(name, utils.casing.to.camelCase, escapeTypescriptReserved)\nexport const fileName = (name: string) => apply(name, escapeFileNameSpecialChars)\nexport const dirName = fileName\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AAGvB,MAAM,6BAA6B,oBAAI,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0BAA0B;AACzE,MAAM,UAAU;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -50,7 +50,7 @@ class AddCommand extends import_global_command.GlobalCommand {
|
|
|
50
50
|
return await this._addNewSinglePackage({ ...ref, alias: this.argv.alias });
|
|
51
51
|
}
|
|
52
52
|
const pkgJson = await utils.pkgJson.readPackageJson(this.argv.installPath).catch((thrown) => {
|
|
53
|
-
throw errors.BotpressCLIError.wrap(thrown, "
|
|
53
|
+
throw errors.BotpressCLIError.wrap(thrown, "Failed to read package.json file");
|
|
54
54
|
});
|
|
55
55
|
if (!pkgJson) {
|
|
56
56
|
this.logger.warn("No package.json found in the install path");
|
|
@@ -299,7 +299,9 @@ class AddCommand extends import_global_command.GlobalCommand {
|
|
|
299
299
|
});
|
|
300
300
|
}
|
|
301
301
|
async _addDependencyToPackage(packageName, targetPackage) {
|
|
302
|
-
const pkgJson = await utils.pkgJson.readPackageJson(this.argv.installPath)
|
|
302
|
+
const pkgJson = await utils.pkgJson.readPackageJson(this.argv.installPath).catch((thrown) => {
|
|
303
|
+
throw errors.BotpressCLIError.wrap(thrown, "Failed to read package.json file");
|
|
304
|
+
});
|
|
303
305
|
const version = targetPackage.pkg.path ?? `${targetPackage.type}:${targetPackage.pkg.name}@${targetPackage.pkg.version}`;
|
|
304
306
|
if (!pkgJson) {
|
|
305
307
|
this.logger.warn("No package.json found in the install path");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/add-command.ts"],
|
|
4
|
-
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as fslib from 'fs'\nimport * as pathlib from 'path'\nimport semver from 'semver'\nimport * as apiUtils from '../api'\nimport * as codegen from '../code-generation'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as pkgRef from '../package-ref'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\nimport {\n ProjectCache,\n ProjectCommand,\n ProjectCommandDefinition,\n ProjectDefinitionLazy,\n ProjectDefinition,\n} from './project-command'\n\ntype InstallablePackage =\n | {\n type: 'integration'\n pkg: codegen.IntegrationInstallablePackage\n }\n | {\n type: 'interface'\n pkg: codegen.InterfaceInstallablePackage\n }\n | {\n type: 'plugin'\n pkg: codegen.PluginInstallablePackage\n }\n\ntype RefWithAlias = pkgRef.PackageRef & { alias?: string }\n\nexport type AddCommandDefinition = typeof commandDefinitions.add\nexport class AddCommand extends GlobalCommand<AddCommandDefinition> {\n public async run(): Promise<void> {\n const ref = this._parseArgvRef()\n if (ref) {\n return await this._addNewSinglePackage({ ...ref, alias: this.argv.alias })\n }\n\n const pkgJson = await utils.pkgJson.readPackageJson(this.argv.installPath).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'failed to read package.json file')\n })\n\n if (!pkgJson) {\n this.logger.warn('No package.json found in the install path')\n return\n }\n\n const { bpDependencies } = pkgJson\n if (!bpDependencies) {\n this.logger.log('No bp dependencies found in package.json')\n return\n }\n\n const bpDependenciesSchema = sdk.z.record(sdk.z.string())\n const parseResults = bpDependenciesSchema.safeParse(bpDependencies)\n if (!parseResults.success) {\n throw new errors.BotpressCLIError('Invalid bpDependencies found in package.json')\n }\n\n for (const [pkgAlias, pkgRefStr] of Object.entries(parseResults.data)) {\n const parsed = pkgRef.parsePackageRef(pkgRefStr)\n if (!parsed) {\n throw new errors.InvalidPackageReferenceError(pkgRefStr)\n }\n\n await this._addSinglePackage({ ...parsed, alias: pkgAlias })\n }\n }\n\n private _parseArgvRef = (): pkgRef.PackageRef | undefined => {\n if (!this.argv.packageRef) {\n return\n }\n\n const parsed = pkgRef.parsePackageRef(this.argv.packageRef)\n if (!parsed) {\n throw new errors.InvalidPackageReferenceError(this.argv.packageRef)\n }\n\n if (parsed.type !== 'name') {\n return parsed\n }\n\n const argvPkgType = this.argv.packageType\n if (!argvPkgType) {\n return parsed\n }\n\n const ref = { ...parsed, pkg: argvPkgType }\n\n const strRef = pkgRef.formatPackageRef(ref)\n this.logger.warn(`argument --packageType is deprecated; please use the package reference format \"${strRef}\"`)\n\n return ref\n }\n\n private async _addSinglePackage(ref: RefWithAlias) {\n const { packageName, targetPackage } = await this._findPackage(ref)\n\n const baseInstallPath = utils.path.absoluteFrom(utils.path.cwd(), this.argv.installPath)\n const packageDirName = utils.casing.to.kebabCase(packageName)\n const installPath = utils.path.join(baseInstallPath, consts.installDirName, packageDirName)\n\n const alreadyInstalled = fslib.existsSync(installPath)\n if (alreadyInstalled) {\n this.logger.warn(`Package with name \"${packageName}\" already installed.`)\n const res = await this.prompt.confirm('Do you want to overwrite the existing package?')\n if (!res) {\n throw new errors.AbortedOperationError()\n }\n\n await this._uninstall(installPath)\n }\n\n if (ref.type === 'name' && ref.version === pkgRef.LATEST_TAG) {\n // If the semver version expression is 'latest', we assume the project\n // is compatible with all versions of the latest major:\n const major = semver.major(targetPackage.pkg.version)\n targetPackage.pkg.version = `>=${major}.0.0 <${major + 1}.0.0`\n\n this.logger.log(\n `Dependency \"${packageName}\" will be installed with version \"${targetPackage.pkg.version}\". ` +\n `To pin a specific version or version range, please change \"${targetPackage.type}:${packageName}@latest\" ` +\n 'to a specific version number or range instead of \"latest\".'\n )\n } else if (ref.type === 'name') {\n // Preserve the semver version expression in the generated code:\n targetPackage.pkg.version = ref.version\n }\n\n let files: codegen.File[]\n if (targetPackage.type === 'integration') {\n files = await codegen.generateIntegrationPackage(targetPackage.pkg)\n } else if (targetPackage.type === 'interface') {\n files = await codegen.generateInterfacePackage(targetPackage.pkg)\n } else if (targetPackage.type === 'plugin') {\n files = await codegen.generatePluginPackage(targetPackage.pkg)\n } else {\n type _assertion = utils.types.AssertNever<typeof targetPackage>\n throw new errors.BotpressCLIError('Invalid package type')\n }\n\n await this._install(installPath, files)\n }\n\n private async _addNewSinglePackage(ref: RefWithAlias) {\n await this._addSinglePackage(ref)\n const { packageName, targetPackage } = await this._findPackage(ref)\n await this._addDependencyToPackage(packageName, targetPackage)\n }\n\n private async _findPackage(ref: RefWithAlias): Promise<{ packageName: string; targetPackage: InstallablePackage }> {\n const targetPackage = ref.type === 'path' ? await this._findLocalPackage(ref) : await this._findRemotePackage(ref)\n if (!targetPackage) {\n const strRef = pkgRef.formatPackageRef(ref)\n throw new errors.BotpressCLIError(`Could not find package \"${strRef}\"`)\n }\n const packageName = ref.alias ?? targetPackage.pkg.name\n\n return { packageName, targetPackage }\n }\n\n private async _findRemotePackage(ref: pkgRef.ApiPackageRef): Promise<InstallablePackage | undefined> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n if (this._pkgCouldBe(ref, 'integration')) {\n const integration = await api.findPublicOrPrivateIntegration(ref)\n if (integration) {\n const { name, version } = integration\n return { type: 'integration', pkg: { integration, name, version } }\n }\n }\n if (this._pkgCouldBe(ref, 'interface')) {\n const intrface = await api.findPublicOrPrivateInterface(ref)\n if (intrface) {\n const { name, version } = intrface\n return { type: 'interface', pkg: { interface: intrface, name, version } }\n }\n }\n if (this._pkgCouldBe(ref, 'plugin')) {\n const plugin = await api.findPublicOrPrivatePlugin(ref)\n if (plugin) {\n const { code } = plugin.public\n ? await api.client.getPublicPluginCode({ id: plugin.id, platform: 'node' })\n : await api.client.getPluginCode({ id: plugin.id, platform: 'node' })\n const { name, version } = plugin\n return {\n type: 'plugin',\n pkg: {\n name,\n version,\n plugin,\n code,\n },\n }\n }\n }\n return\n }\n\n private async _findLocalPackage(ref: pkgRef.LocalPackageRef): Promise<InstallablePackage | undefined> {\n const absPath = utils.path.absoluteFrom(utils.path.cwd(), ref.path)\n const {\n definition: projectDefinition,\n implementation: projectImplementation,\n devId: projectDevId,\n } = await this._readProject(absPath)\n\n if (projectDefinition?.type === 'integration') {\n const { name, version } = projectDefinition.definition\n let devId: string | undefined\n if (this.argv.useDev && projectDevId) {\n this.logger.warn(`Installing integration \"${name}\" with dev version \"${projectDevId}\"`)\n devId = projectDevId\n }\n\n let createIntegrationReqBody = await this._getProjectCmd(ref.path).prepareCreateIntegrationBody(\n projectDefinition.definition\n )\n createIntegrationReqBody = {\n ...createIntegrationReqBody,\n interfaces: utils.records.mapValues(projectDefinition.definition.interfaces ?? {}, (i) => ({\n id: '', // TODO: do this better\n ...i,\n })),\n }\n return {\n type: 'integration',\n pkg: { path: absPath, devId, name, version, integration: createIntegrationReqBody },\n }\n }\n\n if (projectDefinition?.type === 'interface') {\n const { name, version } = projectDefinition.definition\n const createInterfaceReqBody = await apiUtils.prepareCreateInterfaceBody(projectDefinition.definition)\n return {\n type: 'interface',\n pkg: { path: absPath, name, version, interface: createInterfaceReqBody },\n }\n }\n\n if (projectDefinition?.type === 'plugin') {\n if (!projectImplementation) {\n throw new errors.BotpressCLIError(\n 'Plugin implementation not found; Please build the plugin project before installing'\n )\n }\n\n const pluginDefinition = projectDefinition.definition\n const { name, version } = pluginDefinition\n const code = projectImplementation\n\n const createPluginReqBody = await apiUtils.prepareCreatePluginBody(pluginDefinition)\n return {\n type: 'plugin',\n pkg: {\n path: absPath,\n name,\n version,\n code,\n plugin: {\n ...createPluginReqBody,\n dependencies: {\n interfaces: pluginDefinition.interfaces,\n integrations: pluginDefinition.integrations,\n },\n recurringEvents: pluginDefinition.recurringEvents,\n },\n },\n }\n }\n\n if (projectDefinition?.type === 'bot') {\n throw new errors.BotpressCLIError('Cannot install a bot as a package')\n }\n return\n }\n\n private async _install(installPath: utils.path.AbsolutePath, files: codegen.File[]): Promise<void> {\n const line = this.logger.line()\n line.started(`Installing ${files.length} files to \"${installPath}\"`)\n try {\n for (const file of files) {\n const filePath = utils.path.absoluteFrom(installPath, file.path)\n const dirPath = pathlib.dirname(filePath)\n await fslib.promises.mkdir(dirPath, { recursive: true })\n await fslib.promises.writeFile(filePath, file.content)\n }\n line.success(`Installed ${files.length} files to \"${installPath}\"`)\n } finally {\n line.commit()\n }\n }\n\n private async _uninstall(installPath: utils.path.AbsolutePath): Promise<void> {\n await fslib.promises.rm(installPath, { recursive: true })\n }\n\n private async _readProject(workDir: utils.path.AbsolutePath): Promise<{\n definition?: ProjectDefinition\n implementation?: string\n devId?: string\n }> {\n const cmd = this._getProjectCmd(workDir)\n\n const { resolveProjectDefinition } = cmd.readProjectDefinitionFromFS()\n const definition = await resolveProjectDefinition().catch((thrown) => {\n if (thrown instanceof errors.ProjectDefinitionNotFoundError) {\n return undefined\n }\n throw thrown\n })\n\n const devId = await cmd.projectCache.get('devId')\n\n const implementationAbsPath = utils.path.join(workDir, consts.fromWorkDir.outFileCJS)\n if (!fslib.existsSync(implementationAbsPath)) {\n return { definition, devId }\n }\n\n const implementation = await fslib.promises.readFile(implementationAbsPath, 'utf8')\n return { definition, implementation, devId }\n }\n\n private _pkgCouldBe = (ref: pkgRef.ApiPackageRef, pkgType: InstallablePackage['type']) => {\n if (ref.type === 'id') {\n // TODO: use ULID prefixes to determine the type of the package\n return true\n }\n if (!ref.pkg) {\n return true // ref does not specify the package type\n }\n return ref.pkg === pkgType\n }\n\n private _getProjectCmd(workDir: string): _AnyProjectCommand {\n return new _AnyProjectCommand(apiUtils.ApiClient, this.prompt, this.logger, {\n ...this.argv,\n workDir,\n })\n }\n\n private async _addDependencyToPackage(packageName: string, targetPackage: InstallablePackage) {\n const pkgJson = await utils.pkgJson.readPackageJson(this.argv.installPath)\n const version =\n targetPackage.pkg.path ?? `${targetPackage.type}:${targetPackage.pkg.name}@${targetPackage.pkg.version}`\n if (!pkgJson) {\n this.logger.warn('No package.json found in the install path')\n return\n }\n\n const { bpDependencies } = pkgJson\n if (!bpDependencies) {\n pkgJson.bpDependencies = { [packageName]: version }\n await utils.pkgJson.writePackageJson(this.argv.installPath, pkgJson)\n return\n }\n\n const bpDependenciesSchema = sdk.z.record(sdk.z.string())\n const parseResult = bpDependenciesSchema.safeParse(bpDependencies)\n if (!parseResult.success) {\n throw new errors.BotpressCLIError('Invalid bpDependencies found in package.json')\n }\n\n const { data: validatedBpDeps } = parseResult\n\n const alreadyPresentDep = Object.entries(validatedBpDeps).find(([key]) => key === packageName)\n if (alreadyPresentDep) {\n if (alreadyPresentDep[1] !== version) {\n this.logger.warn(\n `The dependency ${packageName} is already present in the bpDependencies of package.json. It will not be replaced.`\n )\n }\n return\n }\n\n pkgJson.bpDependencies = {\n ...validatedBpDeps,\n [packageName]: version,\n }\n\n await utils.pkgJson.writePackageJson(this.argv.installPath, pkgJson)\n }\n}\n\n// this is a hack to avoid refactoring the project command class\nclass _AnyProjectCommand extends ProjectCommand<ProjectCommandDefinition> {\n public async run(): Promise<void> {\n throw new errors.BotpressCLIError('Not implemented')\n }\n\n public readProjectDefinitionFromFS(): ProjectDefinitionLazy {\n return super.readProjectDefinitionFromFS()\n }\n\n public async prepareCreateIntegrationBody(\n integrationDef: sdk.IntegrationDefinition\n ): Promise<apiUtils.CreateIntegrationRequestBody> {\n return super.prepareCreateIntegrationBody(integrationDef)\n }\n\n public get projectCache(): utils.cache.FSKeyValueCache<ProjectCache> {\n return super.projectCache\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAAqB;AACrB,YAAuB;AACvB,cAAyB;AACzB,oBAAmB;AACnB,eAA0B;AAC1B,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,4BAA8B;AAC9B,6BAMO;AAmBA,MAAM,mBAAmB,oCAAoC;AAAA,EAClE,MAAa,MAAqB;AAChC,UAAM,MAAM,KAAK,cAAc;AAC/B,QAAI,KAAK;AACP,aAAO,MAAM,KAAK,qBAAqB,EAAE,GAAG,KAAK,OAAO,KAAK,KAAK,MAAM,CAAC;AAAA,IAC3E;AAEA,UAAM,UAAU,MAAM,MAAM,QAAQ,gBAAgB,KAAK,KAAK,WAAW,EAAE,MAAM,CAAC,WAAW;AAC3F,YAAM,OAAO,iBAAiB,KAAK,QAAQ,kCAAkC;AAAA,IAC/E,CAAC;AAED,QAAI,CAAC,SAAS;AACZ,WAAK,OAAO,KAA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AA,EAEA,MAAc,WAAW,aAAqD;AAC5E,UAAM,MAAM,SAAS,GAAG,aAAa,EAAE,WAAW,KAAK,CAAC;AAAA,EAC1D;AAAA,EAEA,MAAc,aAAa,SAIxB;AACD,UAAM,MAAM,KAAK,eAAe,OAAO;AAEvC,UAAM,EAAE,yBAAyB,IAAI,IAAI,4BAA4B;AACrE,UAAM,aAAa,MAAM,yBAAyB,EAAE,MAAM,CAAC,WAAW;AACpE,UAAI,kBAAkB,OAAO,gCAAgC;AAC3D,eAAO;AAAA,MACT;AACA,YAAM;AAAA,IACR,CAAC;AAED,UAAM,QAAQ,MAAM,IAAI,aAAa,IAAI,OAAO;AAEhD,UAAM,wBAAwB,MAAM,KAAK,KAAK,SAAS,OAAO,YAAY,UAAU;AACpF,QAAI,CAAC,MAAM,WAAW,qBAAqB,GAAG;AAC5C,aAAO,EAAE,YAAY,MAAM;AAAA,IAC7B;AAEA,UAAM,iBAAiB,MAAM,MAAM,SAAS,SAAS,uBAAuB,MAAM;AAClF,WAAO,EAAE,YAAY,gBAAgB,MAAM;AAAA,EAC7C;AAAA,EAEQ,cAAc,CAAC,KAA2B,YAAwC;AACxF,QAAI,IAAI,SAAS,MAAM;AAErB,aAAO;AAAA,IACT;AACA,QAAI,CAAC,IAAI,KAAK;AACZ,aAAO;AAAA,IACT;AACA,WAAO,IAAI,QAAQ;AAAA,EACrB;AAAA,EAEQ,eAAe,SAAqC;AAC1D,WAAO,IAAI,mBAAmB,SAAS,WAAW,KAAK,QAAQ,KAAK,QAAQ;AAAA,MAC1E,GAAG,KAAK;AAAA,MACR;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAc,wBAAwB,aAAqB,eAAmC;AAC5F,UAAM,UAAU,MAAM,MAAM,QAAQ,gBAAgB,KAAK,KAAK,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as fslib from 'fs'\nimport * as pathlib from 'path'\nimport semver from 'semver'\nimport * as apiUtils from '../api'\nimport * as codegen from '../code-generation'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as pkgRef from '../package-ref'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\nimport {\n ProjectCache,\n ProjectCommand,\n ProjectCommandDefinition,\n ProjectDefinitionLazy,\n ProjectDefinition,\n} from './project-command'\n\ntype InstallablePackage =\n | {\n type: 'integration'\n pkg: codegen.IntegrationInstallablePackage\n }\n | {\n type: 'interface'\n pkg: codegen.InterfaceInstallablePackage\n }\n | {\n type: 'plugin'\n pkg: codegen.PluginInstallablePackage\n }\n\ntype RefWithAlias = pkgRef.PackageRef & { alias?: string }\n\nexport type AddCommandDefinition = typeof commandDefinitions.add\nexport class AddCommand extends GlobalCommand<AddCommandDefinition> {\n public async run(): Promise<void> {\n const ref = this._parseArgvRef()\n if (ref) {\n return await this._addNewSinglePackage({ ...ref, alias: this.argv.alias })\n }\n\n const pkgJson = await utils.pkgJson.readPackageJson(this.argv.installPath).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Failed to read package.json file')\n })\n\n if (!pkgJson) {\n this.logger.warn('No package.json found in the install path')\n return\n }\n\n const { bpDependencies } = pkgJson\n if (!bpDependencies) {\n this.logger.log('No bp dependencies found in package.json')\n return\n }\n\n const bpDependenciesSchema = sdk.z.record(sdk.z.string())\n const parseResults = bpDependenciesSchema.safeParse(bpDependencies)\n if (!parseResults.success) {\n throw new errors.BotpressCLIError('Invalid bpDependencies found in package.json')\n }\n\n for (const [pkgAlias, pkgRefStr] of Object.entries(parseResults.data)) {\n const parsed = pkgRef.parsePackageRef(pkgRefStr)\n if (!parsed) {\n throw new errors.InvalidPackageReferenceError(pkgRefStr)\n }\n\n await this._addSinglePackage({ ...parsed, alias: pkgAlias })\n }\n }\n\n private _parseArgvRef = (): pkgRef.PackageRef | undefined => {\n if (!this.argv.packageRef) {\n return\n }\n\n const parsed = pkgRef.parsePackageRef(this.argv.packageRef)\n if (!parsed) {\n throw new errors.InvalidPackageReferenceError(this.argv.packageRef)\n }\n\n if (parsed.type !== 'name') {\n return parsed\n }\n\n const argvPkgType = this.argv.packageType\n if (!argvPkgType) {\n return parsed\n }\n\n const ref = { ...parsed, pkg: argvPkgType }\n\n const strRef = pkgRef.formatPackageRef(ref)\n this.logger.warn(`argument --packageType is deprecated; please use the package reference format \"${strRef}\"`)\n\n return ref\n }\n\n private async _addSinglePackage(ref: RefWithAlias) {\n const { packageName, targetPackage } = await this._findPackage(ref)\n\n const baseInstallPath = utils.path.absoluteFrom(utils.path.cwd(), this.argv.installPath)\n const packageDirName = utils.casing.to.kebabCase(packageName)\n const installPath = utils.path.join(baseInstallPath, consts.installDirName, packageDirName)\n\n const alreadyInstalled = fslib.existsSync(installPath)\n if (alreadyInstalled) {\n this.logger.warn(`Package with name \"${packageName}\" already installed.`)\n const res = await this.prompt.confirm('Do you want to overwrite the existing package?')\n if (!res) {\n throw new errors.AbortedOperationError()\n }\n\n await this._uninstall(installPath)\n }\n\n if (ref.type === 'name' && ref.version === pkgRef.LATEST_TAG) {\n // If the semver version expression is 'latest', we assume the project\n // is compatible with all versions of the latest major:\n const major = semver.major(targetPackage.pkg.version)\n targetPackage.pkg.version = `>=${major}.0.0 <${major + 1}.0.0`\n\n this.logger.log(\n `Dependency \"${packageName}\" will be installed with version \"${targetPackage.pkg.version}\". ` +\n `To pin a specific version or version range, please change \"${targetPackage.type}:${packageName}@latest\" ` +\n 'to a specific version number or range instead of \"latest\".'\n )\n } else if (ref.type === 'name') {\n // Preserve the semver version expression in the generated code:\n targetPackage.pkg.version = ref.version\n }\n\n let files: codegen.File[]\n if (targetPackage.type === 'integration') {\n files = await codegen.generateIntegrationPackage(targetPackage.pkg)\n } else if (targetPackage.type === 'interface') {\n files = await codegen.generateInterfacePackage(targetPackage.pkg)\n } else if (targetPackage.type === 'plugin') {\n files = await codegen.generatePluginPackage(targetPackage.pkg)\n } else {\n type _assertion = utils.types.AssertNever<typeof targetPackage>\n throw new errors.BotpressCLIError('Invalid package type')\n }\n\n await this._install(installPath, files)\n }\n\n private async _addNewSinglePackage(ref: RefWithAlias) {\n await this._addSinglePackage(ref)\n const { packageName, targetPackage } = await this._findPackage(ref)\n await this._addDependencyToPackage(packageName, targetPackage)\n }\n\n private async _findPackage(ref: RefWithAlias): Promise<{ packageName: string; targetPackage: InstallablePackage }> {\n const targetPackage = ref.type === 'path' ? await this._findLocalPackage(ref) : await this._findRemotePackage(ref)\n if (!targetPackage) {\n const strRef = pkgRef.formatPackageRef(ref)\n throw new errors.BotpressCLIError(`Could not find package \"${strRef}\"`)\n }\n const packageName = ref.alias ?? targetPackage.pkg.name\n\n return { packageName, targetPackage }\n }\n\n private async _findRemotePackage(ref: pkgRef.ApiPackageRef): Promise<InstallablePackage | undefined> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n if (this._pkgCouldBe(ref, 'integration')) {\n const integration = await api.findPublicOrPrivateIntegration(ref)\n if (integration) {\n const { name, version } = integration\n return { type: 'integration', pkg: { integration, name, version } }\n }\n }\n if (this._pkgCouldBe(ref, 'interface')) {\n const intrface = await api.findPublicOrPrivateInterface(ref)\n if (intrface) {\n const { name, version } = intrface\n return { type: 'interface', pkg: { interface: intrface, name, version } }\n }\n }\n if (this._pkgCouldBe(ref, 'plugin')) {\n const plugin = await api.findPublicOrPrivatePlugin(ref)\n if (plugin) {\n const { code } = plugin.public\n ? await api.client.getPublicPluginCode({ id: plugin.id, platform: 'node' })\n : await api.client.getPluginCode({ id: plugin.id, platform: 'node' })\n const { name, version } = plugin\n return {\n type: 'plugin',\n pkg: {\n name,\n version,\n plugin,\n code,\n },\n }\n }\n }\n return\n }\n\n private async _findLocalPackage(ref: pkgRef.LocalPackageRef): Promise<InstallablePackage | undefined> {\n const absPath = utils.path.absoluteFrom(utils.path.cwd(), ref.path)\n const {\n definition: projectDefinition,\n implementation: projectImplementation,\n devId: projectDevId,\n } = await this._readProject(absPath)\n\n if (projectDefinition?.type === 'integration') {\n const { name, version } = projectDefinition.definition\n let devId: string | undefined\n if (this.argv.useDev && projectDevId) {\n this.logger.warn(`Installing integration \"${name}\" with dev version \"${projectDevId}\"`)\n devId = projectDevId\n }\n\n let createIntegrationReqBody = await this._getProjectCmd(ref.path).prepareCreateIntegrationBody(\n projectDefinition.definition\n )\n createIntegrationReqBody = {\n ...createIntegrationReqBody,\n interfaces: utils.records.mapValues(projectDefinition.definition.interfaces ?? {}, (i) => ({\n id: '', // TODO: do this better\n ...i,\n })),\n }\n return {\n type: 'integration',\n pkg: { path: absPath, devId, name, version, integration: createIntegrationReqBody },\n }\n }\n\n if (projectDefinition?.type === 'interface') {\n const { name, version } = projectDefinition.definition\n const createInterfaceReqBody = await apiUtils.prepareCreateInterfaceBody(projectDefinition.definition)\n return {\n type: 'interface',\n pkg: { path: absPath, name, version, interface: createInterfaceReqBody },\n }\n }\n\n if (projectDefinition?.type === 'plugin') {\n if (!projectImplementation) {\n throw new errors.BotpressCLIError(\n 'Plugin implementation not found; Please build the plugin project before installing'\n )\n }\n\n const pluginDefinition = projectDefinition.definition\n const { name, version } = pluginDefinition\n const code = projectImplementation\n\n const createPluginReqBody = await apiUtils.prepareCreatePluginBody(pluginDefinition)\n return {\n type: 'plugin',\n pkg: {\n path: absPath,\n name,\n version,\n code,\n plugin: {\n ...createPluginReqBody,\n dependencies: {\n interfaces: pluginDefinition.interfaces,\n integrations: pluginDefinition.integrations,\n },\n recurringEvents: pluginDefinition.recurringEvents,\n },\n },\n }\n }\n\n if (projectDefinition?.type === 'bot') {\n throw new errors.BotpressCLIError('Cannot install a bot as a package')\n }\n return\n }\n\n private async _install(installPath: utils.path.AbsolutePath, files: codegen.File[]): Promise<void> {\n const line = this.logger.line()\n line.started(`Installing ${files.length} files to \"${installPath}\"`)\n try {\n for (const file of files) {\n const filePath = utils.path.absoluteFrom(installPath, file.path)\n const dirPath = pathlib.dirname(filePath)\n await fslib.promises.mkdir(dirPath, { recursive: true })\n await fslib.promises.writeFile(filePath, file.content)\n }\n line.success(`Installed ${files.length} files to \"${installPath}\"`)\n } finally {\n line.commit()\n }\n }\n\n private async _uninstall(installPath: utils.path.AbsolutePath): Promise<void> {\n await fslib.promises.rm(installPath, { recursive: true })\n }\n\n private async _readProject(workDir: utils.path.AbsolutePath): Promise<{\n definition?: ProjectDefinition\n implementation?: string\n devId?: string\n }> {\n const cmd = this._getProjectCmd(workDir)\n\n const { resolveProjectDefinition } = cmd.readProjectDefinitionFromFS()\n const definition = await resolveProjectDefinition().catch((thrown) => {\n if (thrown instanceof errors.ProjectDefinitionNotFoundError) {\n return undefined\n }\n throw thrown\n })\n\n const devId = await cmd.projectCache.get('devId')\n\n const implementationAbsPath = utils.path.join(workDir, consts.fromWorkDir.outFileCJS)\n if (!fslib.existsSync(implementationAbsPath)) {\n return { definition, devId }\n }\n\n const implementation = await fslib.promises.readFile(implementationAbsPath, 'utf8')\n return { definition, implementation, devId }\n }\n\n private _pkgCouldBe = (ref: pkgRef.ApiPackageRef, pkgType: InstallablePackage['type']) => {\n if (ref.type === 'id') {\n // TODO: use ULID prefixes to determine the type of the package\n return true\n }\n if (!ref.pkg) {\n return true // ref does not specify the package type\n }\n return ref.pkg === pkgType\n }\n\n private _getProjectCmd(workDir: string): _AnyProjectCommand {\n return new _AnyProjectCommand(apiUtils.ApiClient, this.prompt, this.logger, {\n ...this.argv,\n workDir,\n })\n }\n\n private async _addDependencyToPackage(packageName: string, targetPackage: InstallablePackage) {\n const pkgJson = await utils.pkgJson.readPackageJson(this.argv.installPath).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Failed to read package.json file')\n })\n\n const version =\n targetPackage.pkg.path ?? `${targetPackage.type}:${targetPackage.pkg.name}@${targetPackage.pkg.version}`\n if (!pkgJson) {\n this.logger.warn('No package.json found in the install path')\n return\n }\n\n const { bpDependencies } = pkgJson\n if (!bpDependencies) {\n pkgJson.bpDependencies = { [packageName]: version }\n await utils.pkgJson.writePackageJson(this.argv.installPath, pkgJson)\n return\n }\n\n const bpDependenciesSchema = sdk.z.record(sdk.z.string())\n const parseResult = bpDependenciesSchema.safeParse(bpDependencies)\n if (!parseResult.success) {\n throw new errors.BotpressCLIError('Invalid bpDependencies found in package.json')\n }\n\n const { data: validatedBpDeps } = parseResult\n\n const alreadyPresentDep = Object.entries(validatedBpDeps).find(([key]) => key === packageName)\n if (alreadyPresentDep) {\n if (alreadyPresentDep[1] !== version) {\n this.logger.warn(\n `The dependency ${packageName} is already present in the bpDependencies of package.json. It will not be replaced.`\n )\n }\n return\n }\n\n pkgJson.bpDependencies = {\n ...validatedBpDeps,\n [packageName]: version,\n }\n\n await utils.pkgJson.writePackageJson(this.argv.installPath, pkgJson)\n }\n}\n\n// this is a hack to avoid refactoring the project command class\nclass _AnyProjectCommand extends ProjectCommand<ProjectCommandDefinition> {\n public async run(): Promise<void> {\n throw new errors.BotpressCLIError('Not implemented')\n }\n\n public readProjectDefinitionFromFS(): ProjectDefinitionLazy {\n return super.readProjectDefinitionFromFS()\n }\n\n public async prepareCreateIntegrationBody(\n integrationDef: sdk.IntegrationDefinition\n ): Promise<apiUtils.CreateIntegrationRequestBody> {\n return super.prepareCreateIntegrationBody(integrationDef)\n }\n\n public get projectCache(): utils.cache.FSKeyValueCache<ProjectCache> {\n return super.projectCache\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAAqB;AACrB,YAAuB;AACvB,cAAyB;AACzB,oBAAmB;AACnB,eAA0B;AAC1B,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,4BAA8B;AAC9B,6BAMO;AAmBA,MAAM,mBAAmB,oCAAoC;AAAA,EAClE,MAAa,MAAqB;AAChC,UAAM,MAAM,KAAK,cAAc;AAC/B,QAAI,KAAK;AACP,aAAO,MAAM,KAAK,qBAAqB,EAAE,GAAG,KAAK,OAAO,KAAK,KAAK,MAAM,CAAC;AA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OAAO,iBAAiB,iBAAiB;AAAA,EACrD;AAAA,EAEO,8BAAqD;AAC1D,WAAO,MAAM,4BAA4B;AAAA,EAC3C;AAAA,EAEA,MAAa,6BACX,gBACgD;AAChD,WAAO,MAAM,6BAA6B,cAAc;AAAA,EAC1D;AAAA,EAEA,IAAW,eAA0D;AACnE,WAAO,MAAM;AAAA,EACf;AACF;",
|
|
6
6
|
"names": ["semver"]
|
|
7
7
|
}
|
|
@@ -52,6 +52,6 @@ export declare abstract class GlobalCommand<C extends GlobalCommandDefinition> e
|
|
|
52
52
|
protected writeProfileToFS(profileName: string, profile: ProfileCredentials): Promise<void>;
|
|
53
53
|
protected ensureLoginAndCreateClient(credentials: YargsConfig<typeof config.schemas.credentials>): Promise<import("../api/client").ApiClient>;
|
|
54
54
|
private readonly _notifyUpdateCli;
|
|
55
|
-
protected
|
|
55
|
+
protected readCLIPkgJson(): Promise<utils.pkgJson.PackageJson>;
|
|
56
56
|
}
|
|
57
57
|
export {};
|
|
@@ -70,7 +70,7 @@ class GlobalCommand extends import_base_command.BaseCommand {
|
|
|
70
70
|
return new utils.cache.FSKeyValueCache(this.globalPaths.abs.globalCacheFile);
|
|
71
71
|
}
|
|
72
72
|
async bootstrap() {
|
|
73
|
-
const pkgJson = await this.
|
|
73
|
+
const pkgJson = await this.readCLIPkgJson();
|
|
74
74
|
const versionText = import_chalk.default.bold(`v${pkgJson.version}`);
|
|
75
75
|
this.logger.log(`Botpress CLI ${versionText}`, { prefix: "\u{1F916}" });
|
|
76
76
|
await this._notifyUpdateCli();
|
|
@@ -128,8 +128,11 @@ class GlobalCommand extends import_base_command.BaseCommand {
|
|
|
128
128
|
throw new errors.BotpressCLIError(`Profile file not found at "${this.globalPaths.abs.profilesPath}"`);
|
|
129
129
|
}
|
|
130
130
|
const fileContent = await fs.promises.readFile(this.globalPaths.abs.profilesPath, "utf-8");
|
|
131
|
-
const
|
|
132
|
-
|
|
131
|
+
const jsonParseResult = utils.json.safeParseJson(fileContent);
|
|
132
|
+
if (!jsonParseResult.success) {
|
|
133
|
+
throw new errors.BotpressCLIError(`Error parsing profiles file: ${jsonParseResult.error.message}`);
|
|
134
|
+
}
|
|
135
|
+
const zodParseResult = import_sdk.z.record(profileCredentialSchema).safeParse(jsonParseResult.data);
|
|
133
136
|
if (!zodParseResult.success) {
|
|
134
137
|
throw errors.BotpressCLIError.wrap(zodParseResult.error, "Error parsing profiles: ");
|
|
135
138
|
}
|
|
@@ -159,7 +162,7 @@ class GlobalCommand extends import_base_command.BaseCommand {
|
|
|
159
162
|
_notifyUpdateCli = async () => {
|
|
160
163
|
try {
|
|
161
164
|
this.logger.debug("Checking if cli is up to date");
|
|
162
|
-
const pkgJson = await this.
|
|
165
|
+
const pkgJson = await this.readCLIPkgJson();
|
|
163
166
|
if (!pkgJson.version) {
|
|
164
167
|
throw new errors.BotpressCLIError("Could not find version in package.json");
|
|
165
168
|
}
|
|
@@ -182,12 +185,14 @@ class GlobalCommand extends import_base_command.BaseCommand {
|
|
|
182
185
|
this.logger.debug(`Failed to check if cli is up to date: ${err.message}`);
|
|
183
186
|
}
|
|
184
187
|
};
|
|
185
|
-
async
|
|
188
|
+
async readCLIPkgJson() {
|
|
186
189
|
if (this._pkgJson) {
|
|
187
190
|
return this._pkgJson;
|
|
188
191
|
}
|
|
189
192
|
const { cliRootDir } = this.globalPaths.abs;
|
|
190
|
-
const pkgJson = await utils.pkgJson.readPackageJson(cliRootDir)
|
|
193
|
+
const pkgJson = await utils.pkgJson.readPackageJson(cliRootDir).catch((thrown) => {
|
|
194
|
+
throw errors.BotpressCLIError.wrap(thrown, `Failed to read CLI package.json file at "${cliRootDir}"`);
|
|
195
|
+
});
|
|
191
196
|
if (!pkgJson) {
|
|
192
197
|
throw new errors.BotpressCLIError(`Could not find package.json at "${cliRootDir}"`);
|
|
193
198
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/global-command.ts"],
|
|
4
|
-
"sourcesContent": ["import { z } from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport latestVersion from 'latest-version'\nimport _ from 'lodash'\nimport semver from 'semver'\nimport type { ApiClientFactory } from '../api/client'\nimport * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { BaseCommand } from './base-command'\n\nexport type GlobalCommandDefinition = CommandDefinition<typeof config.schemas.global>\nexport type GlobalCache = { apiUrl: string; token: string; workspaceId: string; activeProfile: string }\n\nexport type ConfigurableGlobalPaths = {\n botpressHomeDir: string\n cliRootDir: utils.path.AbsolutePath\n profilesPath: string\n}\nexport type ConstantGlobalPaths = typeof consts.fromHomeDir & typeof consts.fromCliRootDir\nexport type AllGlobalPaths = ConfigurableGlobalPaths & ConstantGlobalPaths\n\nconst profileCredentialSchema = z.object({ apiUrl: z.string(), workspaceId: z.string(), token: z.string() })\nexport type ProfileCredentials = z.infer<typeof profileCredentialSchema>\n\nclass GlobalPaths extends utils.path.PathStore<keyof AllGlobalPaths> {\n public constructor(argv: CommandArgv<GlobalCommandDefinition>) {\n const absBotpressHome = utils.path.absoluteFrom(utils.path.cwd(), argv.botpressHome)\n super({\n cliRootDir: consts.cliRootDir,\n botpressHomeDir: absBotpressHome,\n profilesPath: utils.path.absoluteFrom(absBotpressHome, consts.profileFileName),\n ..._.mapValues(consts.fromHomeDir, (p) => utils.path.absoluteFrom(absBotpressHome, p)),\n ..._.mapValues(consts.fromCliRootDir, (p) => utils.path.absoluteFrom(consts.cliRootDir, p)),\n })\n }\n}\n\nexport abstract class GlobalCommand<C extends GlobalCommandDefinition> extends BaseCommand<C> {\n protected api: ApiClientFactory\n protected prompt: utils.prompt.CLIPrompt\n private _pkgJson: utils.pkgJson.PackageJson | undefined\n\n public constructor(\n api: ApiClientFactory,\n prompt: utils.prompt.CLIPrompt,\n ...args: ConstructorParameters<typeof BaseCommand<C>>\n ) {\n super(...args)\n this.api = api\n this.prompt = prompt\n }\n\n protected get globalPaths() {\n return new GlobalPaths(this.argv)\n }\n\n protected get globalCache() {\n return new utils.cache.FSKeyValueCache<GlobalCache>(this.globalPaths.abs.globalCacheFile)\n }\n\n protected override async bootstrap() {\n const pkgJson = await this.
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAkB;AAElB,mBAAkB;AAClB,SAAoB;AACpB,4BAA0B;AAC1B,oBAAc;AACd,oBAAmB;AAGnB,aAAwB;AACxB,aAAwB;AAExB,YAAuB;AACvB,0BAA4B;AAa5B,MAAM,0BAA0B,aAAE,OAAO,EAAE,QAAQ,aAAE,OAAO,GAAG,aAAa,aAAE,OAAO,GAAG,OAAO,aAAE,OAAO,EAAE,CAAC;AAG3G,MAAM,oBAAoB,MAAM,KAAK,UAAgC;AAAA,EAC5D,YAAY,MAA4C;AAC7D,UAAM,kBAAkB,MAAM,KAAK,aAAa,MAAM,KAAK,IAAI,GAAG,KAAK,YAAY;AACnF,UAAM;AAAA,MACJ,YAAY,OAAO;AAAA,MACnB,iBAAiB;AAAA,MACjB,cAAc,MAAM,KAAK,aAAa,iBAAiB,OAAO,eAAe;AAAA,MAC7E,GAAG,cAAAA,QAAE,UAAU,OAAO,aAAa,CAAC,MAAM,MAAM,KAAK,aAAa,iBAAiB,CAAC,CAAC;AAAA,MACrF,GAAG,cAAAA,QAAE,UAAU,OAAO,gBAAgB,CAAC,MAAM,MAAM,KAAK,aAAa,OAAO,YAAY,CAAC,CAAC;AAAA,IAC5F,CAAC;AAAA,EACH;AACF;AAEO,MAAe,sBAAyD,gCAAe;AAAA,EAClF;AAAA,EACA;AAAA,EACF;AAAA,EAED,YACL,KACA,WACG,MACH;AACA,UAAM,GAAG,IAAI;AACb,SAAK,MAAM;AACX,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,IAAc,cAAc;AAC1B,WAAO,IAAI,YAAY,KAAK,IAAI;AAAA,EAClC;AAAA,EAEA,IAAc,cAAc;AAC1B,WAAO,IAAI,MAAM,MAAM,gBAA6B,KAAK,YAAY,IAAI,eAAe;AAAA,EAC1F;AAAA,EAEA,MAAyB,YAAY;AACnC,UAAM,UAAU,MAAM,KAAK,
|
|
4
|
+
"sourcesContent": ["import { z } from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport latestVersion from 'latest-version'\nimport _ from 'lodash'\nimport semver from 'semver'\nimport type { ApiClientFactory } from '../api/client'\nimport * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { BaseCommand } from './base-command'\n\nexport type GlobalCommandDefinition = CommandDefinition<typeof config.schemas.global>\nexport type GlobalCache = { apiUrl: string; token: string; workspaceId: string; activeProfile: string }\n\nexport type ConfigurableGlobalPaths = {\n botpressHomeDir: string\n cliRootDir: utils.path.AbsolutePath\n profilesPath: string\n}\nexport type ConstantGlobalPaths = typeof consts.fromHomeDir & typeof consts.fromCliRootDir\nexport type AllGlobalPaths = ConfigurableGlobalPaths & ConstantGlobalPaths\n\nconst profileCredentialSchema = z.object({ apiUrl: z.string(), workspaceId: z.string(), token: z.string() })\nexport type ProfileCredentials = z.infer<typeof profileCredentialSchema>\n\nclass GlobalPaths extends utils.path.PathStore<keyof AllGlobalPaths> {\n public constructor(argv: CommandArgv<GlobalCommandDefinition>) {\n const absBotpressHome = utils.path.absoluteFrom(utils.path.cwd(), argv.botpressHome)\n super({\n cliRootDir: consts.cliRootDir,\n botpressHomeDir: absBotpressHome,\n profilesPath: utils.path.absoluteFrom(absBotpressHome, consts.profileFileName),\n ..._.mapValues(consts.fromHomeDir, (p) => utils.path.absoluteFrom(absBotpressHome, p)),\n ..._.mapValues(consts.fromCliRootDir, (p) => utils.path.absoluteFrom(consts.cliRootDir, p)),\n })\n }\n}\n\nexport abstract class GlobalCommand<C extends GlobalCommandDefinition> extends BaseCommand<C> {\n protected api: ApiClientFactory\n protected prompt: utils.prompt.CLIPrompt\n private _pkgJson: utils.pkgJson.PackageJson | undefined\n\n public constructor(\n api: ApiClientFactory,\n prompt: utils.prompt.CLIPrompt,\n ...args: ConstructorParameters<typeof BaseCommand<C>>\n ) {\n super(...args)\n this.api = api\n this.prompt = prompt\n }\n\n protected get globalPaths() {\n return new GlobalPaths(this.argv)\n }\n\n protected get globalCache() {\n return new utils.cache.FSKeyValueCache<GlobalCache>(this.globalPaths.abs.globalCacheFile)\n }\n\n protected override async bootstrap() {\n const pkgJson = await this.readCLIPkgJson()\n const versionText = chalk.bold(`v${pkgJson.version}`)\n this.logger.log(`Botpress CLI ${versionText}`, { prefix: '\uD83E\uDD16' })\n\n await this._notifyUpdateCli()\n\n const paths = this.globalPaths\n if (paths.abs.botpressHomeDir !== consts.defaultBotpressHome) {\n this.logger.log(`Using custom botpress home: ${paths.abs.botpressHomeDir}`, { prefix: '\uD83C\uDFE0' })\n }\n }\n\n protected override teardown = async () => {\n this.logger.cleanup()\n }\n\n protected async getAuthenticatedClient(credentials: Partial<YargsConfig<typeof config.schemas.credentials>>) {\n try {\n const cache = this.globalCache\n\n let token: string | undefined\n let workspaceId: string | undefined\n let apiUrl: string | undefined\n\n if (this.argv.profile) {\n if (credentials.token || credentials.workspaceId || credentials.apiUrl) {\n this.logger.warn(\n 'You are currently using credential command line arguments or environment variables as well as a profile. Your profile has overwritten the variables'\n )\n }\n ;({ token, workspaceId, apiUrl } = await this.readProfileFromFS(this.argv.profile))\n this.logger.log(`Using profile \"${this.argv.profile}\"`, { prefix: '\uD83D\uDC64' })\n } else {\n token = credentials.token ?? (await cache.get('token'))\n workspaceId = credentials.workspaceId ?? (await cache.get('workspaceId'))\n apiUrl = credentials.apiUrl ?? (await cache.get('apiUrl'))\n }\n\n if (!(token && workspaceId && apiUrl)) {\n return null\n }\n\n if (apiUrl !== consts.defaultBotpressApiUrl) {\n this.logger.log(`Using custom url ${apiUrl}`, { prefix: '\uD83D\uDD17' })\n }\n\n return this.api.newClient({ apiUrl, token, workspaceId }, this.logger)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'failed to create authenticated client')\n }\n }\n\n protected async readProfileFromFS(profile: string): Promise<ProfileCredentials> {\n const parsedProfiles = await this.readProfilesFromFS()\n\n const profileData = parsedProfiles[profile]\n if (!profileData) {\n throw new errors.BotpressCLIError(\n `Profile \"${profile}\" not found in \"${this.globalPaths.abs.profilesPath}\". Found profiles '${Object.keys(parsedProfiles).join(\"', '\")}'.`\n )\n }\n\n return profileData\n }\n\n protected async readProfilesFromFS(): Promise<Record<string, ProfileCredentials>> {\n if (!fs.existsSync(this.globalPaths.abs.profilesPath)) {\n throw new errors.BotpressCLIError(`Profile file not found at \"${this.globalPaths.abs.profilesPath}\"`)\n }\n const fileContent = await fs.promises.readFile(this.globalPaths.abs.profilesPath, 'utf-8')\n const jsonParseResult = utils.json.safeParseJson(fileContent)\n if (!jsonParseResult.success) {\n throw new errors.BotpressCLIError(`Error parsing profiles file: ${jsonParseResult.error.message}`)\n }\n\n const zodParseResult = z.record(profileCredentialSchema).safeParse(jsonParseResult.data)\n if (!zodParseResult.success) {\n throw errors.BotpressCLIError.wrap(zodParseResult.error, 'Error parsing profiles: ')\n }\n\n return zodParseResult.data\n }\n\n protected async writeProfileToFS(profileName: string, profile: ProfileCredentials): Promise<void> {\n let profiles: Record<string, ProfileCredentials>\n if (fs.existsSync(this.globalPaths.abs.profilesPath)) {\n profiles = await this.readProfilesFromFS()\n } else {\n profiles = {}\n }\n profiles[profileName] = profile\n\n await fs.promises.writeFile(\n this.globalPaths.abs.profilesPath,\n JSON.stringify({ [consts.defaultProfileName]: profiles.defaultProfileName, ...profiles }, null, 2),\n 'utf-8'\n )\n }\n\n protected async ensureLoginAndCreateClient(credentials: YargsConfig<typeof config.schemas.credentials>) {\n const client = await this.getAuthenticatedClient(credentials)\n\n if (client === null) {\n throw new errors.NotLoggedInError()\n }\n\n return client\n }\n\n private readonly _notifyUpdateCli = async (): Promise<void> => {\n try {\n this.logger.debug('Checking if cli is up to date')\n\n const pkgJson = await this.readCLIPkgJson()\n if (!pkgJson.version) {\n throw new errors.BotpressCLIError('Could not find version in package.json')\n }\n\n const latest = await latestVersion(pkgJson.name)\n const isOutdated = semver.lt(pkgJson.version, latest)\n if (isOutdated) {\n this.logger.box(\n [\n `${chalk.bold('Update available')} ${chalk.dim(pkgJson.version)} \u2192 ${chalk.green(latest)}`,\n '',\n 'To update, run:',\n ` for npm ${chalk.cyan(`npm i -g ${pkgJson.name}`)}`,\n ` for yarn ${chalk.cyan(`yarn global add ${pkgJson.name}`)}`,\n ` for pnpm ${chalk.cyan(`pnpm i -g ${pkgJson.name}`)}`,\n ].join('\\n')\n )\n }\n } catch (thrown) {\n const err = errors.BotpressCLIError.map(thrown)\n this.logger.debug(`Failed to check if cli is up to date: ${err.message}`)\n }\n }\n\n protected async readCLIPkgJson(): Promise<utils.pkgJson.PackageJson> {\n if (this._pkgJson) {\n return this._pkgJson\n }\n const { cliRootDir } = this.globalPaths.abs\n const pkgJson = await utils.pkgJson.readPackageJson(cliRootDir).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Failed to read CLI package.json file at \"${cliRootDir}\"`)\n })\n\n if (!pkgJson) {\n throw new errors.BotpressCLIError(`Could not find package.json at \"${cliRootDir}\"`)\n }\n\n this._pkgJson = pkgJson\n return pkgJson\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAkB;AAElB,mBAAkB;AAClB,SAAoB;AACpB,4BAA0B;AAC1B,oBAAc;AACd,oBAAmB;AAGnB,aAAwB;AACxB,aAAwB;AAExB,YAAuB;AACvB,0BAA4B;AAa5B,MAAM,0BAA0B,aAAE,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AAiB,KAAK,QAAQ,4CAA4C,UAAU,GAAG;AAAA,IACtG,CAAC;AAED,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,OAAO,iBAAiB,mCAAmC,UAAU,GAAG;AAAA,IACpF;AAEA,SAAK,WAAW;AAChB,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["_", "chalk", "latestVersion", "semver"]
|
|
7
7
|
}
|
|
@@ -185,12 +185,14 @@ class InitCommand extends import_global_command.GlobalCommand {
|
|
|
185
185
|
}
|
|
186
186
|
await fs.promises.rm(destination, { recursive: true, force: true });
|
|
187
187
|
await fs.promises.cp(srcDir, destination, { recursive: true });
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
const json = await utils.pkgJson.readPackageJson(destination).catch((thrown) => {
|
|
189
|
+
throw errors.BotpressCLIError.wrap(thrown, "Failed to read package.json file");
|
|
190
|
+
});
|
|
191
191
|
const pkgJsonName = utils.casing.to.snakeCase(name);
|
|
192
192
|
const updatedJson = { name: pkgJsonName, ...json, ...pkgJson };
|
|
193
|
-
await
|
|
193
|
+
await utils.pkgJson.writePackageJson(destination, updatedJson).catch((thrown) => {
|
|
194
|
+
throw errors.BotpressCLIError.wrap(thrown, "Failed to write package.json file");
|
|
195
|
+
});
|
|
194
196
|
};
|
|
195
197
|
_checkIfDestinationCanBeUsed = async (destination) => {
|
|
196
198
|
if (fs.existsSync(destination)) {
|