lucid-package 0.0.32 → 0.0.36

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.32",
3
+ "version": "0.0.36",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.debugEditorExtension = exports.watchEditorExtension = exports.updateExtensionSDK = exports.buildEditorExtension = exports.createEditorExtension = void 0;
4
- const fs = require("fs/promises");
4
+ const child_process = require("child_process");
5
+ const express = require("express");
5
6
  const oldFs = require("fs");
7
+ const fs = require("fs/promises");
8
+ const path = require("path");
6
9
  const filesystemutil_1 = require("./filesystemutil");
7
10
  const package_1 = require("./package");
8
- const express = require("express");
9
- const child_process = require("child_process");
10
- const shapelibrary_1 = require("./shapelibrary");
11
11
  const packagemanifest_1 = require("./packagemanifest");
12
- const path = require("path");
12
+ const shapelibrary_1 = require("./shapelibrary");
13
13
  const shellutil_1 = require("./shellutil");
14
14
  const WebPackCLI = require('webpack-cli');
15
15
  function linkInternalTestingSDK() {
@@ -58,14 +58,14 @@ async function createEditorExtension(name, isInternalTesting) {
58
58
  }
59
59
  exports.createEditorExtension = createEditorExtension;
60
60
  async function buildEditorExtension(name, isInternalTesting, quiet = false) {
61
- process.chdir('editorextensions/' + name);
61
+ process.chdir('editorextensions/' + (await getExtensionCodeDirectoryName(name)));
62
62
  installDependenciesIfNeeded(isInternalTesting);
63
63
  const cli = new WebPackCLI();
64
64
  await cli.run(['node', 'webpack', '--mode', 'production', ...(quiet ? ['--stats', 'errors-only'] : [])]);
65
65
  }
66
66
  exports.buildEditorExtension = buildEditorExtension;
67
67
  async function updateExtensionSDK(name) {
68
- process.chdir('editorextensions/' + name);
68
+ process.chdir('editorextensions/' + (await getExtensionCodeDirectoryName(name)));
69
69
  console.log('Installing latest SDK in extension ' + name);
70
70
  console.log((0, shellutil_1.execSyncLoggingOutputOnError)('npm install lucid-extension-sdk@latest').toString());
71
71
  }
@@ -76,7 +76,7 @@ exports.updateExtensionSDK = updateExtensionSDK;
76
76
  * @param quiet If true, will only show errors in output
77
77
  */
78
78
  async function watchEditorExtension(name, isInternalTesting, quiet = false) {
79
- process.chdir(`editorextensions/${name}`);
79
+ process.chdir('editorextensions/' + (await getExtensionCodeDirectoryName(name)));
80
80
  installDependenciesIfNeeded(isInternalTesting);
81
81
  const cli = new WebPackCLI();
82
82
  cli.run(['node', 'webpack', '--watch', ...(quiet ? ['--stats', 'errors-only'] : [])]);
@@ -104,12 +104,13 @@ async function debugEditorExtension(extensionNames, quiet = false) {
104
104
  app.get(['/extension.js', '/editorextension/:name/extension.js'], async (req, res) => {
105
105
  var _a;
106
106
  const name = (_a = req.params['name']) !== null && _a !== void 0 ? _a : extensionNames[0];
107
+ const directory = await getExtensionCodeDirectoryName(name);
107
108
  //Give it several seconds for the extension to finish generating before failing.
108
109
  const before = Date.now();
109
- while (!oldFs.existsSync(`editorextensions/${name}/bin/extension.js`) && Date.now() - before < 5000) {
110
+ while (!oldFs.existsSync(`editorextensions/${directory}/bin/extension.js`) && Date.now() - before < 5000) {
110
111
  await new Promise((resolve) => setTimeout(resolve, 50));
111
112
  }
112
- res.send((await fs.readFile(`editorextensions/${name}/bin/extension.js`)).toString());
113
+ res.send((await fs.readFile(`editorextensions/${directory}/bin/extension.js`)).toString());
113
114
  });
114
115
  app.get(['/scopes', '/editorextension/:name/scopes'], async (req, res) => {
115
116
  var _a, _b, _c;
@@ -155,10 +156,40 @@ async function debugEditorExtension(extensionNames, quiet = false) {
155
156
  (0, shapelibrary_1.debugShapeLibraries)();
156
157
  }
157
158
  exports.debugEditorExtension = debugEditorExtension;
159
+ async function getExtensionManifest(name) {
160
+ var _a;
161
+ const manifest = await (0, packagemanifest_1.readManifest)('local');
162
+ return { manifest, extensionManifest: (_a = manifest['extensions']) === null || _a === void 0 ? void 0 : _a.find((one) => one['name'] === name) };
163
+ }
164
+ /**
165
+ * We allow the creation of editor extensions that use the same code as a different editor extension in the same
166
+ * package. This is a workaround to have one extension work with multiple products. For example, one can build a
167
+ * "google-sheets-spark" extension and then add a "google-sheets-chart" extension to the manifest.json file and enter
168
+ * the same codePath for the chart extension as the spark extension.
169
+ */
170
+ async function getExtensionCodeDirectoryName(name) {
171
+ var _a;
172
+ const extensionManifest = (await getExtensionManifest(name)).extensionManifest;
173
+ const codePath = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['codePath'];
174
+ return codePath ? (_a = (await getExtensionCodeDirectoryNameFromCodePath(codePath))) !== null && _a !== void 0 ? _a : name : name;
175
+ }
176
+ /**
177
+ * Our codePath has the form '/editorextensions/{extensionName}/bin/extension.js'. This function returns the
178
+ * extensionName.
179
+ */
180
+ async function getExtensionCodeDirectoryNameFromCodePath(codePath) {
181
+ var _a;
182
+ const parts = (_a = codePath.split('/')) !== null && _a !== void 0 ? _a : [];
183
+ if (parts[0] === 'editorextensions' && parts[1]) {
184
+ return `${parts[1]}`;
185
+ }
186
+ return undefined;
187
+ }
158
188
  async function getRawEditorExtension(name) {
159
189
  var _a, _b, _c, _d;
160
- const manifest = await (0, packagemanifest_1.readManifest)('local');
161
- const extensionManifest = (_a = manifest['extensions']) === null || _a === void 0 ? void 0 : _a.find((one) => one['name'] === name);
190
+ const { manifest, extensionManifest } = await getExtensionManifest(name);
191
+ const codePath = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['codePath'];
192
+ const directory = codePath ? (_a = (await getExtensionCodeDirectoryNameFromCodePath(codePath))) !== null && _a !== void 0 ? _a : name : name;
162
193
  return {
163
194
  id: '__local__',
164
195
  packageId: (_b = manifest['id']) !== null && _b !== void 0 ? _b : '__local__',
@@ -168,6 +199,6 @@ async function getRawEditorExtension(name) {
168
199
  title: (_c = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['title']) !== null && _c !== void 0 ? _c : 'Local dev extension',
169
200
  product: (_d = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['product']) !== null && _d !== void 0 ? _d : 'chart',
170
201
  scopes: extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['scopes'],
171
- codeUrl: `http://localhost:9900/editorextension/${name}/extension.js`,
202
+ codeUrl: `http://localhost:9900/editorextension/${directory}/extension.js`,
172
203
  };
173
204
  }
@@ -21,6 +21,12 @@ export declare type PackageManifest = {
21
21
  'scopes': string[];
22
22
  'domainWhitelist': string[];
23
23
  }[];
24
+ 'mergeProviders'?: {
25
+ 'name': string;
26
+ 'title': string;
27
+ 'categories': string[];
28
+ 'integration'?: string;
29
+ }[];
24
30
  'dataConnectors'?: {
25
31
  'name': string;
26
32
  'oauthProviderName': string;
@@ -87,6 +87,25 @@ function validateManifestOrThrow(manifest) {
87
87
  }
88
88
  }
89
89
  }
90
+ if (manifest['mergeProviders']) {
91
+ if (!(0, checks_1.isTypedArray)(checks_1.isObject)(manifest['mergeProviders'])) {
92
+ throw new Error('manifest.json: "mergeProviders" must be an array of objects');
93
+ }
94
+ for (const provider of manifest['mergeProviders']) {
95
+ if (!(0, checks_1.isString)(provider['name'])) {
96
+ throw new Error('manifest.json: Merge provider "name" must be a string');
97
+ }
98
+ if (!(0, checks_1.isString)(provider['title'])) {
99
+ throw new Error('manifest.json: Merge provider "title" must be a string');
100
+ }
101
+ if (!(0, checks_1.isTypedArray)(checks_1.isString)(provider['categories'])) {
102
+ throw new Error('manifest.json: Merge provider "categories" must be a string array');
103
+ }
104
+ if (provider['integration'] && !(0, checks_1.isString)(provider['integration'])) {
105
+ throw new Error('manifest.json: Merge provider "integration" must be a string');
106
+ }
107
+ }
108
+ }
90
109
  if (manifest['dataConnectors']) {
91
110
  if (!(0, checks_1.isTypedArray)(checks_1.isObject)(manifest['dataConnectors'])) {
92
111
  throw new Error('manifest.json: "dataConnectors" must be an array of objects');