lucid-package 0.0.15 → 0.0.20

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/README.md CHANGED
@@ -6,72 +6,7 @@ CLI for creating and managing extension packages for the products of Lucid Softw
6
6
 
7
7
  ## Getting started
8
8
 
9
- ### Step 1: Install `lucid-package` and create a new package
10
-
11
- An extension package is a set of Lucid product extensions that is installable by a Lucid
12
- account admin for use by all of their users. In order to start building an extension, you
13
- need to create a package to contain it.
14
-
15
- In a directory that will contain your extension packages:
16
-
17
- ```
18
- npm install lucid-package
19
- npx lucid-package create my-new-package-name
20
- ```
21
-
22
- ### Step 2: Add an editor extension to your new package
23
-
24
- An editor extension is a piece of custom code that executes inside a Lucid product such
25
- as Lucidchart or Lucidspark. The `lucid-package` CLI provides a quick-start template to
26
- help you get up and running immediately.
27
-
28
- To add a new extension to your package:
29
-
30
- ```
31
- cd my-new-package-name
32
- npx lucid-package create-editor-extension my-extension-name
33
- ```
34
-
35
- ### Step 3: Serve your extension code in debug mode to test it
36
-
37
- You don't need to package, upload, and install your extension in order to run it and
38
- make sure it works. The following command will start `webpack` on your code in `--watch`
39
- mode, and start up a local HTTP server that Lucid products can connect to, to load your
40
- latest code.
41
-
42
- To start the debug server:
43
-
44
- ```
45
- npx lucid-package test-editor-extension my-extension-name
46
- ```
47
-
48
- You can then enable loading of your local plugin in the Developer menu in Lucidchart
49
- by clicking `Load local extension`. The page will refresh and your extension code will run.
50
-
51
- The main entry point to your new editor extension is in `editorextensions/my-extension-name/src/extension.ts`.
52
- Experiment by changing code in that file and refreshing your browser tab to reload it.
53
-
54
- For all published extensions, and by default for this debug server as well, your code
55
- runs in a sandboxed JavaScript VM for security. However, this makes debugging difficult.
56
- If you turn on the `Debug local extensions (no sandbox)` option in the Developer menu,
57
- your code will be run via a scoped `eval`, allowing you to use the standard browser
58
- debugging tools to examine and step through your code.
59
-
60
- We recommend that you do all final validation of your extension with the normal
61
- sandbox enabled, however, as you may have inadvertently used features not allowed in
62
- the sandbox that won't work once you release your extension.
63
-
64
- ### Step 4: Prepare your package for upload
65
-
66
- Once your editor extension works the way you want, you can package it for upload to the
67
- Lucid developer dashboard:
68
-
69
- ```
70
- npx lucid-package package
71
- ```
72
-
73
- This will create the file `package.zip` which is ready for upload to the [Lucid developer
74
- dashboard](https://lucid.app/developer).
9
+ Please see our [Extension API Developer Docs](https://developer.lucid.co/extension-api/#lucid-extension-api).
75
10
 
76
11
  ## License
77
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-package",
3
- "version": "0.0.15",
3
+ "version": "0.0.20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,4 +1,15 @@
1
1
  export declare function createEditorExtension(name: string, isInternalTesting: boolean): Promise<void>;
2
- export declare function buildEditorExtension(name: string): Promise<void>;
2
+ export declare function buildEditorExtension(name: string, quiet?: boolean): Promise<void>;
3
3
  export declare function updateExtensionSDK(name: string): Promise<void>;
4
- export declare function debugEditorExtension(name: string): Promise<void>;
4
+ /**
5
+ * Uses webpack to watch for changes in the editor extension
6
+ * @param name The editor extension name
7
+ * @param quiet If true, will only show errors in output
8
+ */
9
+ export declare function watchEditorExtension(name: string, quiet?: boolean): Promise<void>;
10
+ /**
11
+ * Runs the editor extensions and shape libraries in debug mode, including watching code for changes.
12
+ * @param extensionNames The names of the editor extensions
13
+ * @param quiet If true, will only show errors in output
14
+ */
15
+ export declare function debugEditorExtension(extensionNames: string[], quiet?: boolean): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debugEditorExtension = exports.updateExtensionSDK = exports.buildEditorExtension = exports.createEditorExtension = void 0;
3
+ exports.debugEditorExtension = exports.watchEditorExtension = exports.updateExtensionSDK = exports.buildEditorExtension = exports.createEditorExtension = void 0;
4
4
  const fs = require("fs/promises");
5
5
  const oldFs = require("fs");
6
6
  const filesystemutil_1 = require("./filesystemutil");
@@ -27,7 +27,7 @@ async function createEditorExtension(name, isInternalTesting) {
27
27
  });
28
28
  console.log(`Installing dependencies`);
29
29
  process.chdir('editorextensions/' + name);
30
- console.log(child_process.execSync('npm install').toString());
30
+ console.log(child_process.execSync('npm install --silent').toString());
31
31
  if (isInternalTesting) {
32
32
  console.log('Using symlink for dependency on SDK for internal testing');
33
33
  console.log(child_process
@@ -40,10 +40,10 @@ async function createEditorExtension(name, isInternalTesting) {
40
40
  }
41
41
  }
42
42
  exports.createEditorExtension = createEditorExtension;
43
- async function buildEditorExtension(name) {
43
+ async function buildEditorExtension(name, quiet = false) {
44
44
  process.chdir('editorextensions/' + name);
45
45
  const cli = new WebPackCLI();
46
- await cli.run(['node', 'webpack', '--mode', 'production']);
46
+ await cli.run(['node', 'webpack', '--mode', 'production', ...(quiet ? ['--stats', 'errors-only'] : [])]);
47
47
  }
48
48
  exports.buildEditorExtension = buildEditorExtension;
49
49
  async function updateExtensionSDK(name) {
@@ -52,53 +52,85 @@ async function updateExtensionSDK(name) {
52
52
  console.log(child_process.execSync('npm install lucid-extension-sdk@latest').toString());
53
53
  }
54
54
  exports.updateExtensionSDK = updateExtensionSDK;
55
- async function debugEditorExtension(name) {
56
- process.chdir('editorextensions/' + name);
55
+ /**
56
+ * Uses webpack to watch for changes in the editor extension
57
+ * @param name The editor extension name
58
+ * @param quiet If true, will only show errors in output
59
+ */
60
+ async function watchEditorExtension(name, quiet = false) {
61
+ process.chdir(`editorextensions/${name}`);
57
62
  const cli = new WebPackCLI();
58
- cli.run(['node', 'webpack', '--watch']);
63
+ cli.run(['node', 'webpack', '--watch', ...(quiet ? ['--stats', 'errors-only'] : [])]);
64
+ }
65
+ exports.watchEditorExtension = watchEditorExtension;
66
+ /**
67
+ * Runs the editor extensions and shape libraries in debug mode, including watching code for changes.
68
+ * @param extensionNames The names of the editor extensions
69
+ * @param quiet If true, will only show errors in output
70
+ */
71
+ async function debugEditorExtension(extensionNames, quiet = false) {
72
+ await Promise.all(extensionNames.map(async (name) => {
73
+ const child = child_process.spawn(`${process.argv[0]} ${process.argv[1]} watch-editor-extension ${name} ${quiet ? '--quiet ' : ''}`, {
74
+ stdio: 'inherit',
75
+ shell: true,
76
+ });
77
+ return child;
78
+ }));
59
79
  const app = express();
60
80
  app.use((req, res, next) => {
61
81
  res.header('Access-Control-Allow-Origin', '*');
62
82
  res.header('Access-Control-Allow-Methods', 'GET, OPTIONS');
63
83
  next();
64
84
  });
65
- app.get('/extension.js', async (req, res) => {
85
+ app.get(['/extension.js', '/editorextension/:name/extension.js'], async (req, res) => {
86
+ var _a;
87
+ const name = (_a = req.params['name']) !== null && _a !== void 0 ? _a : extensionNames[0];
66
88
  //Give it several seconds for the extension to finish generating before failing.
67
89
  const before = Date.now();
68
- while (!oldFs.existsSync('bin/extension.js') && Date.now() - before < 5000) {
90
+ while (!oldFs.existsSync(`editorextensions/${name}/bin/extension.js`) && Date.now() - before < 5000) {
69
91
  await new Promise((resolve) => setTimeout(resolve, 50));
70
92
  }
71
- res.send((await fs.readFile('bin/extension.js')).toString());
93
+ res.send((await fs.readFile(`editorextensions/${name}/bin/extension.js`)).toString());
72
94
  });
73
- app.get('/scopes', async (req, res) => {
74
- var _a, _b;
75
- const manifest = await (0, packagemanifest_1.readManifest)('../../');
76
- res.send(JSON.stringify((_b = (_a = manifest['extensions']) === null || _a === void 0 ? void 0 : _a.find((extension) => extension['name'] === name)) === null || _b === void 0 ? void 0 : _b.scopes));
95
+ app.get(['/scopes', '/editorextension/:name/scopes'], async (req, res) => {
96
+ var _a, _b, _c;
97
+ const name = (_a = req.params['name']) !== null && _a !== void 0 ? _a : extensionNames[0];
98
+ const manifest = await (0, packagemanifest_1.readManifest)();
99
+ res.send(JSON.stringify((_c = (_b = manifest['extensions']) === null || _b === void 0 ? void 0 : _b.find((extension) => extension['name'] === name)) === null || _c === void 0 ? void 0 : _c.scopes));
77
100
  });
78
101
  app.get('/packageId', async (req, res) => {
79
102
  var _a;
80
- const manifest = await (0, packagemanifest_1.readManifest)('../../');
103
+ const manifest = await (0, packagemanifest_1.readManifest)();
81
104
  res.send((_a = manifest['id']) !== null && _a !== void 0 ? _a : '__local__');
82
105
  });
83
- app.get('/editorextension', async (req, res) => {
84
- var _a, _b, _c, _d;
85
- const manifest = await (0, packagemanifest_1.readManifest)('../../');
86
- const extensionManifest = (_a = manifest['extensions']) === null || _a === void 0 ? void 0 : _a.find((one) => one['name'] === name);
87
- res.send({
88
- id: '__local__',
89
- packageId: (_b = manifest['id']) !== null && _b !== void 0 ? _b : '__local__',
90
- packageVersionId: '__local__',
91
- version: manifest['version'],
92
- name: name,
93
- title: (_c = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['title']) !== null && _c !== void 0 ? _c : 'Local dev extension',
94
- product: (_d = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['product']) !== null && _d !== void 0 ? _d : 'chart',
95
- scopes: extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['scopes'],
96
- codeUrl: 'http://localhost:9900/extension.js',
97
- });
106
+ app.get(['/editorextension', '/editorextension/:name'], async (req, res) => {
107
+ var _a;
108
+ const name = (_a = req.params['name']) !== null && _a !== void 0 ? _a : extensionNames[0];
109
+ const rawExtension = await getRawEditorExtension(name);
110
+ res.send(rawExtension);
111
+ });
112
+ app.get('/editorextensions', async (req, res) => {
113
+ res.send(await Promise.all(extensionNames.map((name) => getRawEditorExtension(name))));
98
114
  });
99
115
  app.listen(9900, 'localhost', () => {
100
116
  console.log('Listening at http://localhost:9900/extension.js');
101
117
  });
102
- (0, shapelibrary_1.debugShapeLibraries)('../..');
118
+ (0, shapelibrary_1.debugShapeLibraries)();
103
119
  }
104
120
  exports.debugEditorExtension = debugEditorExtension;
121
+ async function getRawEditorExtension(name) {
122
+ var _a, _b, _c, _d;
123
+ const manifest = await (0, packagemanifest_1.readManifest)();
124
+ const extensionManifest = (_a = manifest['extensions']) === null || _a === void 0 ? void 0 : _a.find((one) => one['name'] === name);
125
+ return {
126
+ id: '__local__',
127
+ packageId: (_b = manifest['id']) !== null && _b !== void 0 ? _b : '__local__',
128
+ packageVersionId: '__local__',
129
+ version: manifest['version'],
130
+ name: name,
131
+ title: (_c = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['title']) !== null && _c !== void 0 ? _c : 'Local dev extension',
132
+ product: (_d = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['product']) !== null && _d !== void 0 ? _d : 'chart',
133
+ scopes: extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['scopes'],
134
+ codeUrl: `http://localhost:9900/editorextension/${name}/extension.js`,
135
+ };
136
+ }
package/src/index.js CHANGED
@@ -24,6 +24,11 @@ class LucidSuiteExtensionCLI {
24
24
  const packageParser = subparsers.add_parser('bundle', {
25
25
  help: 'Prepare the current package for upload to the developer dashboard',
26
26
  });
27
+ packageParser.add_argument('--quiet', {
28
+ default: false,
29
+ action: 'store_true',
30
+ help: argparse_1.SUPPRESS,
31
+ });
27
32
  const updateSDKParser = subparsers.add_parser('update-sdk', {
28
33
  help: 'Update the editor extension SDK to the latest published version for all editor extensions in this package',
29
34
  });
@@ -35,10 +40,29 @@ class LucidSuiteExtensionCLI {
35
40
  help: 'Compile an editor extension in production mode; use this to check types and validate final compiled output',
36
41
  });
37
42
  buildExtensionParser.add_argument('name');
43
+ buildExtensionParser.add_argument('--quiet', {
44
+ default: false,
45
+ action: 'store_true',
46
+ help: argparse_1.SUPPRESS,
47
+ });
38
48
  const testExtensionParser = subparsers.add_parser('test-editor-extension', {
39
- help: 'Compile an editor extension in debug mode, and serve it at localhost:9900, along with any shape libraries in this package at localhost:9901. Watch for changes to the code and recompile as needed',
49
+ help: 'Compile one or more editor extensions in debug mode, and serve them at localhost:9900, along with any shape libraries in this package at localhost:9901. Watch for changes to the code and recompile as needed',
50
+ });
51
+ testExtensionParser.add_argument('name', { nargs: '*' });
52
+ testExtensionParser.add_argument('--quiet', {
53
+ default: false,
54
+ action: 'store_true',
55
+ help: argparse_1.SUPPRESS,
56
+ });
57
+ const watchExtensionParser = subparsers.add_parser('watch-editor-extension', {
58
+ help: 'Compile an editor extension in debug mode',
59
+ });
60
+ watchExtensionParser.add_argument('name');
61
+ watchExtensionParser.add_argument('--quiet', {
62
+ default: false,
63
+ action: 'store_true',
64
+ help: argparse_1.SUPPRESS,
40
65
  });
41
- testExtensionParser.add_argument('name');
42
66
  const testShapeLibraries = subparsers.add_parser('test-shape-libraries', {
43
67
  help: 'Serve any shape libraries in this package at localhost:9901. Watch for changes to the code and live-update as needed',
44
68
  });
@@ -66,7 +90,7 @@ class LucidSuiteExtensionCLI {
66
90
  break;
67
91
  case 'bundle':
68
92
  if ((0, package_1.currentlyInPackage)()) {
69
- await (0, package_1.writePackage)();
93
+ await (0, package_1.writePackage)(parsed['quiet']);
70
94
  }
71
95
  else {
72
96
  console.error('Not currently in a Lucid extension package folder');
@@ -90,7 +114,7 @@ class LucidSuiteExtensionCLI {
90
114
  break;
91
115
  case 'build-editor-extension':
92
116
  if ((0, package_1.currentlyInPackage)()) {
93
- await (0, editorextension_1.buildEditorExtension)(parsed['name']);
117
+ await (0, editorextension_1.buildEditorExtension)(parsed['name'], parsed['quiet']);
94
118
  }
95
119
  else {
96
120
  console.error('Not currently in a Lucid extension package folder');
@@ -114,7 +138,15 @@ class LucidSuiteExtensionCLI {
114
138
  break;
115
139
  case 'test-editor-extension':
116
140
  if ((0, package_1.currentlyInPackage)()) {
117
- await (0, editorextension_1.debugEditorExtension)(parsed['name']);
141
+ await (0, editorextension_1.debugEditorExtension)(parsed['name'], parsed['quiet']);
142
+ }
143
+ else {
144
+ console.error('Not currently in a Lucid extension package folder');
145
+ }
146
+ break;
147
+ case 'watch-editor-extension':
148
+ if ((0, package_1.currentlyInPackage)()) {
149
+ await (0, editorextension_1.watchEditorExtension)(parsed['name'], parsed['quiet']);
118
150
  }
119
151
  else {
120
152
  console.error('Not currently in a Lucid extension package folder');
package/src/package.d.ts CHANGED
@@ -3,4 +3,4 @@ export declare function createEmptyPackage(root: string): Promise<void>;
3
3
  export declare function currentlyInPackage(): boolean;
4
4
  export declare function modifyManifest(callback: (manifest: PackageManifest) => void | Promise<void>): Promise<void>;
5
5
  export declare function updateAllExtensionSDK(): Promise<void>;
6
- export declare function writePackage(): Promise<void>;
6
+ export declare function writePackage(quiet?: boolean): Promise<void>;
package/src/package.js CHANGED
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.writePackage = exports.updateAllExtensionSDK = exports.modifyManifest = exports.currentlyInPackage = exports.createEmptyPackage = void 0;
4
- const fs = require("fs/promises");
5
- const fsOld = require("fs");
6
- const filesystemutil_1 = require("./filesystemutil");
7
- const editorextension_1 = require("./editorextension");
8
4
  const child_process = require("child_process");
5
+ const fsOld = require("fs");
6
+ const fs = require("fs/promises");
9
7
  const JSZip = require("jszip");
10
- const shapelibrary_1 = require("./shapelibrary");
8
+ const editorextension_1 = require("./editorextension");
9
+ const filesystemutil_1 = require("./filesystemutil");
11
10
  const packagemanifest_1 = require("./packagemanifest");
11
+ const shapelibrary_1 = require("./shapelibrary");
12
12
  async function createEmptyPackage(root) {
13
13
  console.log('Creating empty Lucid Suite package in ' + root);
14
14
  (0, filesystemutil_1.copyFolderRecursiveSync)(__dirname + '/../templates/package', root);
@@ -35,7 +35,7 @@ async function updateAllExtensionSDK() {
35
35
  }
36
36
  }
37
37
  exports.updateAllExtensionSDK = updateAllExtensionSDK;
38
- async function writePackage() {
38
+ async function writePackage(quiet = false) {
39
39
  const zip = new JSZip();
40
40
  //Increment the patch number automatically on each build
41
41
  await modifyManifest(async (manifest) => {
@@ -55,7 +55,16 @@ async function writePackage() {
55
55
  if (parts[0] === 'editorextensions') {
56
56
  //Can't just call the method, as the WebpackCLI class does process.exit(2) :facepalm:
57
57
  console.log(`Compiling editor extension ${parts[1]}`);
58
- const cmd = process.argv[0] + ' ' + process.argv[1] + ' build-editor-extension ' + parts[1];
58
+ // Quotes are needed around every use of a path to deal with spaces
59
+ const cmd = '"' +
60
+ process.argv[0] +
61
+ '" "' +
62
+ process.argv[1] +
63
+ '" build-editor-extension ' +
64
+ (quiet ? '--quiet ' : '') +
65
+ '"' +
66
+ parts[1] +
67
+ '"';
59
68
  console.log(cmd);
60
69
  console.log(child_process.execSync(cmd).toString());
61
70
  }
@@ -41,10 +41,21 @@ async function getShapeListJson(name, packagePath) {
41
41
  const packageManifest = await (0, packagemanifest_1.readManifest)(packagePath + '/');
42
42
  const rawManifest = await fs.readFile(packagePath + `/shapelibraries/${name}/library.manifest`);
43
43
  const manifest = hjson.parse(rawManifest.toString());
44
+ const usedNames = new Set(manifest['shapes'].map((shape) => shape['key']).filter((key) => key !== undefined));
44
45
  return JSON.stringify(await Promise.all(manifest['shapes'].map(async (shapeManifest, index) => {
45
46
  var _a, _b;
46
47
  const rawShapeData = await fs.readFile(packagePath + `/shapelibraries/${name}/shapes/${shapeManifest['shape']}.shape`);
47
48
  const shapeData = hjson.parse(rawShapeData.toString());
49
+ let shapeName = shapeManifest['key'];
50
+ if (shapeName === undefined) {
51
+ shapeName = shapeManifest['shape'];
52
+ let suffixNumber = 1;
53
+ while (usedNames.has(shapeName)) {
54
+ suffixNumber++;
55
+ shapeName = shapeManifest['shape'] + '_' + suffixNumber;
56
+ }
57
+ usedNames.add(shapeName);
58
+ }
48
59
  const properties = {
49
60
  'Base': { 'x': shapeManifest['defaults']['width'] / 2, 'y': shapeManifest['defaults']['height'] / 2 },
50
61
  'BoundingBox': {
@@ -59,13 +70,14 @@ async function getShapeListJson(name, packagePath) {
59
70
  },
60
71
  'Stencil': {
61
72
  'lcszVersion': '1',
62
- 'name': shapeManifest['name'],
73
+ 'name': shapeName,
63
74
  'i18n': {},
64
75
  'sourcePackage': {
65
76
  'packageId': (_a = packageManifest['id']) !== null && _a !== void 0 ? _a : '__local__',
66
77
  'version': packageManifest['version'],
67
78
  'library': name,
68
79
  'shape': shapeManifest['shape'],
80
+ 'name': shapeName,
69
81
  },
70
82
  },
71
83
  };
@@ -110,7 +122,7 @@ async function getShapeListJson(name, packagePath) {
110
122
  'order': index,
111
123
  'properties': JSON.stringify(properties),
112
124
  'shapeLibrary': 'http://localhost:9901/shapeLibraries/' + encodeURIComponent(name),
113
- 'uri': `http://localhost:9901/shapeLibraries/${encodeURIComponent(name)}/shapes/${encodeURIComponent(shapeManifest['shape'])}`,
125
+ 'uri': `http://localhost:9901/shapeLibraries/${encodeURIComponent(name)}/shapes/${encodeURIComponent(shapeName)}`,
114
126
  };
115
127
  })));
116
128
  }