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,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,
|