@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.
Files changed (78) hide show
  1. package/migrations.json +1 -8
  2. package/package.json +7 -4
  3. package/src/executors/build-node-app/executor-impl.d.ts +5 -0
  4. package/src/executors/build-node-app/executor-impl.js +65 -0
  5. package/src/executors/build-node-app/executor.d.ts +4 -2
  6. package/src/executors/build-node-app/executor.js +3 -41
  7. package/src/executors/delete-bot/executor-impl.d.ts +5 -0
  8. package/src/executors/delete-bot/executor-impl.js +110 -0
  9. package/src/executors/delete-bot/executor.d.ts +4 -2
  10. package/src/executors/delete-bot/executor.js +3 -86
  11. package/src/executors/deploy-netlify-snapshot/executor-impl.d.ts +8 -0
  12. package/src/executors/deploy-netlify-snapshot/executor-impl.js +79 -0
  13. package/src/executors/deploy-netlify-snapshot/executor.d.ts +4 -5
  14. package/src/executors/deploy-netlify-snapshot/executor.js +3 -55
  15. package/src/executors/deploy-to-hubtype/executor-impl.d.ts +5 -0
  16. package/src/executors/deploy-to-hubtype/executor-impl.js +172 -0
  17. package/src/executors/deploy-to-hubtype/executor.d.ts +4 -2
  18. package/src/executors/deploy-to-hubtype/executor.js +3 -148
  19. package/src/executors/e2e-webchat/executor-impl.d.ts +5 -0
  20. package/src/executors/e2e-webchat/executor-impl.js +134 -0
  21. package/src/executors/e2e-webchat/executor.d.ts +4 -2
  22. package/src/executors/e2e-webchat/executor.js +4 -111
  23. package/src/executors/integrate-provider/executor-impl.d.ts +5 -0
  24. package/src/executors/integrate-provider/executor-impl.js +153 -0
  25. package/src/executors/integrate-provider/executor.d.ts +4 -2
  26. package/src/executors/integrate-provider/executor.js +3 -129
  27. package/src/executors/login-to-hubtype/executor-impl.d.ts +5 -0
  28. package/src/executors/login-to-hubtype/executor-impl.js +77 -0
  29. package/src/executors/login-to-hubtype/executor.d.ts +4 -2
  30. package/src/executors/login-to-hubtype/executor.js +3 -53
  31. package/src/executors/logout-from-hubtype/executor-impl.d.ts +3 -0
  32. package/src/executors/logout-from-hubtype/executor-impl.js +54 -0
  33. package/src/executors/logout-from-hubtype/executor.d.ts +5 -1
  34. package/src/executors/logout-from-hubtype/executor.js +3 -30
  35. package/src/executors/run-lambda/executor-impl.d.ts +5 -0
  36. package/src/executors/run-lambda/executor-impl.js +65 -0
  37. package/src/executors/run-lambda/executor.d.ts +4 -2
  38. package/src/executors/run-lambda/executor.js +3 -41
  39. package/src/executors/serve-bot/executor-impl.d.ts +5 -0
  40. package/src/executors/serve-bot/executor-impl.js +530 -0
  41. package/src/executors/serve-bot/executor.d.ts +4 -2
  42. package/src/executors/serve-bot/executor.js +3 -506
  43. package/src/generators/action/generator-impl.d.ts +4 -0
  44. package/src/generators/action/generator-impl.js +112 -0
  45. package/src/generators/action/generator.d.ts +2 -3
  46. package/src/generators/action/generator.js +2 -87
  47. package/src/generators/bot-app/files/vite/webchat.config.ts.template +10 -2
  48. package/src/generators/bot-app/generator-impl.d.ts +4 -0
  49. package/src/generators/bot-app/generator-impl.js +328 -0
  50. package/src/generators/bot-app/generator.d.ts +2 -4
  51. package/src/generators/bot-app/generator.js +2 -295
  52. package/src/generators/custom-message/generator-impl.d.ts +4 -0
  53. package/src/generators/custom-message/generator-impl.js +235 -0
  54. package/src/generators/custom-message/generator.d.ts +2 -3
  55. package/src/generators/custom-message/generator.js +2 -210
  56. package/src/generators/preset/generator-impl.d.ts +4 -0
  57. package/src/generators/preset/generator-impl.js +127 -0
  58. package/src/generators/preset/generator.d.ts +2 -4
  59. package/src/generators/preset/generator.js +2 -95
  60. package/src/generators/remove-custom-message/generator-impl.d.ts +4 -0
  61. package/src/generators/remove-custom-message/generator-impl.js +259 -0
  62. package/src/generators/remove-custom-message/generator.d.ts +2 -3
  63. package/src/generators/remove-custom-message/generator.js +2 -234
  64. package/src/generators/webview/generator-impl.d.ts +4 -0
  65. package/src/generators/webview/generator-impl.js +179 -0
  66. package/src/generators/webview/generator.d.ts +2 -3
  67. package/src/generators/webview/generator.js +2 -154
  68. package/src/index.d.ts +1 -0
  69. package/src/index.js +3 -1
  70. package/src/lib/delegate/delegate-executor.d.ts +6 -0
  71. package/src/lib/delegate/delegate-executor.js +119 -0
  72. package/src/lib/delegate/delegate-generator.d.ts +2 -0
  73. package/src/lib/delegate/delegate-generator.js +128 -0
  74. package/src/lib/serve-mode/index.d.ts +25 -0
  75. package/src/lib/serve-mode/index.js +183 -0
  76. package/src/generators/bot-app/files/vite/plugins/dev-log-viewer-html.plugin.ts.template +0 -65
  77. package/src/migrations/install-claude-update-skills/install-claude-update-skills.migration.d.ts +0 -2
  78. package/src/migrations/install-claude-update-skills/install-claude-update-skills.migration.js +0 -290
