lucid-package 0.0.108 → 0.0.110
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/package.json
CHANGED
package/src/editorextension.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAllExtensionNames = exports.debugEditorExtension = exports.watchEditorExtension = exports.updateExtensionSDK = exports.buildEditorExtension = exports.createEditorExtension = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
4
|
const express = require("express");
|
|
6
5
|
const oldFs = require("fs");
|
|
7
6
|
const fs = require("fs/promises");
|
|
@@ -114,7 +113,6 @@ exports.watchEditorExtension = watchEditorExtension;
|
|
|
114
113
|
async function debugEditorExtension(extensionNames, isInternal, quiet = false, pickAnyPort = false, watchIgnoreNodeModules = false) {
|
|
115
114
|
const port = 9900;
|
|
116
115
|
const watchers = await Promise.all(extensionNames.map(async (name) => watchEditorExtension(name, isInternal, quiet, watchIgnoreNodeModules)));
|
|
117
|
-
startCustomUIServers(extensionNames);
|
|
118
116
|
const app = express();
|
|
119
117
|
const server = listen(app, port, pickAnyPort);
|
|
120
118
|
setupWebSockets(server);
|
|
@@ -343,45 +341,3 @@ async function getAllExtensionNames() {
|
|
|
343
341
|
}
|
|
344
342
|
}
|
|
345
343
|
exports.getAllExtensionNames = getAllExtensionNames;
|
|
346
|
-
async function startCustomUIServers(extensionNames) {
|
|
347
|
-
for (let extensionName of extensionNames) {
|
|
348
|
-
const extensionCodePath = path.resolve(path.join('editorextensions', await getExtensionCodeDirectoryName(extensionName)));
|
|
349
|
-
const potentialCustomUIServer = (await fs.readdir(extensionCodePath, { withFileTypes: true }))
|
|
350
|
-
.filter((dirent) => dirent.isDirectory())
|
|
351
|
-
.map((dirent) => path.join(extensionCodePath, dirent.name));
|
|
352
|
-
for (let potentialPaths of potentialCustomUIServer) {
|
|
353
|
-
runNpmStartIfExists(potentialPaths);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
async function runNpmStartIfExists(directoryPath) {
|
|
358
|
-
try {
|
|
359
|
-
// Read the package.json file
|
|
360
|
-
const packageJsonPath = path.join(directoryPath, 'package.json');
|
|
361
|
-
if (oldFs.existsSync(packageJsonPath)) {
|
|
362
|
-
const packageJson = await fs.readFile(packageJsonPath, 'utf-8');
|
|
363
|
-
const packageData = JSON.parse(packageJson);
|
|
364
|
-
// Check if package.json has "scripts" object and it contains "start"
|
|
365
|
-
if (packageData && packageData.scripts && packageData.scripts.start) {
|
|
366
|
-
console.log((0, theme_1.success)(`Found npm start script in ${directoryPath}.`));
|
|
367
|
-
// Execute npm start
|
|
368
|
-
const npmStart = (0, child_process_1.spawn)('npm', ['start'], { cwd: directoryPath, stdio: ['inherit', 'pipe', 'pipe'] });
|
|
369
|
-
npmStart.stdout.on('data', (data) => {
|
|
370
|
-
process.stdout.write(data);
|
|
371
|
-
});
|
|
372
|
-
npmStart.stderr.on('data', (data) => {
|
|
373
|
-
process.stderr.write(data);
|
|
374
|
-
});
|
|
375
|
-
npmStart.on('exit', (code) => {
|
|
376
|
-
console.log(`npm start process exited with code ${code}`);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
console.log(`No npm start script found in ${directoryPath}.`);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
catch (error) {
|
|
385
|
-
console.error(error(`Error occurred: ${error.message}`));
|
|
386
|
-
}
|
|
387
|
-
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const child_process = require('child_process');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const process = require('process');
|
|
4
|
+
|
|
2
5
|
const WebpackShellPluginNext = require('webpack-shell-plugin-next');
|
|
3
6
|
|
|
4
7
|
const angularTargets = [{name: '<<dynamicname>>', port: 4200}];
|
|
@@ -29,32 +32,48 @@ module.exports = {
|
|
|
29
32
|
plugins: [
|
|
30
33
|
new WebpackShellPluginNext({
|
|
31
34
|
// Run during execution of `npx lucid-package@latest test-editor-extension`.
|
|
32
|
-
//
|
|
33
|
-
//
|
|
35
|
+
// Beforehand, the user must manually first start up the Angular server
|
|
36
|
+
// from within the Angular app's directory and in another console, and leave it running.
|
|
34
37
|
onWatchRun: {
|
|
35
|
-
scripts: angularTargets.map(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
scripts: angularTargets.map((target) => async () => {
|
|
39
|
+
// Executed by WebpackShellPluginNext, from within the package's root level directory.
|
|
40
|
+
fs.mkdirSync(`public/${target.name}`, {recursive: true});
|
|
41
|
+
|
|
42
|
+
const angularServerURL = `http://localhost:${target.port}`;
|
|
43
|
+
const angularAppResponse = await fetch(angularServerURL).catch((error) => {
|
|
44
|
+
console.error(
|
|
45
|
+
`Extension failed to load the Angular app. Make sure the Angular server is running on ${angularServerURL}.`,
|
|
46
|
+
);
|
|
47
|
+
throw error;
|
|
48
|
+
});
|
|
49
|
+
const angularAppContentHTML = await angularAppResponse.text();
|
|
50
|
+
|
|
51
|
+
// Enable links to other Angular assets, even when served by the extension,
|
|
52
|
+
// by having those assets' links explicitly point to the Angular dev server
|
|
53
|
+
const angularAppContentHTMLReplaced = angularAppContentHTML.replaceAll(
|
|
54
|
+
/(src|href)="\//gi,
|
|
55
|
+
`$1="http://localhost:${target.port}/`,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Enable the extension to serve a copy of the Angular app
|
|
59
|
+
fs.writeFileSync(`public/${target.name}/index.html`, angularAppContentHTMLReplaced);
|
|
60
|
+
}),
|
|
43
61
|
blocking: true,
|
|
44
62
|
},
|
|
45
63
|
// Run during execution of `npx lucid-package@latest bundle`.
|
|
46
|
-
// When doing a full build, this script will automatically run "ng build"
|
|
47
|
-
// and then copy all the assets to the root level public folder
|
|
48
64
|
onBeforeNormalRun: {
|
|
49
|
-
scripts: angularTargets.map(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
scripts: angularTargets.map((target) => () => {
|
|
66
|
+
// Executed by WebpackShellPluginNext from within each _extension's_ directory.
|
|
67
|
+
fs.mkdirSync(`../../public/${target.name}`, {recursive: true});
|
|
68
|
+
|
|
69
|
+
process.chdir(`${target.name}`);
|
|
70
|
+
// `npx ng build` usually works. But directly pathing to the installed `ng` is more reliable,
|
|
71
|
+
// when used with build tools such as Bazel, or when multiple installations of `ng` may exist
|
|
72
|
+
child_process.execSync('npx -- ./node_modules/@angular/cli build', {stdio: 'inherit'});
|
|
73
|
+
|
|
74
|
+
// Add Angular assets to the extension's bundle
|
|
75
|
+
fs.cpSync(`dist/${target.name}/*`, `../../../public/${target.name}`, {recursive: true});
|
|
76
|
+
}),
|
|
58
77
|
blocking: true,
|
|
59
78
|
swallowError: false,
|
|
60
79
|
safe: true,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const child_process = require('child_process');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const process = require('process');
|
|
4
|
+
|
|
2
5
|
const WebpackShellPluginNext = require('webpack-shell-plugin-next');
|
|
3
6
|
|
|
4
7
|
const reactTargets = [{name: '<<dynamicname>>', port: 3000}];
|
|
@@ -29,32 +32,52 @@ module.exports = {
|
|
|
29
32
|
plugins: [
|
|
30
33
|
new WebpackShellPluginNext({
|
|
31
34
|
// Run during execution of `npx lucid-package@latest test-editor-extension`.
|
|
32
|
-
//
|
|
33
|
-
//
|
|
35
|
+
// Beforehand, the user must manually first run `npx react-scripts start`,
|
|
36
|
+
// from within the React app's directory and in another console, and leave it running.
|
|
34
37
|
onWatchRun: {
|
|
35
|
-
scripts: reactTargets.map(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
scripts: reactTargets.map((target) => async () => {
|
|
39
|
+
// Executed by WebpackShellPluginNext, from within the package's root level directory.
|
|
40
|
+
fs.mkdirSync(`public/${target.name}`, {recursive: true});
|
|
41
|
+
|
|
42
|
+
const reactServerURL = `http://localhost:${target.port}`;
|
|
43
|
+
const reactAppResponse = await fetch(reactServerURL).catch((error) => {
|
|
44
|
+
console.error(
|
|
45
|
+
`Extension failed to load the React app. Make sure the React server is running on ${reactServerURL}.`,
|
|
46
|
+
);
|
|
47
|
+
throw error;
|
|
48
|
+
});
|
|
49
|
+
const reactAppContentHTML = await reactAppResponse.text();
|
|
50
|
+
|
|
51
|
+
// Enable links to other React assets, even when served by the extension,
|
|
52
|
+
// by having those assets' links explicitly point to the React dev server
|
|
53
|
+
const reactAppContentHTMLReplaced = reactAppContentHTML.replaceAll(
|
|
54
|
+
/(src|href)="\//gi,
|
|
55
|
+
`$1="http://localhost:${target.port}/`,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Enable the extension to serve a copy of the React app
|
|
59
|
+
fs.writeFileSync(`public/${target.name}/index.html`, reactAppContentHTMLReplaced);
|
|
60
|
+
}),
|
|
43
61
|
blocking: true,
|
|
44
62
|
},
|
|
45
63
|
// Run during execution of `npx lucid-package@latest bundle`.
|
|
46
|
-
// When doing a full build, this script will automatically run "npm run build"
|
|
47
|
-
// and then copy all the assets to the root level public folder
|
|
48
64
|
onBeforeNormalRun: {
|
|
49
|
-
scripts: reactTargets.map(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
scripts: reactTargets.map((target) => () => {
|
|
66
|
+
// Executed by WebpackShellPluginNext from within each _extension's_ directory.
|
|
67
|
+
fs.mkdirSync(`../../public/${target.name}`, {recursive: true});
|
|
68
|
+
|
|
69
|
+
process.chdir(`${target.name}`);
|
|
70
|
+
child_process.execSync('npx react-scripts build', {stdio: 'inherit'});
|
|
71
|
+
|
|
72
|
+
// In the React app's bundled HTML, enable links to other React assets,
|
|
73
|
+
// by having those links explicitly point to the extension's bundle
|
|
74
|
+
const content = fs.readFileSync('build/index.html', 'utf8');
|
|
75
|
+
const newContent = content.replaceAll(/(src|href)="\//gi, '$1="');
|
|
76
|
+
fs.writeFileSync('build/index.html', newContent);
|
|
77
|
+
|
|
78
|
+
// Add React assets to the extension's bundle
|
|
79
|
+
fs.cpSync('build', `../../../public/${target.name}`, {recursive: true});
|
|
80
|
+
}),
|
|
58
81
|
blocking: true,
|
|
59
82
|
},
|
|
60
83
|
}),
|