@pulse-editor/cli 0.1.1-beta.35 → 0.1.1-beta.37
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import webpack from
|
|
2
|
-
export declare function webpackCompile(mode:
|
|
1
|
+
import webpack from "webpack";
|
|
2
|
+
export declare function webpackCompile(mode: "development" | "production" | "preview", buildTarget?: "client" | "server", isWatchMode?: boolean): Promise<void | webpack.MultiCompiler>;
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import webpack from
|
|
2
|
-
import {
|
|
1
|
+
import webpack from "webpack";
|
|
2
|
+
import { generateTempTsConfig } from "./configs/utils.js";
|
|
3
|
+
import { createWebpackConfig } from "./webpack-config.js";
|
|
3
4
|
export async function webpackCompile(mode, buildTarget, isWatchMode = false) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
generateTempTsConfig();
|
|
6
|
+
const configs = await createWebpackConfig(mode === "preview", buildTarget ?? "both", mode === "development"
|
|
7
|
+
? "development"
|
|
8
|
+
: mode === "preview"
|
|
9
|
+
? "development"
|
|
10
|
+
: "production");
|
|
9
11
|
const compiler = webpack(configs);
|
|
10
12
|
if (isWatchMode) {
|
|
11
13
|
compiler.watch({}, (err, stats) => {
|
|
12
14
|
if (err) {
|
|
13
|
-
console.error(
|
|
15
|
+
console.error("❌ Webpack build failed", err);
|
|
14
16
|
return;
|
|
15
17
|
}
|
|
16
18
|
});
|
|
17
19
|
return compiler;
|
|
18
20
|
}
|
|
19
21
|
return new Promise((resolve, reject) => {
|
|
20
|
-
compiler.run(err => {
|
|
22
|
+
compiler.run((err) => {
|
|
21
23
|
if (err) {
|
|
22
24
|
reject(err);
|
|
23
25
|
return;
|
|
@@ -20,7 +20,7 @@ class MFServerPlugin {
|
|
|
20
20
|
let isFirstRun = true;
|
|
21
21
|
// Before build starts
|
|
22
22
|
compiler.hooks.watchRun.tap("ReloadMessagePlugin", async (compilation) => {
|
|
23
|
-
this.
|
|
23
|
+
this.cleanServerDist();
|
|
24
24
|
if (!isFirstRun) {
|
|
25
25
|
console.log(`[Server] 🔄 Reloading app...`);
|
|
26
26
|
const isServerFunctionChange = compilation.modifiedFiles
|
|
@@ -69,7 +69,6 @@ class MFServerPlugin {
|
|
|
69
69
|
console.log(`[Server] ❌ Failed to build server.`);
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
this.cleanDist();
|
|
73
72
|
try {
|
|
74
73
|
await this.compileServerFunctions(compiler);
|
|
75
74
|
this.compileAppActionSkills();
|
|
@@ -83,7 +82,7 @@ class MFServerPlugin {
|
|
|
83
82
|
});
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
|
-
|
|
85
|
+
cleanServerDist() {
|
|
87
86
|
// Remove existing entry points
|
|
88
87
|
try {
|
|
89
88
|
fs.rmSync("dist/server", { recursive: true, force: true });
|
|
@@ -102,31 +101,6 @@ class MFServerPlugin {
|
|
|
102
101
|
* @param compiler
|
|
103
102
|
*/
|
|
104
103
|
async compileServerFunctions(compiler) {
|
|
105
|
-
// Generate tsconfig for server functions
|
|
106
|
-
function generateTempTsConfig() {
|
|
107
|
-
const tempTsConfigPath = path.join(process.cwd(), "node_modules/.pulse/tsconfig.server.json");
|
|
108
|
-
const tsConfig = {
|
|
109
|
-
compilerOptions: {
|
|
110
|
-
target: "ES2020",
|
|
111
|
-
module: "esnext",
|
|
112
|
-
moduleResolution: "bundler",
|
|
113
|
-
strict: true,
|
|
114
|
-
declaration: true,
|
|
115
|
-
outDir: path.join(process.cwd(), "dist"),
|
|
116
|
-
},
|
|
117
|
-
include: [
|
|
118
|
-
path.join(process.cwd(), "src/server-function/**/*"),
|
|
119
|
-
path.join(process.cwd(), "pulse.config.ts"),
|
|
120
|
-
path.join(process.cwd(), "global.d.ts"),
|
|
121
|
-
],
|
|
122
|
-
exclude: [
|
|
123
|
-
path.join(process.cwd(), "node_modules"),
|
|
124
|
-
path.join(process.cwd(), "dist"),
|
|
125
|
-
],
|
|
126
|
-
};
|
|
127
|
-
fs.writeFileSync(tempTsConfigPath, JSON.stringify(tsConfig, null, 2));
|
|
128
|
-
}
|
|
129
|
-
generateTempTsConfig();
|
|
130
104
|
// Run a new webpack compilation to pick up new server functions
|
|
131
105
|
const options = {
|
|
132
106
|
...compiler.options,
|
|
@@ -231,46 +205,41 @@ ${Object.entries(funcs)
|
|
|
231
205
|
const allJSDocs = sourceFile.getDescendantsOfKind(SyntaxKind.JSDoc);
|
|
232
206
|
const typeDefs = this.parseTypeDefs(allJSDocs);
|
|
233
207
|
/* Extract parameter descriptions from JSDoc */
|
|
234
|
-
// Check if the function's first param is an object
|
|
235
|
-
if (funcDecl.getParameters().length !== 1) {
|
|
236
|
-
throw new Error(`[Action Registration] Function ${funcName} should have exactly one parameter which is an object. Skipping...`);
|
|
237
|
-
}
|
|
238
|
-
else if (!funcDecl.getParameters()[0]?.getType().isObject()) {
|
|
239
|
-
throw new Error(`[Action Registration] Function ${funcName}'s parameter should be an object. Skipping...`);
|
|
240
|
-
}
|
|
241
208
|
const funcParam = funcDecl.getParameters()[0];
|
|
242
209
|
const params = {};
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
210
|
+
if (funcParam) {
|
|
211
|
+
/**
|
|
212
|
+
* Extract default values from the destructured parameter
|
|
213
|
+
* (ObjectBindingPattern → BindingElement initializer)
|
|
214
|
+
*/
|
|
215
|
+
const defaults = new Map();
|
|
216
|
+
const nameNode = funcParam.getNameNode();
|
|
217
|
+
if (Node.isObjectBindingPattern(nameNode)) {
|
|
218
|
+
nameNode.getElements().forEach((el) => {
|
|
219
|
+
if (!Node.isBindingElement(el))
|
|
220
|
+
return;
|
|
221
|
+
const name = el.getName();
|
|
222
|
+
const initializer = el.getInitializer()?.getText();
|
|
223
|
+
if (initializer) {
|
|
224
|
+
defaults.set(name, initializer);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
funcParam
|
|
229
|
+
.getType()
|
|
230
|
+
.getProperties()
|
|
231
|
+
.forEach((prop) => {
|
|
232
|
+
const name = prop.getName();
|
|
233
|
+
const inputTypeDef = typeDefs["input"] ?? {};
|
|
234
|
+
const variable = {
|
|
235
|
+
description: inputTypeDef[name]?.description ?? "",
|
|
236
|
+
type: this.getType(inputTypeDef[name]?.type ?? ""),
|
|
237
|
+
optional: prop.isOptional() ? true : undefined,
|
|
238
|
+
defaultValue: defaults.get(name),
|
|
239
|
+
};
|
|
240
|
+
params[name] = variable;
|
|
258
241
|
});
|
|
259
242
|
}
|
|
260
|
-
funcParam
|
|
261
|
-
.getType()
|
|
262
|
-
.getProperties()
|
|
263
|
-
.forEach((prop) => {
|
|
264
|
-
const name = prop.getName();
|
|
265
|
-
const inputTypeDef = typeDefs["input"] ?? {};
|
|
266
|
-
const variable = {
|
|
267
|
-
description: inputTypeDef[name]?.description ?? "",
|
|
268
|
-
type: this.getType(inputTypeDef[name]?.type ?? ""),
|
|
269
|
-
optional: prop.isOptional() ? true : undefined,
|
|
270
|
-
defaultValue: defaults.get(name),
|
|
271
|
-
};
|
|
272
|
-
params[name] = variable;
|
|
273
|
-
});
|
|
274
243
|
/* Extract return type from JSDoc */
|
|
275
244
|
// Check if the return type is an object
|
|
276
245
|
if (!funcDecl.getReturnType().isObject()) {
|
|
@@ -347,6 +316,8 @@ ${Object.entries(funcs)
|
|
|
347
316
|
return "object";
|
|
348
317
|
if (text.endsWith("[]"))
|
|
349
318
|
return [this.getType(text.slice(0, -2))];
|
|
319
|
+
if (text.length === 0)
|
|
320
|
+
return "undefined";
|
|
350
321
|
console.warn(`[Type Warning] Unrecognized type "${text}". Consider adding explicit types in your action's JSDoc comments for better type safety and documentation.`);
|
|
351
322
|
return text;
|
|
352
323
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { existsSync } from "fs";
|
|
2
|
+
import { existsSync, writeFileSync } from "fs";
|
|
3
3
|
import fs from "fs/promises";
|
|
4
4
|
import { globSync } from "glob";
|
|
5
5
|
import { networkInterfaces } from "os";
|
|
@@ -116,3 +116,30 @@ export function discoverAppSkillActions() {
|
|
|
116
116
|
}, {});
|
|
117
117
|
return entryPoints;
|
|
118
118
|
}
|
|
119
|
+
// Generate tsconfig for server functions
|
|
120
|
+
export function generateTempTsConfig() {
|
|
121
|
+
const tempTsConfigPath = path.join(process.cwd(), "node_modules/.pulse/tsconfig.server.json");
|
|
122
|
+
if (existsSync(tempTsConfigPath)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const tsConfig = {
|
|
126
|
+
compilerOptions: {
|
|
127
|
+
target: "ES2020",
|
|
128
|
+
module: "esnext",
|
|
129
|
+
moduleResolution: "bundler",
|
|
130
|
+
strict: true,
|
|
131
|
+
declaration: true,
|
|
132
|
+
outDir: path.join(process.cwd(), "dist"),
|
|
133
|
+
},
|
|
134
|
+
include: [
|
|
135
|
+
path.join(process.cwd(), "src/server-function/**/*"),
|
|
136
|
+
path.join(process.cwd(), "pulse.config.ts"),
|
|
137
|
+
path.join(process.cwd(), "global.d.ts"),
|
|
138
|
+
],
|
|
139
|
+
exclude: [
|
|
140
|
+
path.join(process.cwd(), "node_modules"),
|
|
141
|
+
path.join(process.cwd(), "dist"),
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
writeFileSync(tempTsConfigPath, JSON.stringify(tsConfig, null, 2));
|
|
145
|
+
}
|