@@ -0,0 +1,259 @@
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
+ function normalizeOptions(tree, options) {
26
+ const projects = (0, import_devkit.getProjects)(tree);
27
+ const project = projects.get(options.project);
28
+ if (!project) {
29
+ throw new Error(`Project "${options.project}" not found`);
30
+ }
31
+ if (!project.tags?.includes("botonic:bot-app")) {
32
+ throw new Error(
33
+ `Project "${options.project}" is not a botonic bot application. Make sure it has the "botonic:bot-app" tag.`
34
+ );
35
+ }
36
+ const projectConfig = (0, import_devkit.readProjectConfiguration)(tree, options.project);
37
+ const projectRoot = projectConfig.root;
38
+ const sourceRoot = projectConfig.sourceRoot || `${projectRoot}/src`;
39
+ const name = (0, import_devkit.names)(options.name);
40
+ const fileName = name.fileName;
41
+ const className = name.className;
42
+ const propertyName = name.propertyName;
43
+ const constantName = name.constantName.toUpperCase();
44
+ const customMessagesPath = options.directory ? `${sourceRoot}/client/custom-messages/${options.directory}` : `${sourceRoot}/client/custom-messages`;
45
+ const configPath = `${sourceRoot}/shared/constants.ts`;
46
+ const actionsPath = `${sourceRoot}/server/bot/actions`;
47
+ const routesPath = `${sourceRoot}/server/bot/routes.ts`;
48
+ return {
49
+ ...options,
50
+ projectName: options.project,
51
+ projectRoot,
52
+ fileName,
53
+ className,
54
+ propertyName,
55
+ constantName,
56
+ customMessagesPath,
57
+ configPath,
58
+ actionsPath,
59
+ routesPath
60
+ };
61
+ }
62
+ function removeFiles(tree, options) {
63
+ const filesToRemove = [
64
+ `${options.customMessagesPath}/${options.fileName}.tsx`,
65
+ `${options.customMessagesPath}/${options.fileName}.spec.tsx`,
66
+ `${options.actionsPath}/${options.fileName}.ts`
67
+ ];
68
+ const removedFiles = [];
69
+ const notFoundFiles = [];
70
+ filesToRemove.forEach((filePath) => {
71
+ if (tree.exists(filePath)) {
72
+ tree.delete(filePath);
73
+ removedFiles.push(filePath);
74
+ } else {
75
+ notFoundFiles.push(filePath);
76
+ }
77
+ });
78
+ return { removedFiles, notFoundFiles };
79
+ }
80
+ function removeFromConfig(tree, options) {
81
+ if (!tree.exists(options.configPath)) {
82
+ console.warn(`Config file not found at ${options.configPath}`);
83
+ return false;
84
+ }
85
+ const content = tree.read(options.configPath, "utf-8");
86
+ const lines = content.split("\n");
87
+ const enumValuePattern = new RegExp(
88
+ `\\s*${options.constantName}\\s*[=:]\\s*['"]${options.fileName}['"],?`
89
+ );
90
+ let found = false;
91
+ const updatedLines = lines.filter((line) => {
92
+ if (enumValuePattern.test(line)) {
93
+ found = true;
94
+ return false;
95
+ }
96
+ return true;
97
+ });
98
+ if (found) {
99
+ tree.write(options.configPath, updatedLines.join("\n"));
100
+ }
101
+ return found;
102
+ }
103
+ function removeFromCustomMessagesIndex(tree, options) {
104
+ const indexPath = `${options.customMessagesPath}/index.ts`;
105
+ if (!tree.exists(indexPath)) {
106
+ console.warn(`Custom messages index not found at ${indexPath}`);
107
+ return false;
108
+ }
109
+ const content = tree.read(indexPath, "utf-8");
110
+ const lines = content.split("\n");
111
+ let found = false;
112
+ const updatedLines = lines.filter((line) => {
113
+ if (line.includes(`import { ${options.className} }`) && line.includes(
114
+ `./${options.directory ? options.directory + "/" : ""}${options.fileName}`
115
+ )) {
116
+ found = true;
117
+ return false;
118
+ }
119
+ if (line.includes(
120
+ `[CUSTOM_MESSAGE_TYPES.${options.constantName}]: ${options.className}`
121
+ )) {
122
+ found = true;
123
+ return false;
124
+ }
125
+ return true;
126
+ });
127
+ if (found) {
128
+ tree.write(indexPath, updatedLines.join("\n"));
129
+ }
130
+ return found;
131
+ }
132
+ function removeFromActionsIndex(tree, options) {
133
+ const indexPath = `${options.actionsPath}/index.ts`;
134
+ if (!tree.exists(indexPath)) {
135
+ console.warn(`Actions index not found at ${indexPath}`);
136
+ return false;
137
+ }
138
+ const content = tree.read(indexPath, "utf-8");
139
+ const exportStatement = `export * from './${options.fileName}'`;
140
+ if (content.includes(exportStatement)) {
141
+ const updatedContent = content.replace(exportStatement + "\n", "").replace(exportStatement, "");
142
+ tree.write(indexPath, updatedContent);
143
+ return true;
144
+ }
145
+ return false;
146
+ }
147
+ function removeFromRoutes(tree, options) {
148
+ if (!tree.exists(options.routesPath)) {
149
+ console.warn(`Routes file not found at ${options.routesPath}`);
150
+ return false;
151
+ }
152
+ const content = tree.read(options.routesPath, "utf-8");
153
+ const lines = content.split("\n");
154
+ const actionImport = `${options.propertyName}Output`;
155
+ let found = false;
156
+ let importStartIndex = -1;
157
+ let importEndIndex = -1;
158
+ for (let i = 0; i < lines.length; i++) {
159
+ if (lines[i].includes("import {") && lines.slice(i, i + 10).some((line) => line.includes("from './actions'"))) {
160
+ importStartIndex = i;
161
+ for (let j = i; j < lines.length; j++) {
162
+ if (lines[j].includes("from './actions'")) {
163
+ importEndIndex = j;
164
+ break;
165
+ }
166
+ }
167
+ break;
168
+ }
169
+ }
170
+ if (importStartIndex !== -1 && importEndIndex !== -1) {
171
+ const importSection = lines.slice(importStartIndex, importEndIndex + 1).join("\n");
172
+ if (importSection.includes(actionImport)) {
173
+ for (let i = importStartIndex; i <= importEndIndex; i++) {
174
+ if (lines[i].includes(actionImport)) {
175
+ if (lines[i].trim() === `${actionImport},` || lines[i].trim() === actionImport) {
176
+ lines.splice(i, 1);
177
+ importEndIndex--;
178
+ } else {
179
+ lines[i] = lines[i].replace(`,\\s*${actionImport}`, "").replace(`${actionImport},`, "").replace(actionImport, "");
180
+ }
181
+ found = true;
182
+ break;
183
+ }
184
+ }
185
+ }
186
+ }
187
+ let routeStartIndex = -1;
188
+ let routeEndIndex = -1;
189
+ for (let i = 0; i < lines.length; i++) {
190
+ if (lines[i].includes(`text: '${options.fileName}'`) && lines[i + 1]?.includes(actionImport)) {
191
+ for (let j = i - 1; j >= 0; j--) {
192
+ if (lines[j].trim() === "{") {
193
+ routeStartIndex = j;
194
+ break;
195
+ }
196
+ }
197
+ for (let j = i + 1; j < lines.length; j++) {
198
+ if (lines[j].includes("},")) {
199
+ routeEndIndex = j;
200
+ break;
201
+ }
202
+ }
203
+ break;
204
+ }
205
+ }
206
+ if (routeStartIndex !== -1 && routeEndIndex !== -1) {
207
+ lines.splice(routeStartIndex, routeEndIndex - routeStartIndex + 1);
208
+ found = true;
209
+ }
210
+ if (found) {
211
+ tree.write(options.routesPath, lines.join("\n"));
212
+ }
213
+ return found;
214
+ }
215
+ async function generator_impl_default(tree, options) {
216
+ console.log(`\u{1F5D1}\uFE0F Removing custom message: ${options.name}`);
217
+ const normalizedOptions = normalizeOptions(tree, options);
218
+ console.log(`\u{1F4C1} Project: ${normalizedOptions.projectName}`);
219
+ console.log(`\u{1F4C2} Location: ${normalizedOptions.customMessagesPath}`);
220
+ if (!options.skipConfirmation) {
221
+ console.log(`
222
+ \u26A0\uFE0F This will remove the following:`);
223
+ console.log(` - Component: ${normalizedOptions.fileName}.tsx`);
224
+ console.log(` - Tests: ${normalizedOptions.fileName}.spec.tsx`);
225
+ console.log(` - Action: ${normalizedOptions.fileName}.ts`);
226
+ console.log(
227
+ ` - Config enum: CUSTOM_MESSAGE_TYPES.${normalizedOptions.constantName}`
228
+ );
229
+ console.log(` - Registration in customMessages object`);
230
+ console.log(` - Route in routes.ts`);
231
+ console.log(`
232
+ Continue? This action cannot be undone.`);
233
+ }
234
+ const { removedFiles, notFoundFiles } = removeFiles(tree, normalizedOptions);
235
+ const configUpdated = removeFromConfig(tree, normalizedOptions);
236
+ const indexUpdated = removeFromCustomMessagesIndex(tree, normalizedOptions);
237
+ const actionsUpdated = removeFromActionsIndex(tree, normalizedOptions);
238
+ const routesUpdated = removeFromRoutes(tree, normalizedOptions);
239
+ await (0, import_devkit.formatFiles)(tree);
240
+ console.log(
241
+ `
242
+ \u{1F389} Successfully removed custom message: ${normalizedOptions.className}`
243
+ );
244
+ if (removedFiles.length > 0) {
245
+ console.log(`\u{1F4C1} Removed files:`);
246
+ removedFiles.forEach((file) => console.log(` - ${file}`));
247
+ }
248
+ if (notFoundFiles.length > 0) {
249
+ console.log(`\u26A0\uFE0F Files not found (skipped):`);
250
+ notFoundFiles.forEach((file) => console.log(` - ${file}`));
251
+ }
252
+ console.log(`\u{1F4DD} Updated configurations:`);
253
+ console.log(` - Config enum: ${configUpdated ? "\u2705" : "\u274C"}`);
254
+ console.log(` - Custom messages index: ${indexUpdated ? "\u2705" : "\u274C"}`);
255
+ console.log(` - Actions index: ${actionsUpdated ? "\u2705" : "\u274C"}`);
256
+ console.log(` - Routes: ${routesUpdated ? "\u2705" : "\u274C"}`);
257
+ console.log(`
258
+ \u{1F680} Custom message removal complete!`);
259
+ }
@@ -1,4 +1,3 @@
1
- import { Tree } from '@nx/devkit';
1
+ import type { Tree } from '@nx/devkit';
2
2
  import type { RemoveCustomMessageGeneratorSchema } from './schema';
