lucid-package 0.0.109 → 0.0.111
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
|
@@ -7,21 +7,21 @@ const editorextension_1 = require("./editorextension");
|
|
|
7
7
|
const installationutil_1 = require("./installationutil");
|
|
8
8
|
const package_1 = require("./package");
|
|
9
9
|
const theme_1 = require("./theme");
|
|
10
|
+
const ANGULAR_PROJECT_NAME = 'angular-app';
|
|
10
11
|
async function createAngularEditorExtension(name, isInternal, skipSDKDependency) {
|
|
11
12
|
await (0, editorextension_1.createEditorExtension)(name, isInternal, skipSDKDependency, path.join('angular', 'skeleton'), [
|
|
12
13
|
'webpack-shell-plugin-next',
|
|
13
14
|
]);
|
|
14
|
-
const
|
|
15
|
-
const angularEditorExtensionTargetFolder = path.join(process.cwd(), angularProjectName);
|
|
15
|
+
const angularEditorExtensionTargetFolder = path.join(process.cwd(), ANGULAR_PROJECT_NAME);
|
|
16
16
|
console.log((0, theme_1.success)('Creating Angular project in ' + angularEditorExtensionTargetFolder));
|
|
17
|
-
(0, installationutil_1.installAngularProject)(
|
|
18
|
-
const webpackConfig = (await fs.readFile('webpack.config.js', 'utf8')).replace('<<dynamicname>>',
|
|
19
|
-
const extensionTemplateCode = (await fs.readFile(path.join('src', 'extension.ts'), 'utf8')).replace('<<dynamicname>>',
|
|
17
|
+
(0, installationutil_1.installAngularProject)(ANGULAR_PROJECT_NAME);
|
|
18
|
+
const webpackConfig = (await fs.readFile('webpack.config.js', 'utf8')).replace('<<dynamicname>>', ANGULAR_PROJECT_NAME);
|
|
19
|
+
const extensionTemplateCode = (await fs.readFile(path.join('src', 'extension.ts'), 'utf8')).replace('<<dynamicname>>', ANGULAR_PROJECT_NAME);
|
|
20
20
|
await fs.writeFile(path.join(process.cwd(), 'webpack.config.js'), webpackConfig);
|
|
21
21
|
await fs.writeFile(path.join('src', 'extension.ts'), extensionTemplateCode);
|
|
22
|
-
process.chdir(path.join(
|
|
22
|
+
process.chdir(path.join(ANGULAR_PROJECT_NAME));
|
|
23
23
|
const packageJson = await (0, package_1.readJson)('package.json');
|
|
24
|
-
packageJson.name =
|
|
24
|
+
packageJson.name = ANGULAR_PROJECT_NAME;
|
|
25
25
|
await fs.writeFile('package.json', JSON.stringify(packageJson, null, 4));
|
|
26
26
|
console.log('Installing Angular dependencies');
|
|
27
27
|
(0, installationutil_1.installDependenciesIfNeeded)(isInternal, skipSDKDependency);
|
|
@@ -7,6 +7,7 @@ const editorextension_1 = require("./editorextension");
|
|
|
7
7
|
const installationutil_1 = require("./installationutil");
|
|
8
8
|
const package_1 = require("./package");
|
|
9
9
|
const theme_1 = require("./theme");
|
|
10
|
+
const REACT_PROJECT_NAME = 'react-app';
|
|
10
11
|
async function createReactEditorExtension(name, flavor, isInternal, skipSDKDependency) {
|
|
11
12
|
await (0, editorextension_1.createEditorExtension)(name, isInternal, skipSDKDependency, path.join('react', 'skeleton'), [
|
|
12
13
|
'webpack-shell-plugin-next',
|
|
@@ -22,11 +23,10 @@ async function createReactEditorExtension(name, flavor, isInternal, skipSDKDepen
|
|
|
22
23
|
console.log((0, theme_1.error)('Unexpected flavor type'));
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
|
-
const
|
|
26
|
-
const reactEditorExtensionTargetFolder = path.join(process.cwd(), reactProjectName);
|
|
26
|
+
const reactEditorExtensionTargetFolder = path.join(process.cwd(), REACT_PROJECT_NAME);
|
|
27
27
|
const publicTargetFolder = path.join(process.cwd(), '..', '..', 'public');
|
|
28
28
|
console.log((0, theme_1.success)('Creating React project in ' + reactEditorExtensionTargetFolder));
|
|
29
|
-
(0, installationutil_1.installReactProject)(
|
|
29
|
+
(0, installationutil_1.installReactProject)(REACT_PROJECT_NAME, typescript);
|
|
30
30
|
await fs.mkdir(path.join(publicTargetFolder, name));
|
|
31
31
|
await copyFilesTo(path.join(reactEditorExtensionTargetFolder, 'public'), path.join(publicTargetFolder, name), [
|
|
32
32
|
'.png',
|
|
@@ -38,13 +38,13 @@ async function createReactEditorExtension(name, flavor, isInternal, skipSDKDepen
|
|
|
38
38
|
'.svg',
|
|
39
39
|
'.ico',
|
|
40
40
|
]);
|
|
41
|
-
const webpackConfig = (await fs.readFile('webpack.config.js', 'utf8')).replace('<<dynamicname>>',
|
|
42
|
-
const extensionTemplateCode = (await fs.readFile(path.join('src', 'extension.ts'), 'utf8')).replace('<<dynamicname>>',
|
|
41
|
+
const webpackConfig = (await fs.readFile('webpack.config.js', 'utf8')).replace('<<dynamicname>>', REACT_PROJECT_NAME);
|
|
42
|
+
const extensionTemplateCode = (await fs.readFile(path.join('src', 'extension.ts'), 'utf8')).replace('<<dynamicname>>', REACT_PROJECT_NAME);
|
|
43
43
|
await fs.writeFile(path.join(process.cwd(), 'webpack.config.js'), webpackConfig);
|
|
44
44
|
await fs.writeFile(path.join('src', 'extension.ts'), extensionTemplateCode);
|
|
45
|
-
process.chdir(path.join(
|
|
45
|
+
process.chdir(path.join(REACT_PROJECT_NAME));
|
|
46
46
|
const packageJson = await (0, package_1.readJson)('package.json');
|
|
47
|
-
packageJson.name =
|
|
47
|
+
packageJson.name = REACT_PROJECT_NAME;
|
|
48
48
|
await fs.writeFile('package.json', JSON.stringify(packageJson, null, 4));
|
|
49
49
|
/*
|
|
50
50
|
Hacky solution to change react template from create-react-app; susceptible to changes in create-react-app;
|
|
@@ -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,
|