lucid-package 0.0.109 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-package",
3
- "version": "0.0.109",
3
+ "version": "0.0.110",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -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 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
- // When doing a watch build, the user must manually first run "ng serve".
33
- // Then, this script will update the html file to prefix http://localhost:4200/ to all the resource URLs
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
- (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: 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
- (target) =>
51
- // Executed by WebpackShellPluginNext from within each _extension's_ directory.
52
- `mkdir -p ../../public/${target.name} &&` +
53
- `cd ${target.name} && ` +
54
- // `npx ng build` usually works, but this is more reliable when used with build tools such as bazel
55
- `./node_modules/.bin/ng build && ` +
56
- `cp -r dist/${target.name}/* ../../../public/${target.name}`,
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,