@botonic/nx-plugin 2.31.0 → 2.32.0-alpha.0
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/migrations.json +1 -8
- package/package.json +7 -4
- package/src/executors/build-node-app/executor-impl.d.ts +5 -0
- package/src/executors/build-node-app/executor-impl.js +65 -0
- package/src/executors/build-node-app/executor.d.ts +4 -2
- package/src/executors/build-node-app/executor.js +3 -41
- package/src/executors/delete-bot/executor-impl.d.ts +5 -0
- package/src/executors/delete-bot/executor-impl.js +110 -0
- package/src/executors/delete-bot/executor.d.ts +4 -2
- package/src/executors/delete-bot/executor.js +3 -86
- package/src/executors/deploy-netlify-snapshot/executor-impl.d.ts +8 -0
- package/src/executors/deploy-netlify-snapshot/executor-impl.js +79 -0
- package/src/executors/deploy-netlify-snapshot/executor.d.ts +4 -5
- package/src/executors/deploy-netlify-snapshot/executor.js +3 -55
- package/src/executors/deploy-to-hubtype/executor-impl.d.ts +5 -0
- package/src/executors/deploy-to-hubtype/executor-impl.js +172 -0
- package/src/executors/deploy-to-hubtype/executor.d.ts +4 -2
- package/src/executors/deploy-to-hubtype/executor.js +3 -148
- package/src/executors/e2e-webchat/executor-impl.d.ts +5 -0
- package/src/executors/e2e-webchat/executor-impl.js +134 -0
- package/src/executors/e2e-webchat/executor.d.ts +4 -2
- package/src/executors/e2e-webchat/executor.js +4 -111
- package/src/executors/integrate-provider/executor-impl.d.ts +5 -0
- package/src/executors/integrate-provider/executor-impl.js +153 -0
- package/src/executors/integrate-provider/executor.d.ts +4 -2
- package/src/executors/integrate-provider/executor.js +3 -129
- package/src/executors/login-to-hubtype/executor-impl.d.ts +5 -0
- package/src/executors/login-to-hubtype/executor-impl.js +77 -0
- package/src/executors/login-to-hubtype/executor.d.ts +4 -2
- package/src/executors/login-to-hubtype/executor.js +3 -53
- package/src/executors/logout-from-hubtype/executor-impl.d.ts +3 -0
- package/src/executors/logout-from-hubtype/executor-impl.js +54 -0
- package/src/executors/logout-from-hubtype/executor.d.ts +5 -1
- package/src/executors/logout-from-hubtype/executor.js +3 -30
- package/src/executors/run-lambda/executor-impl.d.ts +5 -0
- package/src/executors/run-lambda/executor-impl.js +65 -0
- package/src/executors/run-lambda/executor.d.ts +4 -2
- package/src/executors/run-lambda/executor.js +3 -41
- package/src/executors/serve-bot/executor-impl.d.ts +5 -0
- package/src/executors/serve-bot/executor-impl.js +530 -0
- package/src/executors/serve-bot/executor.d.ts +4 -2
- package/src/executors/serve-bot/executor.js +3 -506
- package/src/generators/action/generator-impl.d.ts +4 -0
- package/src/generators/action/generator-impl.js +112 -0
- package/src/generators/action/generator.d.ts +2 -3
- package/src/generators/action/generator.js +2 -87
- package/src/generators/bot-app/files/vite/webchat.config.ts.template +10 -2
- package/src/generators/bot-app/generator-impl.d.ts +4 -0
- package/src/generators/bot-app/generator-impl.js +328 -0
- package/src/generators/bot-app/generator.d.ts +2 -4
- package/src/generators/bot-app/generator.js +2 -295
- package/src/generators/custom-message/generator-impl.d.ts +4 -0
- package/src/generators/custom-message/generator-impl.js +235 -0
- package/src/generators/custom-message/generator.d.ts +2 -3
- package/src/generators/custom-message/generator.js +2 -210
- package/src/generators/preset/generator-impl.d.ts +4 -0
- package/src/generators/preset/generator-impl.js +127 -0
- package/src/generators/preset/generator.d.ts +2 -4
- package/src/generators/preset/generator.js +2 -95
- package/src/generators/remove-custom-message/generator-impl.d.ts +4 -0
- package/src/generators/remove-custom-message/generator-impl.js +259 -0
- package/src/generators/remove-custom-message/generator.d.ts +2 -3
- package/src/generators/remove-custom-message/generator.js +2 -234
- package/src/generators/webview/generator-impl.d.ts +4 -0
- package/src/generators/webview/generator-impl.js +179 -0
- package/src/generators/webview/generator.d.ts +2 -3
- package/src/generators/webview/generator.js +2 -154
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -1
- package/src/lib/delegate/delegate-executor.d.ts +6 -0
- package/src/lib/delegate/delegate-executor.js +119 -0
- package/src/lib/delegate/delegate-generator.d.ts +2 -0
- package/src/lib/delegate/delegate-generator.js +128 -0
- package/src/lib/serve-mode/index.d.ts +25 -0
- package/src/lib/serve-mode/index.js +183 -0
- package/src/generators/bot-app/files/vite/plugins/dev-log-viewer-html.plugin.ts.template +0 -65
- package/src/migrations/install-claude-update-skills/install-claude-update-skills.migration.d.ts +0 -2
- package/src/migrations/install-claude-update-skills/install-claude-update-skills.migration.js +0 -290
|
@@ -28,300 +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 generator_exports = {};
|
|
30
30
|
__export(generator_exports, {
|
|
31
|
-
default: () =>
|
|
31
|
+
default: () => import_generator_impl.default
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(generator_exports);
|
|
34
|
-
var
|
|
35
|
-
var import_child_process = require("child_process");
|
|
36
|
-
var fs = __toESM(require("fs"));
|
|
37
|
-
var path = __toESM(require("path"));
|
|
38
|
-
const MODULE_DIR = __dirname;
|
|
39
|
-
function getLilaraVersion(options) {
|
|
40
|
-
const version = options.lilaraVersion;
|
|
41
|
-
if (version && version !== "latest") {
|
|
42
|
-
return version.replace(/^[\^~]/, "");
|
|
43
|
-
}
|
|
44
|
-
const jsonPath = path.join(MODULE_DIR, "lilara-version.json");
|
|
45
|
-
try {
|
|
46
|
-
if (fs.existsSync(jsonPath)) {
|
|
47
|
-
const data = JSON.parse(fs.readFileSync(jsonPath, "utf-8"));
|
|
48
|
-
if (data.version && typeof data.version === "string") {
|
|
49
|
-
return data.version.replace(/^[\^~]/, "");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
} catch {
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
const tag = (0, import_child_process.execSync)('git describe --tags --match "lilara-v*" --abbrev=0', {
|
|
56
|
-
encoding: "utf-8",
|
|
57
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
58
|
-
}).trim();
|
|
59
|
-
const v = tag.replace(/^lilara-v/, "");
|
|
60
|
-
if (v) return v;
|
|
61
|
-
} catch {
|
|
62
|
-
}
|
|
63
|
-
return "latest";
|
|
64
|
-
}
|
|
65
|
-
function getBotonicVersion(options) {
|
|
66
|
-
const version = options.botonicVersion;
|
|
67
|
-
if (version && version !== "{{WORKSPACE_VERSION}}" && version !== "latest") {
|
|
68
|
-
return version.replace(/^[\^~]/, "");
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
const packageJsonPath = path.resolve(
|
|
72
|
-
MODULE_DIR,
|
|
73
|
-
"..",
|
|
74
|
-
"..",
|
|
75
|
-
"..",
|
|
76
|
-
"package.json"
|
|
77
|
-
);
|
|
78
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
79
|
-
return packageJson.version || "latest";
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.warn("Could not read plugin version, using latest:", error);
|
|
82
|
-
return "latest";
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function normalizeOptions(tree, options) {
|
|
86
|
-
let appName = options.name;
|
|
87
|
-
let directory = options.directory;
|
|
88
|
-
if (options.name.includes("/")) {
|
|
89
|
-
const parts = options.name.split("/");
|
|
90
|
-
appName = parts.pop();
|
|
91
|
-
if (!directory) {
|
|
92
|
-
directory = parts.join("/");
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const name = (0, import_devkit.names)(appName).fileName;
|
|
96
|
-
if (!name) {
|
|
97
|
-
throw new Error(`Failed to normalize app name: ${appName}`);
|
|
98
|
-
}
|
|
99
|
-
let projectDirectory;
|
|
100
|
-
if (directory) {
|
|
101
|
-
const directoryName = (0, import_devkit.names)(directory).fileName;
|
|
102
|
-
if (!directoryName) {
|
|
103
|
-
throw new Error(`Failed to normalize directory name: ${directory}`);
|
|
104
|
-
}
|
|
105
|
-
projectDirectory = `${directoryName}/${name}`;
|
|
106
|
-
} else {
|
|
107
|
-
projectDirectory = name;
|
|
108
|
-
}
|
|
109
|
-
if (!projectDirectory) {
|
|
110
|
-
throw new Error(
|
|
111
|
-
`Failed to determine project directory for app name: ${appName}`
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
const projectName = projectDirectory.replace(new RegExp("/", "g"), "-");
|
|
115
|
-
const projectRoot = `${(0, import_devkit.getWorkspaceLayout)(tree).appsDir}/${projectDirectory}`;
|
|
116
|
-
return {
|
|
117
|
-
...options,
|
|
118
|
-
name: appName,
|
|
119
|
-
// Use the parsed app name
|
|
120
|
-
directory,
|
|
121
|
-
// Use the parsed directory
|
|
122
|
-
projectName,
|
|
123
|
-
projectRoot,
|
|
124
|
-
projectDirectory
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function createProjectConfiguration(tree, options) {
|
|
128
|
-
const projectConfig = {
|
|
129
|
-
name: options.projectName,
|
|
130
|
-
root: options.projectRoot,
|
|
131
|
-
sourceRoot: `${options.projectRoot}/src`,
|
|
132
|
-
projectType: "application",
|
|
133
|
-
tags: ["type:app", "botonic:bot-app"]
|
|
134
|
-
// Note: targets are now inferred by the @botonic/nx-plugin based on the 'botonic:bot-app' tag
|
|
135
|
-
// and the presence of configuration files (vite.config.ts, bot-config.ts, etc.)
|
|
136
|
-
};
|
|
137
|
-
(0, import_devkit.addProjectConfiguration)(tree, options.projectName, projectConfig);
|
|
138
|
-
}
|
|
139
|
-
function createPackageJson(tree, options, botonicVersion, lilaraVersion) {
|
|
140
|
-
const packageJson = {
|
|
141
|
-
name: options.projectName,
|
|
142
|
-
version: "1.0.0",
|
|
143
|
-
type: "module",
|
|
144
|
-
private: true,
|
|
145
|
-
description: `Botonic bot application: ${options.projectName}`,
|
|
146
|
-
main: "dist/src/index.js",
|
|
147
|
-
scripts: {},
|
|
148
|
-
dependencies: {
|
|
149
|
-
"@botonic/core": botonicVersion,
|
|
150
|
-
"@botonic/plugin-ai-agents": botonicVersion,
|
|
151
|
-
"@botonic/plugin-flow-builder": botonicVersion,
|
|
152
|
-
"@botonic/plugin-hubtype-analytics": botonicVersion,
|
|
153
|
-
"@botonic/shared": botonicVersion,
|
|
154
|
-
"@botonic/webchat-core": botonicVersion,
|
|
155
|
-
"@botonic/webchat-react": botonicVersion,
|
|
156
|
-
"@botonic/webviews": botonicVersion,
|
|
157
|
-
"@lilara/foundations": lilaraVersion,
|
|
158
|
-
"@lilara/ui-web": lilaraVersion,
|
|
159
|
-
"@lilara/ui-web-react": lilaraVersion,
|
|
160
|
-
react: "18.3.1",
|
|
161
|
-
"react-dom": "18.3.1",
|
|
162
|
-
zod: "^4.4.3"
|
|
163
|
-
},
|
|
164
|
-
devDependencies: {
|
|
165
|
-
"@nx/vite": "21.6.11",
|
|
166
|
-
"@types/node": "22.13.0",
|
|
167
|
-
"@types/react": "18.3.1",
|
|
168
|
-
"@types/react-dom": "18.3.0",
|
|
169
|
-
"@vitejs/plugin-react": "^4.2.0",
|
|
170
|
-
"@vitejs/plugin-react-swc": "^3.5.0",
|
|
171
|
-
typescript: "5.7.3",
|
|
172
|
-
vite: "7.1.9",
|
|
173
|
-
vitest: "4.1.1"
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
(0, import_devkit.writeJson)(tree, `${options.projectRoot}/package.json`, packageJson);
|
|
177
|
-
}
|
|
178
|
-
function createTsConfigs(tree, options) {
|
|
179
|
-
const tsconfig = {
|
|
180
|
-
compilerOptions: {
|
|
181
|
-
jsx: "react-jsx",
|
|
182
|
-
allowJs: false,
|
|
183
|
-
esModuleInterop: true,
|
|
184
|
-
allowSyntheticDefaultImports: true,
|
|
185
|
-
resolveJsonModule: true,
|
|
186
|
-
strict: true,
|
|
187
|
-
types: ["vite/client", "vitest"]
|
|
188
|
-
},
|
|
189
|
-
files: [],
|
|
190
|
-
include: ["src/**/*.ts", "src/**/*.tsx"],
|
|
191
|
-
references: [
|
|
192
|
-
{ path: "./tsconfig.app.json" },
|
|
193
|
-
{ path: "./tsconfig.spec.json" }
|
|
194
|
-
],
|
|
195
|
-
extends: "../../tsconfig.base.json"
|
|
196
|
-
};
|
|
197
|
-
const tsconfigApp = {
|
|
198
|
-
extends: "./tsconfig.json",
|
|
199
|
-
compilerOptions: {
|
|
200
|
-
outDir: "./dist/out-tsc",
|
|
201
|
-
types: ["node", "vite/client"],
|
|
202
|
-
composite: true,
|
|
203
|
-
noEmit: false,
|
|
204
|
-
declaration: true
|
|
205
|
-
},
|
|
206
|
-
files: [
|
|
207
|
-
"../../node_modules/@nx/react/typings/cssmodule.d.ts",
|
|
208
|
-
"../../node_modules/@nx/react/typings/image.d.ts"
|
|
209
|
-
],
|
|
210
|
-
exclude: [
|
|
211
|
-
"jest.config.ts",
|
|
212
|
-
"src/**/*.spec.ts",
|
|
213
|
-
"src/**/*.test.ts",
|
|
214
|
-
"src/**/*.spec.tsx",
|
|
215
|
-
"src/**/*.test.tsx",
|
|
216
|
-
"src/**/*.spec.js",
|
|
217
|
-
"src/**/*.test.js",
|
|
218
|
-
"src/**/*.spec.jsx",
|
|
219
|
-
"src/**/*.test.jsx"
|
|
220
|
-
],
|
|
221
|
-
include: ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
222
|
-
};
|
|
223
|
-
const tsconfigSpec = {
|
|
224
|
-
extends: "./tsconfig.json",
|
|
225
|
-
compilerOptions: {
|
|
226
|
-
outDir: "./dist/out-tsc",
|
|
227
|
-
module: "commonjs",
|
|
228
|
-
types: ["vitest/globals", "vitest/importMeta", "vite/client", "node"],
|
|
229
|
-
composite: true,
|
|
230
|
-
noEmit: false,
|
|
231
|
-
declaration: true
|
|
232
|
-
},
|
|
233
|
-
include: [
|
|
234
|
-
"vite.config.ts",
|
|
235
|
-
"vitest.config.ts",
|
|
236
|
-
"src/**/*.test.ts",
|
|
237
|
-
"src/**/*.spec.ts",
|
|
238
|
-
"src/**/*.test.tsx",
|
|
239
|
-
"src/**/*.spec.tsx",
|
|
240
|
-
"src/**/*.test.js",
|
|
241
|
-
"src/**/*.spec.js",
|
|
242
|
-
"src/**/*.test.jsx",
|
|
243
|
-
"src/**/*.spec.jsx",
|
|
244
|
-
"src/**/*.d.ts"
|
|
245
|
-
]
|
|
246
|
-
};
|
|
247
|
-
(0, import_devkit.writeJson)(tree, `${options.projectRoot}/tsconfig.json`, tsconfig);
|
|
248
|
-
(0, import_devkit.writeJson)(tree, `${options.projectRoot}/tsconfig.app.json`, tsconfigApp);
|
|
249
|
-
(0, import_devkit.writeJson)(tree, `${options.projectRoot}/tsconfig.spec.json`, tsconfigSpec);
|
|
250
|
-
}
|
|
251
|
-
function addBotonicDependencies(tree, botonicVersion) {
|
|
252
|
-
return (0, import_devkit.addDependenciesToPackageJson)(
|
|
253
|
-
tree,
|
|
254
|
-
// dependencies
|
|
255
|
-
{
|
|
256
|
-
react: "18.3.1",
|
|
257
|
-
"react-dom": "18.3.1"
|
|
258
|
-
},
|
|
259
|
-
// devDependencies
|
|
260
|
-
{
|
|
261
|
-
"@nx/vite": "21.6.11",
|
|
262
|
-
"@types/node": "22.13.0",
|
|
263
|
-
"@types/react": "18.3.1",
|
|
264
|
-
"@types/react-dom": "18.3.0",
|
|
265
|
-
"@vitejs/plugin-react": "4.2.0",
|
|
266
|
-
"@vitejs/plugin-react-swc": "3.5.0",
|
|
267
|
-
typescript: "5.7.3",
|
|
268
|
-
vite: "7.1.9",
|
|
269
|
-
vitest: "4.1.1"
|
|
270
|
-
}
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
function addBotonicFiles(tree, options, botonicVersion) {
|
|
274
|
-
const templateOptions = {
|
|
275
|
-
...options,
|
|
276
|
-
...(0, import_devkit.names)(options.name),
|
|
277
|
-
botonicVersion
|
|
278
|
-
};
|
|
279
|
-
(0, import_devkit.generateFiles)(
|
|
280
|
-
tree,
|
|
281
|
-
(0, import_devkit.joinPathFragments)(MODULE_DIR, "files"),
|
|
282
|
-
options.projectRoot,
|
|
283
|
-
templateOptions
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
async function generator_default(tree, options) {
|
|
287
|
-
const botonicVersion = getBotonicVersion(options);
|
|
288
|
-
const lilaraVersion = getLilaraVersion(options);
|
|
289
|
-
const tasks = [];
|
|
290
|
-
console.log(`\u{1F916} Using Botonic version: ${botonicVersion}`);
|
|
291
|
-
console.log(`\u{1F3A8} Using Lilara version: ${lilaraVersion}`);
|
|
292
|
-
console.log(`\u{1F50D} Creating project using programmatic configuration...`);
|
|
293
|
-
const normalizedOptions = normalizeOptions(tree, options);
|
|
294
|
-
console.log(`\u{1F50D} Normalized options:`, {
|
|
295
|
-
projectName: normalizedOptions.projectName,
|
|
296
|
-
projectRoot: normalizedOptions.projectRoot,
|
|
297
|
-
projectDirectory: normalizedOptions.projectDirectory
|
|
298
|
-
});
|
|
299
|
-
createProjectConfiguration(tree, normalizedOptions);
|
|
300
|
-
createPackageJson(tree, normalizedOptions, botonicVersion, lilaraVersion);
|
|
301
|
-
createTsConfigs(tree, normalizedOptions);
|
|
302
|
-
const depsTask = addBotonicDependencies(tree, botonicVersion);
|
|
303
|
-
tasks.push(depsTask);
|
|
304
|
-
tasks.push(() => (0, import_devkit.installPackagesTask)(tree));
|
|
305
|
-
tasks.push(
|
|
306
|
-
() => (0, import_devkit.installPackagesTask)(
|
|
307
|
-
tree,
|
|
308
|
-
true,
|
|
309
|
-
`${normalizedOptions.projectRoot}/src/server/lambda/`
|
|
310
|
-
)
|
|
311
|
-
);
|
|
312
|
-
addBotonicFiles(tree, normalizedOptions, botonicVersion);
|
|
313
|
-
await (0, import_devkit.formatFiles)(tree);
|
|
314
|
-
tasks.push(() => {
|
|
315
|
-
console.log(
|
|
316
|
-
`
|
|
317
|
-
\u{1F389} Successfully created Botonic bot app: ${normalizedOptions.projectName}`
|
|
318
|
-
);
|
|
319
|
-
console.log(`\u{1F4C1} Project location: ${normalizedOptions.projectRoot}`);
|
|
320
|
-
console.log(`
|
|
321
|
-
\u{1F4CB} Next step:`);
|
|
322
|
-
console.log(` npx nx run ${normalizedOptions.projectName}:serve`);
|
|
323
|
-
console.log(`
|
|
324
|
-
\u{1F680} Happy bot building!`);
|
|
325
|
-
});
|
|
326
|
-
return (0, import_devkit.runTasksInSerial)(...tasks);
|
|
327
|
-
}
|
|
34
|
+
var import_generator_impl = __toESM(require("./generator-impl"));
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var generator_impl_exports = {};
|
|
20
|
+
__export(generator_impl_exports, {
|
|
21
|
+
default: () => generator_impl_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(generator_impl_exports);
|
|
24
|
+
var import_devkit = require("@nx/devkit");
|
|
25
|
+
var import_bot_app_utils = require("../shared/bot-app-utils");
|
|
26
|
+
const MODULE_DIR = __dirname;
|
|
27
|
+
function normalizeOptions(tree, options) {
|
|
28
|
+
const { projectRoot, sourceRoot } = (0, import_bot_app_utils.validateBotAppProject)(
|
|
29
|
+
tree,
|
|
30
|
+
options.project
|
|
31
|
+
);
|
|
32
|
+
const paths = (0, import_bot_app_utils.resolveStandardPaths)(sourceRoot);
|
|
33
|
+
const name = (0, import_devkit.names)(options.name);
|
|
34
|
+
const fileName = name.fileName;
|
|
35
|
+
const className = name.className;
|
|
36
|
+
const propertyName = name.propertyName;
|
|
37
|
+
const constantName = name.constantName.toUpperCase();
|
|
38
|
+
const customMessagesPath = options.directory ? `${sourceRoot}/client/custom-messages/${options.directory}` : `${sourceRoot}/client/custom-messages`;
|
|
39
|
+
return {
|
|
40
|
+
...options,
|
|
41
|
+
projectName: options.project,
|
|
42
|
+
projectRoot,
|
|
43
|
+
fileName,
|
|
44
|
+
className,
|
|
45
|
+
propertyName,
|
|
46
|
+
constantName,
|
|
47
|
+
customMessagesPath,
|
|
48
|
+
constantsPath: paths.constantsPath,
|
|
49
|
+
actionsPath: paths.actionsPath,
|
|
50
|
+
routesPath: paths.routesPath
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function addFilesToProject(tree, options) {
|
|
54
|
+
const name = (0, import_devkit.names)(options.name);
|
|
55
|
+
const templateOptions = {
|
|
56
|
+
...options,
|
|
57
|
+
...name,
|
|
58
|
+
name: name.fileName
|
|
59
|
+
// __name__ in filenames must be kebab-case
|
|
60
|
+
};
|
|
61
|
+
(0, import_devkit.generateFiles)(
|
|
62
|
+
tree,
|
|
63
|
+
(0, import_devkit.joinPathFragments)(MODULE_DIR, "files"),
|
|
64
|
+
options.customMessagesPath,
|
|
65
|
+
templateOptions
|
|
66
|
+
);
|
|
67
|
+
if (options.skipTests) {
|
|
68
|
+
const testFilePath = `${options.customMessagesPath}/${options.fileName}.spec.tsx`;
|
|
69
|
+
if (tree.exists(testFilePath)) {
|
|
70
|
+
tree.delete(testFilePath);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (options.skipAction) {
|
|
74
|
+
const actionPath = `${options.customMessagesPath}/${options.fileName}-output.ts`;
|
|
75
|
+
if (tree.exists(actionPath)) {
|
|
76
|
+
tree.delete(actionPath);
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
const sourceActionPath = `${options.customMessagesPath}/${options.fileName}-output.ts`;
|
|
80
|
+
const targetActionPath = `${options.actionsPath}/${options.fileName}.ts`;
|
|
81
|
+
if (tree.exists(sourceActionPath)) {
|
|
82
|
+
const content = tree.read(sourceActionPath, "utf-8");
|
|
83
|
+
tree.write(targetActionPath, content);
|
|
84
|
+
tree.delete(sourceActionPath);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function updateCustomMessagesIndex(tree, options) {
|
|
89
|
+
const indexPath = `${options.customMessagesPath}/index.ts`;
|
|
90
|
+
if (!tree.exists(indexPath)) {
|
|
91
|
+
tree.write(
|
|
92
|
+
indexPath,
|
|
93
|
+
`import { CUSTOM_MESSAGE_TYPES } from '../../shared/constants'
|
|
94
|
+
|
|
95
|
+
export const customMessages = {
|
|
96
|
+
[CUSTOM_MESSAGE_TYPES.${options.constantName}]: ${options.className},
|
|
97
|
+
}
|
|
98
|
+
`
|
|
99
|
+
);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const content = tree.read(indexPath, "utf-8");
|
|
103
|
+
const lines = content.split("\n");
|
|
104
|
+
const importStatement = `import { ${options.className} } from './${options.directory ? options.directory + "/" : ""}${options.fileName}'`;
|
|
105
|
+
let importInsertIndex = 0;
|
|
106
|
+
for (let i = 0; i < lines.length; i++) {
|
|
107
|
+
if (lines[i].startsWith("import")) {
|
|
108
|
+
importInsertIndex = i + 1;
|
|
109
|
+
} else if (lines[i].trim() === "" && importInsertIndex > 0) {
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
lines.splice(importInsertIndex, 0, importStatement);
|
|
114
|
+
const exportLineIndex = lines.findIndex(
|
|
115
|
+
(line) => line.includes("export const customMessages")
|
|
116
|
+
);
|
|
117
|
+
if (exportLineIndex !== -1) {
|
|
118
|
+
let braceIndex = exportLineIndex;
|
|
119
|
+
while (braceIndex < lines.length && !lines[braceIndex].includes("{")) {
|
|
120
|
+
braceIndex++;
|
|
121
|
+
}
|
|
122
|
+
if (braceIndex < lines.length) {
|
|
123
|
+
const braceLine = lines[braceIndex];
|
|
124
|
+
if (braceLine.trim() === "{" || braceLine.includes("{}")) {
|
|
125
|
+
const newEntry = ` [CUSTOM_MESSAGE_TYPES.${options.constantName}]: ${options.className},`;
|
|
126
|
+
if (braceLine.includes("{}")) {
|
|
127
|
+
lines[braceIndex] = braceLine.replace("{}", `{
|
|
128
|
+
${newEntry}
|
|
129
|
+
}`);
|
|
130
|
+
} else {
|
|
131
|
+
lines.splice(braceIndex + 1, 0, newEntry);
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
let closingBraceIndex = braceIndex;
|
|
135
|
+
let braceCount = 0;
|
|
136
|
+
for (let i = braceIndex; i < lines.length; i++) {
|
|
137
|
+
for (const char of lines[i]) {
|
|
138
|
+
if (char === "{") braceCount++;
|
|
139
|
+
if (char === "}") braceCount--;
|
|
140
|
+
}
|
|
141
|
+
if (braceCount === 0) {
|
|
142
|
+
closingBraceIndex = i;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const newEntry = ` [CUSTOM_MESSAGE_TYPES.${options.constantName}]: ${options.className},`;
|
|
147
|
+
lines.splice(closingBraceIndex, 0, newEntry);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
tree.write(indexPath, lines.join("\n"));
|
|
152
|
+
}
|
|
153
|
+
function updateConstantsFile(tree, options) {
|
|
154
|
+
if (!tree.exists(options.constantsPath)) {
|
|
155
|
+
tree.write(
|
|
156
|
+
options.constantsPath,
|
|
157
|
+
`export const CUSTOM_MESSAGE_TYPES = {
|
|
158
|
+
${options.constantName}: '${options.fileName}',
|
|
159
|
+
} as const
|
|
160
|
+
|
|
161
|
+
export const WEBVIEWS = {
|
|
162
|
+
// Add your webviews here
|
|
163
|
+
} as const
|
|
164
|
+
|
|
165
|
+
export const PAYLOADS = {
|
|
166
|
+
// Add your payloads here
|
|
167
|
+
} as const
|
|
168
|
+
`
|
|
169
|
+
);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
(0, import_bot_app_utils.addConstEntry)(
|
|
173
|
+
tree,
|
|
174
|
+
options.constantsPath,
|
|
175
|
+
"CUSTOM_MESSAGE_TYPES",
|
|
176
|
+
options.constantName,
|
|
177
|
+
options.fileName
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
function updateActionsIndex(tree, options) {
|
|
181
|
+
if (options.skipAction) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
(0, import_bot_app_utils.addExportToIndex)(
|
|
185
|
+
tree,
|
|
186
|
+
`${options.actionsPath}/index.ts`,
|
|
187
|
+
`export * from './${options.fileName}'`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
function updateRoutes(tree, options) {
|
|
191
|
+
if (options.skipAction) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const actionImport = `${options.propertyName}Output`;
|
|
195
|
+
(0, import_bot_app_utils.addActionImportToRoutes)(tree, options.routesPath, actionImport);
|
|
196
|
+
(0, import_bot_app_utils.insertRouteBeforeFlowBuilder)(tree, options.routesPath, [
|
|
197
|
+
` {`,
|
|
198
|
+
` text: '${options.fileName}',`,
|
|
199
|
+
` action: async () => await ${actionImport}(botonicContext),`,
|
|
200
|
+
` },`
|
|
201
|
+
]);
|
|
202
|
+
}
|
|
203
|
+
async function generator_impl_default(tree, options) {
|
|
204
|
+
console.log(`Creating custom message: ${options.name}`);
|
|
205
|
+
const normalizedOptions = normalizeOptions(tree, options);
|
|
206
|
+
console.log(`Project: ${normalizedOptions.projectName}`);
|
|
207
|
+
console.log(`Location: ${normalizedOptions.customMessagesPath}`);
|
|
208
|
+
addFilesToProject(tree, normalizedOptions);
|
|
209
|
+
updateConstantsFile(tree, normalizedOptions);
|
|
210
|
+
updateCustomMessagesIndex(tree, normalizedOptions);
|
|
211
|
+
updateActionsIndex(tree, normalizedOptions);
|
|
212
|
+
updateRoutes(tree, normalizedOptions);
|
|
213
|
+
await (0, import_devkit.formatFiles)(tree);
|
|
214
|
+
console.log(
|
|
215
|
+
`
|
|
216
|
+
Successfully created custom message: ${normalizedOptions.className}`
|
|
217
|
+
);
|
|
218
|
+
console.log(`Next steps:`);
|
|
219
|
+
console.log(
|
|
220
|
+
` 1. Customize the component in: ${normalizedOptions.customMessagesPath}/${normalizedOptions.fileName}.tsx`
|
|
221
|
+
);
|
|
222
|
+
if (!options.skipAction) {
|
|
223
|
+
console.log(
|
|
224
|
+
` 2. Update the action in: ${normalizedOptions.actionsPath}/${normalizedOptions.fileName}.ts`
|
|
225
|
+
);
|
|
226
|
+
console.log(
|
|
227
|
+
` 3. Test by typing '${normalizedOptions.fileName}' in the webchat`
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
if (!options.skipTests) {
|
|
231
|
+
console.log(
|
|
232
|
+
` 4. Update the tests in: ${normalizedOptions.customMessagesPath}/${normalizedOptions.fileName}.spec.tsx`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Tree } from '@nx/devkit';
|
|
1
|
+
import type { Tree } from '@nx/devkit';
|
|
2
2
|
import type { CustomMessageGeneratorSchema } from './schema';
|
|
3
|
-
export default function (tree: Tree, options: CustomMessageGeneratorSchema): Promise<void>;
|
|
4
|
-
export { CustomMessageGeneratorSchema };
|
|
3
|
+
export default function (tree: Tree, options: CustomMessageGeneratorSchema): Promise<void | import("@nx/devkit").GeneratorCallback>;
|