3
- export default function (tree: Tree, options: RemoveCustomMessageGeneratorSchema): Promise<void>;
4
- export { RemoveCustomMessageGeneratorSchema };
3
+ export default function (tree: Tree, options: RemoveCustomMessageGeneratorSchema): Promise<void | import("@nx/devkit").GeneratorCallback>;
@@ -21,239 +21,7 @@ __export(generator_exports, {
21
21
  default: () => generator_default
22
22
  });
23
23
  module.exports = __toCommonJS(generator_exports);
24
- var import_devkit = require("@nx/devkit");
25
- function normalizeOptions(tree, options) {
26
- const projects = (0, import_devkit.getProjects)(tree);
27
- const project = projects.get(options.project);
28
- if (!project) {
29
- throw new Error(`Project "${options.project}" not found`);
30
- }
31
- if (!project.tags?.includes("botonic:bot-app")) {
32
- throw new Error(
33
- `Project "${options.project}" is not a botonic bot application. Make sure it has the "botonic:bot-app" tag.`
34
- );
35
- }
36
- const projectConfig = (0, import_devkit.readProjectConfiguration)(tree, options.project);
37
- const projectRoot = projectConfig.root;
38
- const sourceRoot = projectConfig.sourceRoot || `${projectRoot}/src`;
39
- const name = (0, import_devkit.names)(options.name);
40
- const fileName = name.fileName;
41
- const className = name.className;
42
- const propertyName = name.propertyName;
43
- const constantName = name.constantName.toUpperCase();
44
- const customMessagesPath = options.directory ? `${sourceRoot}/client/custom-messages/${options.directory}` : `${sourceRoot}/client/custom-messages`;
45
- const configPath = `${sourceRoot}/shared/constants.ts`;
46
- const actionsPath = `${sourceRoot}/server/bot/actions`;
47
- const routesPath = `${sourceRoot}/server/bot/routes.ts`;
48
- return {
49
- ...options,
50
- projectName: options.project,
51
- projectRoot,
52
- fileName,
53
- className,
54
- propertyName,
55
- constantName,
56
- customMessagesPath,
57
- configPath,
58
- actionsPath,
59
- routesPath
60
- };
61
- }
62
- function removeFiles(tree, options) {
63
- const filesToRemove = [
64
- `${options.customMessagesPath}/${options.fileName}.tsx`,
65
- `${options.customMessagesPath}/${options.fileName}.spec.tsx`,
66
- `${options.actionsPath}/${options.fileName}.ts`
67
- ];
68
- const removedFiles = [];
69
- const notFoundFiles = [];
70
- filesToRemove.forEach((filePath) => {
71
- if (tree.exists(filePath)) {
72
- tree.delete(filePath);
73
- removedFiles.push(filePath);
74
- } else {
75
- notFoundFiles.push(filePath);
76
- }
77
- });
78
- return { removedFiles, notFoundFiles };
79
- }
80
- function removeFromConfig(tree, options) {
81
- if (!tree.exists(options.configPath)) {
82
- console.warn(`Config file not found at ${options.configPath}`);
83
- return false;
84
- }
85
- const content = tree.read(options.configPath, "utf-8");
86
- const lines = content.split("\n");
87
- const enumValuePattern = new RegExp(
88
- `\\s*${options.constantName}\\s*[=:]\\s*['"]${options.fileName}['"],?`
89
- );
90
- let found = false;
91
- const updatedLines = lines.filter((line) => {
92
- if (enumValuePattern.test(line)) {
93
- found = true;
94
- return false;
95
- }
96
- return true;
97
- });
98
- if (found) {
99
- tree.write(options.configPath, updatedLines.join("\n"));
100
- }
101
- return found;
102
- }
103
- function removeFromCustomMessagesIndex(tree, options) {
104
- const indexPath = `${options.customMessagesPath}/index.ts`;
105
- if (!tree.exists(indexPath)) {
106
- console.warn(`Custom messages index not found at ${indexPath}`);
107
- return false;
108
- }
109
- const content = tree.read(indexPath, "utf-8");
110
- const lines = content.split("\n");
111
- let found = false;
112
- const updatedLines = lines.filter((line) => {
113
- if (line.includes(`import { ${options.className} }`) && line.includes(
114
- `./${options.directory ? options.directory + "/" : ""}${options.fileName}`
115
- )) {
116
- found = true;
117
- return false;
118
- }
119
- if (line.includes(
120
- `[CUSTOM_MESSAGE_TYPES.${options.constantName}]: ${options.className}`
121
- )) {
122
- found = true;
123
- return false;
124
- }
125
- return true;
126
- });
127
- if (found) {
128
- tree.write(indexPath, updatedLines.join("\n"));
129
- }
130
- return found;
131
- }
132
- function removeFromActionsIndex(tree, options) {
133
- const indexPath = `${options.actionsPath}/index.ts`;
134
- if (!tree.exists(indexPath)) {
135
- console.warn(`Actions index not found at ${indexPath}`);
136
- return false;
137
- }
138
- const content = tree.read(indexPath, "utf-8");
139
- const exportStatement = `export * from './${options.fileName}'`;
140
- if (content.includes(exportStatement)) {
141
- const updatedContent = content.replace(exportStatement + "\n", "").replace(exportStatement, "");
142
- tree.write(indexPath, updatedContent);
143
- return true;
144
- }
145
- return false;
146
- }
147
- function removeFromRoutes(tree, options) {
148
- if (!tree.exists(options.routesPath)) {
149
- console.warn(`Routes file not found at ${options.routesPath}`);
150
- return false;
151
- }
152
- const content = tree.read(options.routesPath, "utf-8");
153
- const lines = content.split("\n");
154
- const actionImport = `${options.propertyName}Output`;
155
- let found = false;
156
- let importStartIndex = -1;
157
- let importEndIndex = -1;
158
- for (let i = 0; i < lines.length; i++) {
159
- if (lines[i].includes("import {") && lines.slice(i, i + 10).some((line) => line.includes("from './actions'"))) {
160
- importStartIndex = i;
161
- for (let j = i; j < lines.length; j++) {
162
- if (lines[j].includes("from './actions'")) {
163
- importEndIndex = j;
164
- break;
165
- }
166
- }
167
- break;
168
- }
169
- }
170
- if (importStartIndex !== -1 && importEndIndex !== -1) {
171
- const importSection = lines.slice(importStartIndex, importEndIndex + 1).join("\n");
172
- if (importSection.includes(actionImport)) {
173
- for (let i = importStartIndex; i <= importEndIndex; i++) {
174
- if (lines[i].includes(actionImport)) {
175
- if (lines[i].trim() === `${actionImport},` || lines[i].trim() === actionImport) {
176
- lines.splice(i, 1);
177
- importEndIndex--;
178
- } else {
179
- lines[i] = lines[i].replace(`,\\s*${actionImport}`, "").replace(`${actionImport},`, "").replace(actionImport, "");
180
- }
181
- found = true;
182
- break;
183
- }
184
- }
185
- }
186
- }
187
- let routeStartIndex = -1;
188
- let routeEndIndex = -1;
189
- for (let i = 0; i < lines.length; i++) {
190
- if (lines[i].includes(`text: '${options.fileName}'`) && lines[i + 1]?.includes(actionImport)) {
191
- for (let j = i - 1; j >= 0; j--) {
192
- if (lines[j].trim() === "{") {
193
- routeStartIndex = j;
194
- break;
195
- }
196
- }
197
- for (let j = i + 1; j < lines.length; j++) {
198
- if (lines[j].includes("},")) {
199
- routeEndIndex = j;
200
- break;
201
- }
202
- }
203
- break;
204
- }
205
- }
206
- if (routeStartIndex !== -1 && routeEndIndex !== -1) {
207
- lines.splice(routeStartIndex, routeEndIndex - routeStartIndex + 1);
208
- found = true;
209
- }
210
- if (found) {
211
- tree.write(options.routesPath, lines.join("\n"));
212
- }
213
- return found;
214
- }
24
+ var import_delegate_generator = require("../../lib/delegate/delegate-generator");
215
25
  async function generator_default(tree, options) {
216
- console.log(`\u{1F5D1}\uFE0F Removing custom message: ${options.name}`);
217
- const normalizedOptions = normalizeOptions(tree, options);
218
- console.log(`\u{1F4C1} Project: ${normalizedOptions.projectName}`);
219
- console.log(`\u{1F4C2} Location: ${normalizedOptions.customMessagesPath}`);
220
- if (!options.skipConfirmation) {
221
- console.log(`
222
- \u26A0\uFE0F This will remove the following:`);
223
- console.log(` - Component: ${normalizedOptions.fileName}.tsx`);
224
- console.log(` - Tests: ${normalizedOptions.fileName}.spec.tsx`);
225
- console.log(` - Action: ${normalizedOptions.fileName}.ts`);
226
- console.log(
227
- ` - Config enum: CUSTOM_MESSAGE_TYPES.${normalizedOptions.constantName}`
228
- );
229
- console.log(` - Registration in customMessages object`);
230
- console.log(` - Route in routes.ts`);
231
- console.log(`
232
- Continue? This action cannot be undone.`);
233
- }
234
- const { removedFiles, notFoundFiles } = removeFiles(tree, normalizedOptions);
235
- const configUpdated = removeFromConfig(tree, normalizedOptions);
236
- const indexUpdated = removeFromCustomMessagesIndex(tree, normalizedOptions);
237
- const actionsUpdated = removeFromActionsIndex(tree, normalizedOptions);
238
- const routesUpdated = removeFromRoutes(tree, normalizedOptions);
239
- await (0, import_devkit.formatFiles)(tree);
240
- console.log(
241
- `
242
- \u{1F389} Successfully removed custom message: ${normalizedOptions.className}`
243
- );
244
- if (removedFiles.length > 0) {
245
- console.log(`\u{1F4C1} Removed files:`);
246
- removedFiles.forEach((file) => console.log(` - ${file}`));
247
- }
248
- if (notFoundFiles.length > 0) {
249
- console.log(`\u26A0\uFE0F Files not found (skipped):`);
250
- notFoundFiles.forEach((file) => console.log(` - ${file}`));
251
- }
252
- console.log(`\u{1F4DD} Updated configurations:`);
253
- console.log(` - Config enum: ${configUpdated ? "\u2705" : "\u274C"}`);
254
- console.log(` - Custom messages index: ${indexUpdated ? "\u2705" : "\u274C"}`);
255
- console.log(` - Actions index: ${actionsUpdated ? "\u2705" : "\u274C"}`);
256
- console.log(` - Routes: ${routesUpdated ? "\u2705" : "\u274C"}`);
257
- console.log(`
258
- \u{1F680} Custom message removal complete!`);
26
+ return (0, import_delegate_generator.runLocalGenerator)(__filename, "remove-custom-message", tree, options);
259
27
  }
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import type { WebviewGeneratorSchema } from './schema';
3
+ export default function (tree: Tree, options: WebviewGeneratorSchema): Promise<void>;
4
+ export { WebviewGeneratorSchema };
@@ -0,0 +1,179 @@
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 constantName = name.constantName.toUpperCase();
37
+ return {
38
+ ...options,
39
+ projectName: options.project,
40
+ projectRoot,
41
+ fileName,
42
+ className,
43
+ constantName,
44
+ webviewsPath: paths.webviewsPath,
45
+ constantsPath: paths.constantsPath
46
+ };
47
+ }
48
+ function addFilesToProject(tree, options) {
49
+ const name = (0, import_devkit.names)(options.name);
50
+ const templateOptions = {
51
+ ...options,
52
+ ...name,
53
+ name: name.fileName
54
+ // __name__ in filenames must be kebab-case
55
+ };
56
+ (0, import_devkit.generateFiles)(
57
+ tree,
58
+ (0, import_devkit.joinPathFragments)(MODULE_DIR, "files"),
59
+ options.webviewsPath,
60
+ templateOptions
61
+ );
62
+ if (options.skipTests) {
63
+ const testFilePath = `${options.webviewsPath}/${options.fileName}.spec.tsx`;
64
+ if (tree.exists(testFilePath)) {
65
+ tree.delete(testFilePath);
66
+ }
67
+ }
68
+ }
69
+ function updateConstantsFile(tree, options) {
70
+ if (!tree.exists(options.constantsPath)) {
71
+ tree.write(
72
+ options.constantsPath,
73
+ `export const CUSTOM_MESSAGE_TYPES = {
74
+ // Add your custom message types here
75
+ } as const
76
+
77
+ export const WEBVIEWS = {
78
+ ${options.constantName}: '${options.fileName}',
79
+ } as const
80
+
81
+ export const PAYLOADS = {
82
+ // Add your payloads here
83
+ } as const
84
+ `
85
+ );
86
+ return;
87
+ }
88
+ (0, import_bot_app_utils.addConstEntry)(
89
+ tree,
90
+ options.constantsPath,
91
+ "WEBVIEWS",
92
+ options.constantName,
93
+ options.fileName
94
+ );
95
+ }
96
+ function updateWebviewsIndex(tree, options) {
97
+ const indexPath = `${options.webviewsPath}/index.tsx`;
98
+ if (!tree.exists(indexPath)) {
99
+ console.warn(
100
+ `Webviews index not found at ${indexPath}. Skipping registration.`
101
+ );
102
+ return;
103
+ }
104
+ const content = tree.read(indexPath, "utf-8");
105
+ const lines = content.split("\n");
106
+ const componentImport = `import { ${options.className} } from './${options.fileName}'`;
107
+ if (!content.includes(componentImport)) {
108
+ let lastImportIndex = -1;
109
+ for (let i = 0; i < lines.length; i++) {
110
+ if (lines[i].startsWith("import ")) lastImportIndex = i;
111
+ }
112
+ lines.splice(lastImportIndex + 1, 0, componentImport);
113
+ }
114
+ if (!content.includes("WEBVIEWS")) {
115
+ const sharedImport = `import { WEBVIEWS } from '../../shared/constants'`;
116
+ let lastImportIndex = -1;
117
+ for (let i = 0; i < lines.length; i++) {
118
+ if (lines[i].startsWith("import ")) lastImportIndex = i;
119
+ }
120
+ lines.splice(lastImportIndex, 0, sharedImport);
121
+ }
122
+ const newEntry = [
123
+ ` {`,
124
+ ` path: WEBVIEWS.${options.constantName},`,
125
+ ` component: ${options.className},`,
126
+ ` allowClose: true,`,
127
+ ` },`
128
+ ];
129
+ const alreadyRegistered = lines.some(
130
+ (l) => l.includes(`WEBVIEWS.${options.constantName}`)
131
+ );
132
+ if (!alreadyRegistered) {
133
+ let arrayCloseIndex = -1;
134
+ let inArray = false;
135
+ let depth = 0;
136
+ for (let i = 0; i < lines.length; i++) {
137
+ if (lines[i].includes("WebviewDefinition[]") || lines[i].includes("const webviews")) {
138
+ inArray = true;
139
+ }
140
+ if (inArray) {
141
+ for (const char of lines[i]) {
142
+ if (char === "[") depth++;
143
+ if (char === "]") depth--;
144
+ }
145
+ if (depth === 0 && inArray && lines[i].includes("]")) {
146
+ arrayCloseIndex = i;
147
+ break;
148
+ }
149
+ }
150
+ }
151
+ if (arrayCloseIndex !== -1) {
152
+ for (let i = newEntry.length - 1; i >= 0; i--) {
153
+ lines.splice(arrayCloseIndex, 0, newEntry[i]);
154
+ }
155
+ }
156
+ }
157
+ tree.write(indexPath, lines.join("\n"));
158
+ }
159
+ async function generator_impl_default(tree, options) {
160
+ console.log(`Creating webview: ${options.name}`);
161
+ const normalizedOptions = normalizeOptions(tree, options);
162
+ console.log(`Project: ${normalizedOptions.projectName}`);
163
+ console.log(`Location: ${normalizedOptions.webviewsPath}`);
164
+ addFilesToProject(tree, normalizedOptions);
165
+ updateConstantsFile(tree, normalizedOptions);
166
+ updateWebviewsIndex(tree, normalizedOptions);
167
+ await (0, import_devkit.formatFiles)(tree);
168
+ console.log(`
169
+ Successfully created webview: ${normalizedOptions.className}`);
170
+ console.log(`Next steps:`);
171
+ console.log(
172
+ ` 1. Implement the UI in: ${normalizedOptions.webviewsPath}/${normalizedOptions.fileName}.tsx`
173
+ );
174
+ if (!options.skipTests) {
175
+ console.log(
176
+ ` 2. Update the tests in: ${normalizedOptions.webviewsPath}/${normalizedOptions.fileName}.spec.tsx`
177
+ );
178
+ }
179
+ }
@@ -1,4 +1,3 @@
1
- import { Tree } from '@nx/devkit';
1
+ import type { Tree } from '@nx/devkit';
2
2
  import type { WebviewGeneratorSchema } from './schema';
3
- export default function (tree: Tree, options: WebviewGeneratorSchema): Promise<void>;
4
- export { WebviewGeneratorSchema };
3
+ export default function (tree: Tree, options: WebviewGeneratorSchema): Promise<void | import("@nx/devkit").GeneratorCallback>;