lucid-package 0.0.17 → 0.0.21

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.17",
3
+ "version": "0.0.21",
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
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, quiet?: boolean): 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");
@@ -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, quiet = false) {
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
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
@@ -46,14 +46,23 @@ class LucidSuiteExtensionCLI {
46
46
  help: argparse_1.SUPPRESS,
47
47
  });
48
48
  const testExtensionParser = subparsers.add_parser('test-editor-extension', {
49
- 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
50
  });
51
- testExtensionParser.add_argument('name');
51
+ testExtensionParser.add_argument('name', { nargs: '*' });
52
52
  testExtensionParser.add_argument('--quiet', {
53
53
  default: false,
54
54
  action: 'store_true',
55
55
  help: argparse_1.SUPPRESS,
56
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,
65
+ });
57
66
  const testShapeLibraries = subparsers.add_parser('test-shape-libraries', {
58
67
  help: 'Serve any shape libraries in this package at localhost:9901. Watch for changes to the code and live-update as needed',
59
68
  });
@@ -135,6 +144,14 @@ class LucidSuiteExtensionCLI {
135
144
  console.error('Not currently in a Lucid extension package folder');
136
145
  }
137
146
  break;
147
+ case 'watch-editor-extension':
148
+ if ((0, package_1.currentlyInPackage)()) {
149
+ await (0, editorextension_1.watchEditorExtension)(parsed['name'], parsed['quiet']);
150
+ }
151
+ else {
152
+ console.error('Not currently in a Lucid extension package folder');
153
+ }
154
+ break;
138
155
  default:
139
156
  parser.print_help();
140
157
  }
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);
@@ -55,12 +55,16 @@ async function writePackage(quiet = false) {
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] +
59
- ' ' +
58
+ // Quotes are needed around every use of a path to deal with spaces
59
+ const cmd = '"' +
60
+ process.argv[0] +
61
+ '" "' +
60
62
  process.argv[1] +
61
- ' build-editor-extension ' +
63
+ '" build-editor-extension ' +
62
64
  (quiet ? '--quiet ' : '') +
63
- parts[1];
65
+ '"' +
66
+ parts[1] +
67
+ '"';
64
68
  console.log(cmd);
65
69
  console.log(child_process.execSync(cmd).toString());
66
70
  }
@@ -72,6 +72,10 @@ function validateManifestOrThrow(manifest) {
72
72
  if (!(0, checks_1.isTypedArray)(checks_1.isString)(provider['domainWhitelist'])) {
73
73
  throw new Error('manifest.json: OAuth provider "domainWhitelist" must be a string array');
74
74
  }
75
+ if (provider['clientAuthentication'] !== 'basic' &&
76
+ provider['clientAuthentication'] !== 'clientParameters') {
77
+ throw new Error('manifest.json: OAuth provider "clientAuthentication" must be "basic" or "clientParameters"');
78
+ }
75
79
  }
76
80
  }
77
81
  if (manifest['dataConnectors']) {
@@ -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
  }