@pulse-editor/cli 0.1.1-beta.22 → 0.1.1-beta.24
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/dist/components/commands/create.js +3 -1
- package/dist/lib/server/express.js +11 -2
- package/dist/lib/server/preview/backend/load-remote.cjs +28 -18
- package/dist/lib/webpack/webpack.config.js +1 -49
- package/package.json +1 -1
- package/dist/lib/server/preview/backend/index.d.ts +0 -1
- package/dist/lib/server/preview/backend/index.js +0 -23
|
@@ -59,7 +59,9 @@ export default function Create({ cli }) {
|
|
|
59
59
|
if (projectName) {
|
|
60
60
|
// Check if the project already exists
|
|
61
61
|
const projectPath = path.join(process.cwd(), projectName);
|
|
62
|
-
if (fs.existsSync(projectPath)
|
|
62
|
+
if (fs.existsSync(projectPath) &&
|
|
63
|
+
fs.lstatSync(projectPath).isDirectory() &&
|
|
64
|
+
fs.readdirSync(projectPath).length > 0) {
|
|
63
65
|
setErrorMessage(_jsx(Text, { color: "redBright", children: "\u274C A project with same name already exists in current path." }));
|
|
64
66
|
setTimeout(() => {
|
|
65
67
|
exit();
|
|
@@ -65,9 +65,18 @@ app.all(/^\/server-function\/(.*)/, async (req, res) => {
|
|
|
65
65
|
});
|
|
66
66
|
const dir = path.resolve('node_modules/@pulse-editor/cli/dist/lib/server/preview/backend/load-remote.cjs');
|
|
67
67
|
const fileUrl = pathToFileURL(dir).href;
|
|
68
|
-
const {
|
|
68
|
+
const { loadFunc, loadPrice } = await import(fileUrl);
|
|
69
|
+
const price = await loadPrice(func, pulseConfig.id, 'http://localhost:3030', pulseConfig.version);
|
|
70
|
+
if (price) {
|
|
71
|
+
// Make func name and price bold in console
|
|
72
|
+
console.log(`🏃 Running function \x1b[1m${func}\x1b[0m, credits consumed: \x1b[1m${price}\x1b[0m`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
console.log(`🏃 Running function \x1b[1m${func}\x1b[0m.`);
|
|
76
|
+
}
|
|
69
77
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
-
const
|
|
78
|
+
const loadedFunc = await loadFunc(func, pulseConfig.id, 'http://localhost:3030', pulseConfig.version);
|
|
79
|
+
const response = await loadedFunc(request);
|
|
71
80
|
const streamPipeline = promisify(pipeline);
|
|
72
81
|
if (response) {
|
|
73
82
|
// 1️⃣ Set status code
|
|
@@ -1,23 +1,33 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {createInstance} = require('@module-federation/runtime');
|
|
2
2
|
|
|
3
|
-
async function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
],
|
|
14
|
-
});
|
|
3
|
+
async function importRemoteModule(func, appId, origin, version) {
|
|
4
|
+
const instance = createInstance({
|
|
5
|
+
name: 'server_function_runner',
|
|
6
|
+
remotes: [
|
|
7
|
+
{
|
|
8
|
+
name: appId + '_server',
|
|
9
|
+
entry: `${origin}/${appId}/${version}/server/remoteEntry.js`,
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
});
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const loadedModule = await instance.loadRemote(`${appId}_server/${func}`);
|
|
15
|
+
return loadedModule;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function loadFunc(func, appId, origin, version) {
|
|
19
|
+
// here we assign the return value of the init() function, which can be used to do some more complex
|
|
20
|
+
// things with the module federation runtime
|
|
21
|
+
const module = await importRemoteModule(func, appId, origin, version);
|
|
22
|
+
const loadedFunc = module.default;
|
|
23
|
+
|
|
24
|
+
return loadedFunc;
|
|
25
|
+
}
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
async function loadPrice(func, appId, origin, version) {
|
|
28
|
+
const module = await importRemoteModule(func, appId, origin, version);
|
|
29
|
+
const price = module._CREDIT_PER_CALL;
|
|
30
|
+
return price;
|
|
21
31
|
}
|
|
22
32
|
|
|
23
|
-
module.exports = {
|
|
33
|
+
module.exports = {loadFunc, loadPrice};
|
|
@@ -284,54 +284,6 @@ ${Object.entries(funcs)
|
|
|
284
284
|
level: 'warn',
|
|
285
285
|
},
|
|
286
286
|
};
|
|
287
|
-
const previewHostConfig = {
|
|
288
|
-
mode: mode,
|
|
289
|
-
entry: './node_modules/@pulse-editor/cli/dist/lib/server/preview/backend/index.js',
|
|
290
|
-
target: 'async-node',
|
|
291
|
-
output: {
|
|
292
|
-
publicPath: 'auto',
|
|
293
|
-
library: { type: 'commonjs-module' },
|
|
294
|
-
path: path.resolve(projectDirName, 'dist/preview/backend'),
|
|
295
|
-
filename: 'index.cjs',
|
|
296
|
-
},
|
|
297
|
-
resolve: {
|
|
298
|
-
extensions: ['.ts', '.js'],
|
|
299
|
-
},
|
|
300
|
-
module: {
|
|
301
|
-
rules: [
|
|
302
|
-
{
|
|
303
|
-
test: /\.tsx?$/,
|
|
304
|
-
use: [
|
|
305
|
-
{
|
|
306
|
-
loader: 'ts-loader',
|
|
307
|
-
options: {
|
|
308
|
-
transpileOnly: false, // Enables type-checking and .d.ts file emission
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
],
|
|
312
|
-
exclude: [/node_modules/, /dist/],
|
|
313
|
-
},
|
|
314
|
-
],
|
|
315
|
-
},
|
|
316
|
-
plugins: [
|
|
317
|
-
new NodeFederationPlugin({
|
|
318
|
-
remoteType: 'script',
|
|
319
|
-
name: 'preview_host',
|
|
320
|
-
useRuntimePlugin: true,
|
|
321
|
-
exposes: {},
|
|
322
|
-
}, {}),
|
|
323
|
-
],
|
|
324
|
-
stats: {
|
|
325
|
-
all: false,
|
|
326
|
-
errors: true,
|
|
327
|
-
warnings: true,
|
|
328
|
-
logging: 'warn',
|
|
329
|
-
colors: true,
|
|
330
|
-
},
|
|
331
|
-
infrastructureLogging: {
|
|
332
|
-
level: 'warn',
|
|
333
|
-
},
|
|
334
|
-
};
|
|
335
287
|
const mfClientConfig = {
|
|
336
288
|
mode: mode,
|
|
337
289
|
name: 'client',
|
|
@@ -531,7 +483,7 @@ ${Object.entries(funcs)
|
|
|
531
483
|
};
|
|
532
484
|
// #endregion
|
|
533
485
|
if (isPreview) {
|
|
534
|
-
return [previewClientConfig,
|
|
486
|
+
return [previewClientConfig, mfServerConfig];
|
|
535
487
|
}
|
|
536
488
|
else if (buildTarget === 'server') {
|
|
537
489
|
return [mfServerConfig];
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function loadAndCall(func: string, req: Request): Promise<Response>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/* This folder contains temporary code to be moved to a different package in the future. */
|
|
2
|
-
// @ts-expect-error ignore ts error
|
|
3
|
-
import { createInstance } from '@module-federation/runtime';
|
|
4
|
-
import { performReload } from '@module-federation/node/utils';
|
|
5
|
-
import { readConfigFile } from '../../utils.js';
|
|
6
|
-
export async function loadAndCall(func, req) {
|
|
7
|
-
const pulseConfig = await readConfigFile();
|
|
8
|
-
await performReload(true);
|
|
9
|
-
// here we assign the return value of the init() function, which can be used to do some more complex
|
|
10
|
-
// things with the module federation runtime
|
|
11
|
-
const instance = createInstance({
|
|
12
|
-
name: 'preview_host',
|
|
13
|
-
remotes: [
|
|
14
|
-
{
|
|
15
|
-
name: pulseConfig.id + '_server',
|
|
16
|
-
entry: `http://localhost:3030/.server-function/remoteEntry.js`,
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
});
|
|
20
|
-
const loadedFunc = (await instance.loadRemote(`${pulseConfig.id}_server/${func}`)).default;
|
|
21
|
-
const res = await loadedFunc(req);
|
|
22
|
-
return res;
|
|
23
|
-
}
|