@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
|
@@ -21,159 +21,7 @@ __export(generator_exports, {
|
|
|
21
21
|
default: () => generator_default
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(generator_exports);
|
|
24
|
-
var
|
|
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
|
-
}
|
|
24
|
+
var import_delegate_generator = require("../../lib/delegate/delegate-generator");
|
|
159
25
|
async function generator_default(tree, options) {
|
|
160
|
-
|
|
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
|
-
}
|
|
26
|
+
return (0, import_delegate_generator.runLocalGenerator)(__filename, "webview", tree, options);
|
|
179
27
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export { default as buildNodeAppExecutor } from './executors/build-node-app/exec
|
|
|
4
4
|
export { default as runLambdaExecutor } from './executors/run-lambda/executor';
|
|
5
5
|
export { default as serveBotExecutor } from './executors/serve-bot/executor';
|
|
6
6
|
export * from './lib';
|
|
7
|
+
export * from './lib/serve-mode';
|
|
7
8
|
export { BotonicPlugin, createNodesV2 } from './plugin';
|
package/src/index.js
CHANGED
|
@@ -42,6 +42,7 @@ var import_executor = __toESM(require("./executors/build-node-app/executor"));
|
|
|
42
42
|
var import_executor2 = __toESM(require("./executors/run-lambda/executor"));
|
|
43
43
|
var import_executor3 = __toESM(require("./executors/serve-bot/executor"));
|
|
44
44
|
__reExport(src_exports, require("./lib"), module.exports);
|
|
45
|
+
__reExport(src_exports, require("./lib/serve-mode"), module.exports);
|
|
45
46
|
var import_plugin = require("./plugin");
|
|
46
47
|
// Annotate the CommonJS export names for ESM import in node:
|
|
47
48
|
0 && (module.exports = {
|
|
@@ -52,5 +53,6 @@ var import_plugin = require("./plugin");
|
|
|
52
53
|
serveBotExecutor,
|
|
53
54
|
...require("./generators/bot-app/generator"),
|
|
54
55
|
...require("./generators/preset/generator"),
|
|
55
|
-
...require("./lib")
|
|
56
|
+
...require("./lib"),
|
|
57
|
+
...require("./lib/serve-mode")
|
|
56
58
|
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
export declare function runLocalExecutor<T = unknown>(wrapperFilename: string, executorName: string, options: T, ctx: ExecutorContext): Promise<{
|
|
3
|
+
success: boolean;
|
|
4
|
+
} | AsyncIterableIterator<{
|
|
5
|
+
success: boolean;
|
|
6
|
+
}>>;
|
|
@@ -0,0 +1,119 @@
|
|
|
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 delegate_executor_exports = {};
|
|
20
|
+
__export(delegate_executor_exports, {
|
|
21
|
+
runLocalExecutor: () => runLocalExecutor
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(delegate_executor_exports);
|
|
24
|
+
var import_devkit = require("@nx/devkit");
|
|
25
|
+
var import_fs = require("fs");
|
|
26
|
+
var import_path = require("path");
|
|
27
|
+
const DEPTH_VAR = "BOTONIC_NX_PLUGIN_DELEGATION_DEPTH";
|
|
28
|
+
async function runLocalExecutor(wrapperFilename, executorName, options, ctx) {
|
|
29
|
+
const wrapperDir = (0, import_path.dirname)(wrapperFilename);
|
|
30
|
+
const implPath = (0, import_path.join)(wrapperDir, "executor-impl");
|
|
31
|
+
const impl = async () => {
|
|
32
|
+
const mod = await import(
|
|
33
|
+
/* @vite-ignore */
|
|
34
|
+
implPath
|
|
35
|
+
);
|
|
36
|
+
return (mod.default ?? mod)(options, ctx);
|
|
37
|
+
};
|
|
38
|
+
if (process.env[DEPTH_VAR]) return impl();
|
|
39
|
+
const projectRoot = ctx.projectName ? (0, import_path.join)(ctx.root, ctx.projectsConfigurations.projects[ctx.projectName].root) : ctx.root;
|
|
40
|
+
const myPkgJson = resolveSelfPkgJson(wrapperDir);
|
|
41
|
+
if (!myPkgJson) return impl();
|
|
42
|
+
const workspaceVersion = readVersion(myPkgJson);
|
|
43
|
+
let localPkgJson = null;
|
|
44
|
+
try {
|
|
45
|
+
localPkgJson = require.resolve("@botonic/nx-plugin/package.json", {
|
|
46
|
+
paths: [projectRoot]
|
|
47
|
+
});
|
|
48
|
+
} catch {
|
|
49
|
+
import_devkit.logger.info(
|
|
50
|
+
`[@botonic/nx-plugin v${workspaceVersion}] Running executor '${executorName}'`
|
|
51
|
+
);
|
|
52
|
+
return impl();
|
|
53
|
+
}
|
|
54
|
+
if ((0, import_fs.realpathSync)(localPkgJson) === (0, import_fs.realpathSync)(myPkgJson)) {
|
|
55
|
+
import_devkit.logger.info(
|
|
56
|
+
`[@botonic/nx-plugin v${workspaceVersion}] Running executor '${executorName}'`
|
|
57
|
+
);
|
|
58
|
+
return impl();
|
|
59
|
+
}
|
|
60
|
+
const localRoot = (0, import_path.dirname)(localPkgJson);
|
|
61
|
+
const execJsonPath = (0, import_path.join)(localRoot, "executors.json");
|
|
62
|
+
if (!(0, import_fs.existsSync)(execJsonPath)) {
|
|
63
|
+
import_devkit.logger.info(
|
|
64
|
+
`[@botonic/nx-plugin v${workspaceVersion}] Running executor '${executorName}'`
|
|
65
|
+
);
|
|
66
|
+
return impl();
|
|
67
|
+
}
|
|
68
|
+
const execJson = JSON.parse((0, import_fs.readFileSync)(execJsonPath, "utf-8"));
|
|
69
|
+
const entry = execJson?.executors?.[executorName];
|
|
70
|
+
if (!entry?.implementation) {
|
|
71
|
+
import_devkit.logger.info(
|
|
72
|
+
`[@botonic/nx-plugin v${workspaceVersion}] Running executor '${executorName}'`
|
|
73
|
+
);
|
|
74
|
+
return impl();
|
|
75
|
+
}
|
|
76
|
+
const implRelative = entry.implementation;
|
|
77
|
+
const implResolved = require.resolve((0, import_path.join)(localRoot, implRelative));
|
|
78
|
+
const localVersion = readVersion(localPkgJson);
|
|
79
|
+
import_devkit.logger.info(
|
|
80
|
+
`[@botonic/nx-plugin v${workspaceVersion}] Delegating executor '${executorName}' to local v${localVersion}`
|
|
81
|
+
);
|
|
82
|
+
process.env[DEPTH_VAR] = "1";
|
|
83
|
+
try {
|
|
84
|
+
const mod = await import(
|
|
85
|
+
/* @vite-ignore */
|
|
86
|
+
implResolved
|
|
87
|
+
);
|
|
88
|
+
return await (mod.default ?? mod)(options, ctx);
|
|
89
|
+
} finally {
|
|
90
|
+
delete process.env[DEPTH_VAR];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function readVersion(pkgJsonPath) {
|
|
94
|
+
try {
|
|
95
|
+
return JSON.parse((0, import_fs.readFileSync)(pkgJsonPath, "utf-8")).version ?? "unknown";
|
|
96
|
+
} catch {
|
|
97
|
+
return "unknown";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function resolveSelfPkgJson(startDir) {
|
|
101
|
+
let dir = startDir;
|
|
102
|
+
while (true) {
|
|
103
|
+
const pkgPath = (0, import_path.join)(dir, "package.json");
|
|
104
|
+
if ((0, import_fs.existsSync)(pkgPath)) {
|
|
105
|
+
try {
|
|
106
|
+
const pkg = JSON.parse((0, import_fs.readFileSync)(pkgPath, "utf-8"));
|
|
107
|
+
if (pkg.name === "@botonic/nx-plugin") return pkgPath;
|
|
108
|
+
} catch {
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const next = (0, import_path.dirname)(dir);
|
|
112
|
+
if (next === dir) return null;
|
|
113
|
+
dir = next;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
117
|
+
0 && (module.exports = {
|
|
118
|
+
runLocalExecutor
|
|
119
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
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 delegate_generator_exports = {};
|
|
20
|
+
__export(delegate_generator_exports, {
|
|
21
|
+
runLocalGenerator: () => runLocalGenerator
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(delegate_generator_exports);
|
|
24
|
+
var import_devkit = require("@nx/devkit");
|
|
25
|
+
var import_fs = require("fs");
|
|
26
|
+
var import_path = require("path");
|
|
27
|
+
const DEPTH_VAR = "BOTONIC_NX_PLUGIN_DELEGATION_DEPTH";
|
|
28
|
+
async function runLocalGenerator(wrapperFilename, generatorName, tree, options) {
|
|
29
|
+
const wrapperDir = (0, import_path.dirname)(wrapperFilename);
|
|
30
|
+
const implPath = (0, import_path.join)(wrapperDir, "generator-impl");
|
|
31
|
+
const impl = async () => {
|
|
32
|
+
const mod = await import(
|
|
33
|
+
/* @vite-ignore */
|
|
34
|
+
implPath
|
|
35
|
+
);
|
|
36
|
+
return (mod.default ?? mod)(tree, options);
|
|
37
|
+
};
|
|
38
|
+
if (process.env[DEPTH_VAR]) return impl();
|
|
39
|
+
let projectRoot = null;
|
|
40
|
+
const projectName = options.project;
|
|
41
|
+
if (typeof projectName === "string") {
|
|
42
|
+
try {
|
|
43
|
+
const config = (0, import_devkit.readProjectConfiguration)(tree, projectName);
|
|
44
|
+
projectRoot = config.root;
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!projectRoot) return impl();
|
|
49
|
+
const myPkgJson = resolveSelfPkgJson(wrapperDir);
|
|
50
|
+
if (!myPkgJson) return impl();
|
|
51
|
+
const workspaceVersion = readVersion(myPkgJson);
|
|
52
|
+
let localPkgJson = null;
|
|
53
|
+
try {
|
|
54
|
+
localPkgJson = require.resolve("@botonic/nx-plugin/package.json", {
|
|
55
|
+
paths: [projectRoot]
|
|
56
|
+
});
|
|
57
|
+
} catch {
|
|
58
|
+
import_devkit.logger.info(
|
|
59
|
+
`[@botonic/nx-plugin v${workspaceVersion}] Running generator '${generatorName}'`
|
|
60
|
+
);
|
|
61
|
+
return impl();
|
|
62
|
+
}
|
|
63
|
+
if ((0, import_fs.realpathSync)(localPkgJson) === (0, import_fs.realpathSync)(myPkgJson)) {
|
|
64
|
+
import_devkit.logger.info(
|
|
65
|
+
`[@botonic/nx-plugin v${workspaceVersion}] Running generator '${generatorName}'`
|
|
66
|
+
);
|
|
67
|
+
return impl();
|
|
68
|
+
}
|
|
69
|
+
const localRoot = (0, import_path.dirname)(localPkgJson);
|
|
70
|
+
const genJsonPath = (0, import_path.join)(localRoot, "generators.json");
|
|
71
|
+
if (!(0, import_fs.existsSync)(genJsonPath)) {
|
|
72
|
+
import_devkit.logger.info(
|
|
73
|
+
`[@botonic/nx-plugin v${workspaceVersion}] Running generator '${generatorName}'`
|
|
74
|
+
);
|
|
75
|
+
return impl();
|
|
76
|
+
}
|
|
77
|
+
const genJson = JSON.parse((0, import_fs.readFileSync)(genJsonPath, "utf-8"));
|
|
78
|
+
const entry = genJson?.generators?.[generatorName];
|
|
79
|
+
if (!entry?.factory) {
|
|
80
|
+
import_devkit.logger.info(
|
|
81
|
+
`[@botonic/nx-plugin v${workspaceVersion}] Running generator '${generatorName}'`
|
|
82
|
+
);
|
|
83
|
+
return impl();
|
|
84
|
+
}
|
|
85
|
+
const factoryRelative = entry.factory;
|
|
86
|
+
const factoryResolved = require.resolve((0, import_path.join)(localRoot, factoryRelative));
|
|
87
|
+
const localVersion = readVersion(localPkgJson);
|
|
88
|
+
import_devkit.logger.info(
|
|
89
|
+
`[@botonic/nx-plugin v${workspaceVersion}] Delegating generator '${generatorName}' to local v${localVersion}`
|
|
90
|
+
);
|
|
91
|
+
process.env[DEPTH_VAR] = "1";
|
|
92
|
+
try {
|
|
93
|
+
const mod = await import(
|
|
94
|
+
/* @vite-ignore */
|
|
95
|
+
factoryResolved
|
|
96
|
+
);
|
|
97
|
+
return await (mod.default ?? mod)(tree, options);
|
|
98
|
+
} finally {
|
|
99
|
+
delete process.env[DEPTH_VAR];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function readVersion(pkgJsonPath) {
|
|
103
|
+
try {
|
|
104
|
+
return JSON.parse((0, import_fs.readFileSync)(pkgJsonPath, "utf-8")).version ?? "unknown";
|
|
105
|
+
} catch {
|
|
106
|
+
return "unknown";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function resolveSelfPkgJson(startDir) {
|
|
110
|
+
let dir = startDir;
|
|
111
|
+
while (true) {
|
|
112
|
+
const pkgPath = (0, import_path.join)(dir, "package.json");
|
|
113
|
+
if ((0, import_fs.existsSync)(pkgPath)) {
|
|
114
|
+
try {
|
|
115
|
+
const pkg = JSON.parse((0, import_fs.readFileSync)(pkgPath, "utf-8"));
|
|
116
|
+
if (pkg.name === "@botonic/nx-plugin") return pkgPath;
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const next = (0, import_path.dirname)(dir);
|
|
121
|
+
if (next === dir) return null;
|
|
122
|
+
dir = next;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
+
0 && (module.exports = {
|
|
127
|
+
runLocalGenerator
|
|
128
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export interface ChannelCredentials {
|
|
3
|
+
botId?: string;
|
|
4
|
+
apiUrl?: string;
|
|
5
|
+
tunnelUrl?: string;
|
|
6
|
+
lambdaFn?: string;
|
|
7
|
+
accessToken?: string;
|
|
8
|
+
refreshToken?: string;
|
|
9
|
+
clientId?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface WhatsappPanelOptions extends ChannelCredentials {
|
|
12
|
+
registeredPhone?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface DevPanelsOptions {
|
|
15
|
+
panels: Array<'whatsapp' | 'webchat'>;
|
|
16
|
+
registeredPhone?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Injects the WhatsApp channel routing panel. Serve-only. */
|
|
19
|
+
export declare function createWhatsappPanelPlugin(opts?: WhatsappPanelOptions): Plugin;
|
|
20
|
+
/** Injects the Webchat channel routing panel. Serve-only. */
|
|
21
|
+
export declare function createWebchatPanelPlugin(opts?: ChannelCredentials): Plugin;
|
|
22
|
+
/** Injects the log-viewer split layout. Serve-only. No per-panel configuration needed. */
|
|
23
|
+
export declare function createLogViewerPlugin(): Plugin;
|
|
24
|
+
/** Convenience wrapper — creates all requested panel plugins in one call. */
|
|
25
|
+
export declare function createDevPanelsPlugin(opts: DevPanelsOptions): Plugin[];
|
|
@@ -0,0 +1,183 @@
|
|
|
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 serve_mode_exports = {};
|
|
20
|
+
__export(serve_mode_exports, {
|
|
21
|
+
createDevPanelsPlugin: () => createDevPanelsPlugin,
|
|
22
|
+
createLogViewerPlugin: () => createLogViewerPlugin,
|
|
23
|
+
createWebchatPanelPlugin: () => createWebchatPanelPlugin,
|
|
24
|
+
createWhatsappPanelPlugin: () => createWhatsappPanelPlugin
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(serve_mode_exports);
|
|
27
|
+
var import_child_process = require("child_process");
|
|
28
|
+
var import_fs = require("fs");
|
|
29
|
+
var import_path = require("path");
|
|
30
|
+
function resolveServeModePaths() {
|
|
31
|
+
const root = (0, import_path.resolve)(__dirname, "../../../serve-mode");
|
|
32
|
+
if ((0, import_fs.existsSync)((0, import_path.join)(root, "vite.config.ts"))) {
|
|
33
|
+
return { root, bundle: (0, import_path.join)(root, "dist/serve-mode.js"), canBuild: true };
|
|
34
|
+
}
|
|
35
|
+
const bundle = (0, import_path.join)(root, "serve-mode.js");
|
|
36
|
+
return { root: (0, import_path.dirname)(bundle), bundle, canBuild: false };
|
|
37
|
+
}
|
|
38
|
+
const PATHS = resolveServeModePaths();
|
|
39
|
+
const BUNDLE_ROUTE = "/__serve-mode/bundle.js";
|
|
40
|
+
const BUNDLE_SCRIPT_MARKER = "data-botonic-serve-mode";
|
|
41
|
+
const FACTORY_PATH = __filename;
|
|
42
|
+
async function ensureBundleBuilt() {
|
|
43
|
+
if (!PATHS.canBuild) return;
|
|
44
|
+
if ((0, import_fs.existsSync)(PATHS.bundle)) {
|
|
45
|
+
const bundleMtime = (0, import_fs.statSync)(PATHS.bundle).mtimeMs;
|
|
46
|
+
const viteConfigPath = (0, import_path.join)(PATHS.root, "vite.config.ts");
|
|
47
|
+
const configMtime = (0, import_fs.existsSync)(viteConfigPath) ? (0, import_fs.statSync)(viteConfigPath).mtimeMs : 0;
|
|
48
|
+
const factoryMtime = (0, import_fs.existsSync)(FACTORY_PATH) ? (0, import_fs.statSync)(FACTORY_PATH).mtimeMs : 0;
|
|
49
|
+
const srcDir = (0, import_path.join)(PATHS.root, "src");
|
|
50
|
+
if (configMtime <= bundleMtime && factoryMtime <= bundleMtime && !isSrcNewerThan(srcDir, bundleMtime))
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
(0, import_child_process.execSync)(
|
|
55
|
+
`node_modules/.bin/vite build --config ${PATHS.root}/vite.config.ts --mode production`,
|
|
56
|
+
{
|
|
57
|
+
cwd: process.cwd(),
|
|
58
|
+
stdio: "inherit",
|
|
59
|
+
env: { ...process.env, NODE_ENV: "production" }
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.warn(
|
|
64
|
+
"[botonic-serve-mode] Failed to build panel bundle \u2014 panels will not be injected.",
|
|
65
|
+
e
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function isSrcNewerThan(dir, bundleMtime) {
|
|
70
|
+
try {
|
|
71
|
+
const { readdirSync } = require("fs");
|
|
72
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
73
|
+
const full = (0, import_path.resolve)(dir, entry.name);
|
|
74
|
+
if (entry.isDirectory()) {
|
|
75
|
+
if (isSrcNewerThan(full, bundleMtime)) return true;
|
|
76
|
+
} else if ((0, import_fs.statSync)(full).mtimeMs > bundleMtime) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
function registerBundleMiddleware(server) {
|
|
86
|
+
const stack = server.middlewares.stack;
|
|
87
|
+
const already = stack.some(
|
|
88
|
+
(layer) => typeof layer.route === "string" && layer.route === BUNDLE_ROUTE
|
|
89
|
+
);
|
|
90
|
+
if (already) return;
|
|
91
|
+
server.middlewares.use(BUNDLE_ROUTE, (_req, res) => {
|
|
92
|
+
if (!(0, import_fs.existsSync)(PATHS.bundle)) {
|
|
93
|
+
res.statusCode = 404;
|
|
94
|
+
res.end("Dev panels bundle not found");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
98
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
99
|
+
res.end((0, import_fs.readFileSync)(PATHS.bundle));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function injectConfigScript(html, configJson) {
|
|
103
|
+
const configScript = `<script>window.__BOTONIC_DEV__=Object.assign(window.__BOTONIC_DEV__||{},${configJson});</script>`;
|
|
104
|
+
return html.replace("</body>", `${configScript}</body>`);
|
|
105
|
+
}
|
|
106
|
+
function injectBundleScript(html) {
|
|
107
|
+
if (html.includes(BUNDLE_SCRIPT_MARKER)) return html;
|
|
108
|
+
const bundleScript = `<script ${BUNDLE_SCRIPT_MARKER} defer src="${BUNDLE_ROUTE}"></script>`;
|
|
109
|
+
return html.replace("</body>", `${bundleScript}</body>`);
|
|
110
|
+
}
|
|
111
|
+
function credentialsFromEnv(overrides = {}) {
|
|
112
|
+
return {
|
|
113
|
+
botId: overrides.botId ?? process.env.VITE_DEV_BOT_ID ?? "",
|
|
114
|
+
apiUrl: overrides.apiUrl ?? process.env.VITE_DEV_API_URL ?? "https://api.hubtype.com",
|
|
115
|
+
tunnelUrl: overrides.tunnelUrl ?? process.env.VITE_DEV_SESSION_URL ?? "",
|
|
116
|
+
lambdaFn: overrides.lambdaFn ?? process.env.VITE_DEV_LAMBDA_FUNCTION_NAME ?? "BotonicV2LocalLambda",
|
|
117
|
+
accessToken: overrides.accessToken ?? process.env.VITE_DEV_ACCESS_TOKEN ?? "",
|
|
118
|
+
refreshToken: overrides.refreshToken ?? process.env.VITE_DEV_REFRESH_TOKEN ?? "",
|
|
119
|
+
clientId: overrides.clientId ?? process.env.VITE_DEV_CLIENT_ID ?? ""
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function createWhatsappPanelPlugin(opts = {}) {
|
|
123
|
+
return {
|
|
124
|
+
name: "botonic-serve-mode-whatsapp",
|
|
125
|
+
apply: "serve",
|
|
126
|
+
async configureServer(server) {
|
|
127
|
+
await ensureBundleBuilt();
|
|
128
|
+
registerBundleMiddleware(server);
|
|
129
|
+
},
|
|
130
|
+
transformIndexHtml(html) {
|
|
131
|
+
if (!process.env["BOT_HAS_WHATSAPP"]) return html;
|
|
132
|
+
const config = JSON.stringify({
|
|
133
|
+
whatsapp: {
|
|
134
|
+
...credentialsFromEnv(opts),
|
|
135
|
+
registeredPhone: opts.registeredPhone ?? ""
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return injectBundleScript(injectConfigScript(html, config));
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function createWebchatPanelPlugin(opts = {}) {
|
|
143
|
+
return {
|
|
144
|
+
name: "botonic-serve-mode-webchat",
|
|
145
|
+
apply: "serve",
|
|
146
|
+
async configureServer(server) {
|
|
147
|
+
await ensureBundleBuilt();
|
|
148
|
+
registerBundleMiddleware(server);
|
|
149
|
+
},
|
|
150
|
+
transformIndexHtml(html) {
|
|
151
|
+
const config = JSON.stringify({ webchat: credentialsFromEnv(opts) });
|
|
152
|
+
return injectBundleScript(injectConfigScript(html, config));
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function createLogViewerPlugin() {
|
|
157
|
+
return {
|
|
158
|
+
name: "botonic-serve-mode-log-viewer",
|
|
159
|
+
apply: "serve",
|
|
160
|
+
async configureServer(server) {
|
|
161
|
+
await ensureBundleBuilt();
|
|
162
|
+
registerBundleMiddleware(server);
|
|
163
|
+
},
|
|
164
|
+
transformIndexHtml(html) {
|
|
165
|
+
const config = JSON.stringify({ logViewer: true });
|
|
166
|
+
return injectBundleScript(injectConfigScript(html, config));
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function createDevPanelsPlugin(opts) {
|
|
171
|
+
const plugins = [];
|
|
172
|
+
if (opts.panels.includes("whatsapp"))
|
|
173
|
+
plugins.push(createWhatsappPanelPlugin(opts));
|
|
174
|
+
if (opts.panels.includes("webchat")) plugins.push(createWebchatPanelPlugin());
|
|
175
|
+
return plugins;
|
|
176
|
+
}
|
|
177
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
178
|
+
0 && (module.exports = {
|
|
179
|
+
createDevPanelsPlugin,
|
|
180
|
+
createLogViewerPlugin,
|
|
181
|
+
createWebchatPanelPlugin,
|
|
182
|
+
createWhatsappPanelPlugin
|
|
183
|
+
});
|