lucid-package 0.0.107 → 0.0.109

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-package",
3
- "version": "0.0.107",
3
+ "version": "0.0.109",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -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
- }
@@ -37,7 +37,7 @@ module.exports = {
37
37
  // Executed by WebpackShellPluginNext, from within the package's root level directory.
38
38
  `mkdir -p public/${target.name} &&` +
39
39
  `curl http://localhost:${target.port} | ` +
40
- `sed -E "s/(src|href)=\\"/\\\\1=\\"http:\\/\\/localhost:${target.port}\\//gi" > ` +
40
+ `sed -E "s/(src|href)=\\"\\//\\1=\\"http:\\/\\/localhost:${target.port}\\//gi" > ` +
41
41
  `public/${target.name}/index.html`,
42
42
  ),
43
43
  blocking: true,
@@ -1,4 +1,7 @@
1
- const path = require('path');
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
- // When doing a watch build, the user must manually first run "npm start".
33
- // Then, this script will update the html file to prefix http://localhost:3000/ to all the resource URLs
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
- (target) =>
37
- // Executed by WebpackShellPluginNext, from within the package's root level directory.
38
- `mkdir -p public/${target.name} &&` +
39
- `curl http://localhost:${target.port} | ` +
40
- `sed -E "s/(src|href)=\\"/\\\\1=\\"http:\\/\\/localhost:${target.port}\/gi" > ` +
41
- `public/${target.name}/index.html`,
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
- (target) =>
51
- // Executed by WebpackShellPluginNext from within each _extension's_ directory.
52
- `mkdir -p ../../public/${target.name} &&` +
53
- `cd ${target.name} && ` +
54
- `npm run build && ` +
55
- `sed -i -E "s/(src|href)=\\"\\//\\1=\\"\/gi" build/index.html &&` +
56
- `cp -r build/* ../../../public/${target.name}`,
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
  }),