lucid-package 0.0.35 → 0.0.37
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 +1 -1
- package/src/editorextension.js +44 -13
- package/src/packagemanifest.d.ts +1 -1
- package/src/packagemanifest.js +4 -2
package/package.json
CHANGED
package/src/editorextension.js
CHANGED
|
@@ -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
|
|
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
|
|
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(
|
|
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/${
|
|
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/${
|
|
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 (
|
|
161
|
-
const
|
|
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/${
|
|
202
|
+
codeUrl: `http://localhost:9900/editorextension/${directory}/extension.js`,
|
|
172
203
|
};
|
|
173
204
|
}
|
package/src/packagemanifest.d.ts
CHANGED
package/src/packagemanifest.js
CHANGED
|
@@ -29,8 +29,10 @@ function validateManifestOrThrow(manifest) {
|
|
|
29
29
|
if (!(0, checks_1.isTypedArray)(checks_1.isString)(extension['scopes'])) {
|
|
30
30
|
throw new Error('manifest.json: extension "scopes" must be a string array');
|
|
31
31
|
}
|
|
32
|
-
if (extension['product'] !== 'chart' &&
|
|
33
|
-
|
|
32
|
+
if (extension['product'] !== 'chart' &&
|
|
33
|
+
extension['product'] !== 'spark' &&
|
|
34
|
+
extension['product'] !== 'teamspaces') {
|
|
35
|
+
throw new Error(`manifest.json: found ${extension['product']}. extension "product" must be "chart" or "spark" or "teamspaces"`);
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
}
|