lucid-package 0.0.78 → 0.0.80
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/dataconnector.js +5 -2
- package/src/editorextension.js +23 -12
- package/src/filesystemutil.d.ts +5 -0
- package/src/filesystemutil.js +9 -1
- package/src/index.js +2 -1
- package/src/installationutil.js +2 -2
- package/src/package.js +8 -6
- package/src/packagemanifest.d.ts +4 -2
- package/src/packagemanifest.js +15 -4
- package/src/shapelibrary.js +18 -18
package/package.json
CHANGED
package/src/dataconnector.js
CHANGED
|
@@ -4,9 +4,12 @@ exports.createDataConnector = void 0;
|
|
|
4
4
|
const filesystemutil_1 = require("./filesystemutil");
|
|
5
5
|
const installationutil_1 = require("./installationutil");
|
|
6
6
|
const package_1 = require("./package");
|
|
7
|
+
const path = require("path");
|
|
7
8
|
async function createDataConnector(name, isInternalTesting, skipSDKDependency) {
|
|
8
9
|
console.log('Creating data connector in dataconnectors/' + name);
|
|
9
|
-
|
|
10
|
+
const source = path.join(__dirname, '..', 'templates', 'dataconnector');
|
|
11
|
+
const targetFolder = path.join('dataconnectors', name);
|
|
12
|
+
(0, filesystemutil_1.copyFolderRecursiveSync)(source, targetFolder);
|
|
10
13
|
await (0, package_1.modifyManifest)((manifest) => {
|
|
11
14
|
if (!manifest['dataConnectors']) {
|
|
12
15
|
manifest['dataConnectors'] = [];
|
|
@@ -19,7 +22,7 @@ async function createDataConnector(name, isInternalTesting, skipSDKDependency) {
|
|
|
19
22
|
});
|
|
20
23
|
});
|
|
21
24
|
console.log(`Installing dependencies`);
|
|
22
|
-
process.chdir(
|
|
25
|
+
process.chdir(targetFolder);
|
|
23
26
|
(0, installationutil_1.installDependenciesIfNeeded)(isInternalTesting, skipSDKDependency);
|
|
24
27
|
}
|
|
25
28
|
exports.createDataConnector = createDataConnector;
|
package/src/editorextension.js
CHANGED
|
@@ -5,6 +5,7 @@ const child_process = require("child_process");
|
|
|
5
5
|
const express = require("express");
|
|
6
6
|
const oldFs = require("fs");
|
|
7
7
|
const fs = require("fs/promises");
|
|
8
|
+
const path = require("path");
|
|
8
9
|
const cors_1 = require("./cors");
|
|
9
10
|
const filesystemutil_1 = require("./filesystemutil");
|
|
10
11
|
const installationutil_1 = require("./installationutil");
|
|
@@ -15,9 +16,14 @@ const shellutil_1 = require("./shellutil");
|
|
|
15
16
|
const supportedproduct_1 = require("./supportedproduct");
|
|
16
17
|
const WebPackCLI = require('webpack-cli');
|
|
17
18
|
async function createEditorExtension(name, isInternalTesting, skipSDKDependency) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const editorExtensionSource = path.join(__dirname, '..', 'templates', 'editorextension');
|
|
20
|
+
const editorExtensionTargetFolder = path.join('editorextensions', name);
|
|
21
|
+
const publicSource = path.join(__dirname, '..', 'templates', 'public');
|
|
22
|
+
const publicTargetFolder = 'public';
|
|
23
|
+
const codePath = path.join('editorextensions', name, 'bin', 'extension.js');
|
|
24
|
+
console.log('Creating empty editor extension in ' + editorExtensionTargetFolder);
|
|
25
|
+
(0, filesystemutil_1.copyFolderRecursiveSync)(editorExtensionSource, editorExtensionTargetFolder);
|
|
26
|
+
(0, filesystemutil_1.copyFolderRecursiveSync)(publicSource, publicTargetFolder);
|
|
21
27
|
await (0, package_1.modifyManifest)((manifest) => {
|
|
22
28
|
if (!manifest['extensions']) {
|
|
23
29
|
manifest['extensions'] = [];
|
|
@@ -26,24 +32,26 @@ async function createEditorExtension(name, isInternalTesting, skipSDKDependency)
|
|
|
26
32
|
'name': name,
|
|
27
33
|
'title': name,
|
|
28
34
|
'products': [supportedproduct_1.SupportedProduct.Chart, supportedproduct_1.SupportedProduct.Spark],
|
|
29
|
-
'codePath':
|
|
35
|
+
'codePath': codePath,
|
|
30
36
|
'scopes': ['READ', 'WRITE', 'DOWNLOAD', 'SHOW_MODAL', 'CUSTOM_UI', 'NETWORK'],
|
|
31
37
|
});
|
|
32
38
|
});
|
|
33
39
|
console.log(`Installing dependencies`);
|
|
34
|
-
process.chdir(
|
|
40
|
+
process.chdir(editorExtensionTargetFolder);
|
|
35
41
|
(0, installationutil_1.installDependenciesIfNeeded)(isInternalTesting, skipSDKDependency);
|
|
36
42
|
}
|
|
37
43
|
exports.createEditorExtension = createEditorExtension;
|
|
38
44
|
async function buildEditorExtension(name, isInternalTesting, quiet = false) {
|
|
39
|
-
|
|
45
|
+
const extensionCodePath = path.join('editorextensions', (await getExtensionCodeDirectoryName(name)));
|
|
46
|
+
process.chdir(extensionCodePath);
|
|
40
47
|
(0, installationutil_1.installDependenciesIfNeeded)(isInternalTesting);
|
|
41
48
|
const cli = new WebPackCLI();
|
|
42
49
|
await cli.run(['node', 'webpack', '--mode', 'production', ...(quiet ? ['--stats', 'errors-only'] : [])]);
|
|
43
50
|
}
|
|
44
51
|
exports.buildEditorExtension = buildEditorExtension;
|
|
45
52
|
async function updateExtensionSDK(name) {
|
|
46
|
-
|
|
53
|
+
const extensionCodePath = path.join('editorextensions', (await getExtensionCodeDirectoryName(name)));
|
|
54
|
+
process.chdir(extensionCodePath);
|
|
47
55
|
console.log('Installing latest SDK in extension ' + name);
|
|
48
56
|
console.log((0, shellutil_1.execSyncLoggingOutputOnError)('npm install lucid-extension-sdk@latest').toString());
|
|
49
57
|
}
|
|
@@ -54,7 +62,8 @@ exports.updateExtensionSDK = updateExtensionSDK;
|
|
|
54
62
|
* @param quiet If true, will only show errors in output
|
|
55
63
|
*/
|
|
56
64
|
async function watchEditorExtension(name, isInternalTesting, quiet = false) {
|
|
57
|
-
|
|
65
|
+
const extensionCodePath = path.join('editorextensions', (await getExtensionCodeDirectoryName(name)));
|
|
66
|
+
process.chdir(extensionCodePath);
|
|
58
67
|
(0, installationutil_1.installDependenciesIfNeeded)(isInternalTesting);
|
|
59
68
|
const cli = new WebPackCLI();
|
|
60
69
|
cli.run(['node', 'webpack', '--watch', ...(quiet ? ['--stats', 'errors-only'] : [])]);
|
|
@@ -68,7 +77,7 @@ exports.watchEditorExtension = watchEditorExtension;
|
|
|
68
77
|
async function debugEditorExtension(extensionNames, quiet = false, pickAnyPort = false) {
|
|
69
78
|
let port = 9900;
|
|
70
79
|
await Promise.all(extensionNames.map(async (name) => {
|
|
71
|
-
const child = child_process.spawn(
|
|
80
|
+
const child = child_process.spawn(`"${process.argv[0]}" "${process.argv[1]}" watch-editor-extension ${name} ${quiet ? '--quiet ' : ''}`, {
|
|
72
81
|
stdio: 'inherit',
|
|
73
82
|
shell: true,
|
|
74
83
|
});
|
|
@@ -81,10 +90,11 @@ async function debugEditorExtension(extensionNames, quiet = false, pickAnyPort =
|
|
|
81
90
|
const directory = await getExtensionCodeDirectoryName(name);
|
|
82
91
|
//Give it several seconds for the extension to finish generating before failing.
|
|
83
92
|
const before = Date.now();
|
|
84
|
-
|
|
93
|
+
const bundlePath = path.join('editorextensions', directory, 'bin', 'extension.js');
|
|
94
|
+
while (!oldFs.existsSync(bundlePath) && Date.now() - before < 5000) {
|
|
85
95
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
86
96
|
}
|
|
87
|
-
res.send((await fs.readFile(
|
|
97
|
+
res.send((await fs.readFile(bundlePath)).toString());
|
|
88
98
|
});
|
|
89
99
|
app.get(['/scopes', '/editorextension/:name/scopes'], async (req, res) => {
|
|
90
100
|
const name = req.params['name'] ?? extensionNames[0];
|
|
@@ -115,6 +125,7 @@ async function debugEditorExtension(extensionNames, quiet = false, pickAnyPort =
|
|
|
115
125
|
'Label': setting.label,
|
|
116
126
|
'Description': setting.description,
|
|
117
127
|
'DataType': setting.type,
|
|
128
|
+
'DefaultValue': setting.default,
|
|
118
129
|
};
|
|
119
130
|
})));
|
|
120
131
|
});
|
|
@@ -213,7 +224,7 @@ async function getExtensionCodeDirectoryName(name) {
|
|
|
213
224
|
* extensionName.
|
|
214
225
|
*/
|
|
215
226
|
async function getExtensionCodeDirectoryNameFromCodePath(codePath) {
|
|
216
|
-
const parts = codePath.split(
|
|
227
|
+
const parts = codePath.split(path.sep) ?? [];
|
|
217
228
|
if (parts[0] === 'editorextensions' && parts[1]) {
|
|
218
229
|
return `${parts[1]}`;
|
|
219
230
|
}
|
package/src/filesystemutil.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export declare function copyFileSync(source: string, target: string): void;
|
|
2
2
|
export declare function copyFolderRecursiveSync(source: string, targetFolder: string): void;
|
|
3
|
+
/**
|
|
4
|
+
* On Windows machines '\' is used as the file separator. To ensure that we correctly zip files on Windows
|
|
5
|
+
* machines we replace '\' with '/'.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getNormalizedZipPath(rawPath: string): string;
|
package/src/filesystemutil.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.copyFolderRecursiveSync = exports.copyFileSync = void 0;
|
|
3
|
+
exports.getNormalizedZipPath = exports.copyFolderRecursiveSync = exports.copyFileSync = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
function copyFileSync(source, target) {
|
|
@@ -35,3 +35,11 @@ function copyFolderRecursiveSync(source, targetFolder) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
exports.copyFolderRecursiveSync = copyFolderRecursiveSync;
|
|
38
|
+
/**
|
|
39
|
+
* On Windows machines '\' is used as the file separator. To ensure that we correctly zip files on Windows
|
|
40
|
+
* machines we replace '\' with '/'.
|
|
41
|
+
*/
|
|
42
|
+
function getNormalizedZipPath(rawPath) {
|
|
43
|
+
return path.sep === '\\' ? rawPath.replace(/\\/g, '/') : rawPath;
|
|
44
|
+
}
|
|
45
|
+
exports.getNormalizedZipPath = getNormalizedZipPath;
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path = require("path");
|
|
3
4
|
const argparse_1 = require("argparse");
|
|
4
5
|
const dataconnector_1 = require("./dataconnector");
|
|
5
6
|
const editorextension_1 = require("./editorextension");
|
|
@@ -116,7 +117,7 @@ class LucidSuiteExtensionCLI {
|
|
|
116
117
|
let isInternalTesting = !!parsed['chdir'];
|
|
117
118
|
if (isInternalTesting) {
|
|
118
119
|
if (parsed['project']) {
|
|
119
|
-
process.chdir(parsed['chdir']
|
|
120
|
+
process.chdir(path.join(parsed['chdir'], parsed['project']));
|
|
120
121
|
}
|
|
121
122
|
else {
|
|
122
123
|
process.chdir(parsed['chdir']);
|
package/src/installationutil.js
CHANGED
|
@@ -8,7 +8,7 @@ function installDependenciesIfNeeded(isInternalTesting, skipSDKDependency = fals
|
|
|
8
8
|
if (!oldFs.existsSync('node_modules')) {
|
|
9
9
|
console.log((0, shellutil_1.execSyncLoggingOutputOnError)('npm install --silent').toString());
|
|
10
10
|
}
|
|
11
|
-
if (!oldFs.existsSync('node_modules
|
|
11
|
+
if (!oldFs.existsSync(path.join('node_modules', 'lucid-extension-sdk')) && !skipSDKDependency) {
|
|
12
12
|
if (isInternalTesting) {
|
|
13
13
|
linkInternalTestingSDK();
|
|
14
14
|
}
|
|
@@ -20,7 +20,7 @@ function installDependenciesIfNeeded(isInternalTesting, skipSDKDependency = fals
|
|
|
20
20
|
}
|
|
21
21
|
exports.installDependenciesIfNeeded = installDependenciesIfNeeded;
|
|
22
22
|
function linkInternalTestingSDK() {
|
|
23
|
-
if (!oldFs.existsSync('node_modules
|
|
23
|
+
if (!oldFs.existsSync(path.join('node_modules', 'lucid-extension-sdk'))) {
|
|
24
24
|
const cwd = process.cwd();
|
|
25
25
|
const rootSearch = 'lucid/main/extensibility/';
|
|
26
26
|
const pos = cwd.indexOf(rootSearch);
|
package/src/package.js
CHANGED
|
@@ -13,7 +13,8 @@ const shapelibrary_1 = require("./shapelibrary");
|
|
|
13
13
|
const shellutil_1 = require("./shellutil");
|
|
14
14
|
async function createEmptyPackage(root) {
|
|
15
15
|
console.log('Creating empty Lucid Suite package in ' + root);
|
|
16
|
-
|
|
16
|
+
const source = path.join(__dirname, '..', 'templates', 'package');
|
|
17
|
+
(0, filesystemutil_1.copyFolderRecursiveSync)(source, root);
|
|
17
18
|
}
|
|
18
19
|
exports.createEmptyPackage = createEmptyPackage;
|
|
19
20
|
function currentlyInPackage() {
|
|
@@ -41,7 +42,7 @@ exports.modifyManifest = modifyManifest;
|
|
|
41
42
|
async function updateAllExtensionSDK() {
|
|
42
43
|
const manifest = await (0, packagemanifest_1.readManifest)();
|
|
43
44
|
for (const extension of manifest['extensions'] || []) {
|
|
44
|
-
const parts = extension['codePath'].split(
|
|
45
|
+
const parts = extension['codePath'].split(path.sep);
|
|
45
46
|
if (parts[0] === 'editorextensions') {
|
|
46
47
|
await (0, editorextension_1.updateExtensionSDK)(parts[1]);
|
|
47
48
|
}
|
|
@@ -71,7 +72,7 @@ async function writePackage(quiet = false, manifestOverrideEnv) {
|
|
|
71
72
|
.join(', ')}`);
|
|
72
73
|
process.exit(1);
|
|
73
74
|
}
|
|
74
|
-
const parts = extension['codePath'].split(
|
|
75
|
+
const parts = extension['codePath'].split(path.sep);
|
|
75
76
|
if (parts[0] === 'editorextensions') {
|
|
76
77
|
//Can't just call the method, as the WebpackCLI class does process.exit(2) :facepalm:
|
|
77
78
|
console.log(`Compiling editor extension ${parts[1]}`);
|
|
@@ -92,7 +93,7 @@ async function writePackage(quiet = false, manifestOverrideEnv) {
|
|
|
92
93
|
}
|
|
93
94
|
//Do the same for each shape library
|
|
94
95
|
for (const library of manifest['shapeLibraries'] || []) {
|
|
95
|
-
const parts = library['lcszPath'].split(
|
|
96
|
+
const parts = library['lcszPath'].split(path.sep);
|
|
96
97
|
if (parts[0] === 'shapelibraries') {
|
|
97
98
|
console.log(`Building shape library ${parts[1]}`);
|
|
98
99
|
await (0, shapelibrary_1.buildShapeLibrary)(parts[1].replace('.lcsz', ''));
|
|
@@ -112,8 +113,9 @@ async function writePackage(quiet = false, manifestOverrideEnv) {
|
|
|
112
113
|
if (zipDirectory != null) {
|
|
113
114
|
zipPath = zipDirectory + filePath.substring(directory.length);
|
|
114
115
|
}
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
const normalizedZipPath = (0, filesystemutil_1.getNormalizedZipPath)(zipPath);
|
|
117
|
+
console.log('Adding resource file: ' + filePath + ' -> ' + normalizedZipPath);
|
|
118
|
+
zip.file(normalizedZipPath, await fs.readFile(filePath));
|
|
117
119
|
}
|
|
118
120
|
else if (stat.isDirectory()) {
|
|
119
121
|
await checkDirForResources(filePath, zipDirectory ? path.join(zipDirectory, fileName) : undefined);
|
package/src/packagemanifest.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JsonSerializable } from 'lucid-extension-sdk';
|
|
1
2
|
import { SupportedProduct } from './supportedproduct';
|
|
2
3
|
export declare enum SettingType {
|
|
3
4
|
STRING = "string"
|
|
@@ -45,11 +46,12 @@ export type PackageManifest = {
|
|
|
45
46
|
'label': string;
|
|
46
47
|
'description': string;
|
|
47
48
|
'type': SettingType;
|
|
49
|
+
'default'?: JsonSerializable;
|
|
48
50
|
}[];
|
|
49
51
|
'public'?: Record<string, string>;
|
|
50
52
|
};
|
|
51
53
|
/**
|
|
52
54
|
* @param manifestOverrideEnv The environment to override the manifest with
|
|
53
|
-
* @param
|
|
55
|
+
* @param basePath The path to read the manifest from
|
|
54
56
|
*/
|
|
55
|
-
export declare function readManifest(manifestOverrideEnv?: string,
|
|
57
|
+
export declare function readManifest(manifestOverrideEnv?: string, basePath?: string): Promise<PackageManifest>;
|
package/src/packagemanifest.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.readManifest = exports.SettingType = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const fsPromises = require("fs/promises");
|
|
6
|
+
const path = require("path");
|
|
6
7
|
const lucid_extension_sdk_1 = require("lucid-extension-sdk");
|
|
7
8
|
const supportedproduct_1 = require("./supportedproduct");
|
|
8
9
|
var SettingType;
|
|
@@ -40,6 +41,16 @@ function validateManifestOrThrow(manifest) {
|
|
|
40
41
|
if (!(0, lucid_extension_sdk_1.enumValidator)(SettingType)(setting['type'])) {
|
|
41
42
|
throw new Error('manifest.json: setting "type" must be "string"');
|
|
42
43
|
}
|
|
44
|
+
if ((0, lucid_extension_sdk_1.isDef)(setting['default'])) {
|
|
45
|
+
if (setting['type'] === SettingType.STRING) {
|
|
46
|
+
if (!(0, lucid_extension_sdk_1.isString)(setting['default'])) {
|
|
47
|
+
throw new Error('manifest.json: setting "default" must be of the type specified for the setting');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new Error('manifest.json: unsupported setting type');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
43
54
|
}
|
|
44
55
|
}
|
|
45
56
|
if (manifest['extensions']) {
|
|
@@ -222,12 +233,12 @@ function deepMixin(target, mixin) {
|
|
|
222
233
|
}
|
|
223
234
|
/**
|
|
224
235
|
* @param manifestOverrideEnv The environment to override the manifest with
|
|
225
|
-
* @param
|
|
236
|
+
* @param basePath The path to read the manifest from
|
|
226
237
|
*/
|
|
227
|
-
async function readManifest(manifestOverrideEnv,
|
|
228
|
-
const raw = JSON.parse((await fsPromises.readFile(path
|
|
238
|
+
async function readManifest(manifestOverrideEnv, basePath = '.') {
|
|
239
|
+
const raw = JSON.parse((await fsPromises.readFile(path.join(basePath, 'manifest.json'))).toString());
|
|
229
240
|
if (manifestOverrideEnv) {
|
|
230
|
-
const manifestOverridePath = path
|
|
241
|
+
const manifestOverridePath = path.join(basePath, `manifest.${manifestOverrideEnv}.json`);
|
|
231
242
|
try {
|
|
232
243
|
const overrides = JSON.parse((await fsPromises.readFile(manifestOverridePath)).toString());
|
|
233
244
|
deepMixin(raw, overrides);
|
package/src/shapelibrary.js
CHANGED
|
@@ -15,8 +15,10 @@ const ws = require('ws');
|
|
|
15
15
|
const chokidar = require('chokidar');
|
|
16
16
|
const sizeOf = require('image-size');
|
|
17
17
|
async function createEmptyShapeLibrary(name) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const source = path.join(__dirname, '..', 'templates', 'shapelibrary');
|
|
19
|
+
const targetFolder = path.join('shapelibraries', name);
|
|
20
|
+
console.log('Creating shape library in ' + targetFolder);
|
|
21
|
+
(0, filesystemutil_1.copyFolderRecursiveSync)(source, targetFolder);
|
|
20
22
|
await (0, package_1.modifyManifest)((manifest) => {
|
|
21
23
|
if (!manifest['shapeLibraries']) {
|
|
22
24
|
manifest['shapeLibraries'] = [];
|
|
@@ -24,13 +26,13 @@ async function createEmptyShapeLibrary(name) {
|
|
|
24
26
|
manifest['shapeLibraries'].push({
|
|
25
27
|
'name': name,
|
|
26
28
|
'product': 'chart',
|
|
27
|
-
'lcszPath':
|
|
29
|
+
'lcszPath': path.join('shapelibraries', `${name}.lcsz`),
|
|
28
30
|
});
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
33
|
exports.createEmptyShapeLibrary = createEmptyShapeLibrary;
|
|
32
34
|
async function createImageShapeLibrary(name, imagePath, config) {
|
|
33
|
-
console.log('Creating image shape library in
|
|
35
|
+
console.log('Creating image shape library in ' + path.join('shapelibraries', name));
|
|
34
36
|
if (!fsSync.lstatSync(imagePath).isDirectory()) {
|
|
35
37
|
console.error('The provided path `' + imagePath + '` is not a folder');
|
|
36
38
|
return;
|
|
@@ -115,7 +117,7 @@ async function createImageShapeLibrary(name, imagePath, config) {
|
|
|
115
117
|
manifest['shapeLibraries'].push({
|
|
116
118
|
'name': name,
|
|
117
119
|
'product': 'chart',
|
|
118
|
-
'lcszPath':
|
|
120
|
+
'lcszPath': path.join('shapelibraries', `${name}.lcsz`),
|
|
119
121
|
});
|
|
120
122
|
}
|
|
121
123
|
});
|
|
@@ -134,12 +136,14 @@ const defaultNameMap = new Map([
|
|
|
134
136
|
//Produce JSON equivalent to the document service's
|
|
135
137
|
// /shapeLibraries/:name/shapes endpoint
|
|
136
138
|
async function getShapeListJson(name, packagePath, port = 9901) {
|
|
137
|
-
const packageManifest = await (0, packagemanifest_1.readManifest)('local', packagePath
|
|
138
|
-
const
|
|
139
|
+
const packageManifest = await (0, packagemanifest_1.readManifest)('local', packagePath);
|
|
140
|
+
const manifestPath = path.join(packagePath, 'shapelibraries', name, 'library.manifest');
|
|
141
|
+
const rawManifest = await fs.readFile(manifestPath);
|
|
139
142
|
const manifest = hjson.parse(rawManifest.toString());
|
|
140
143
|
const usedNames = new Set(manifest['shapes'].map((shape) => shape['key']).filter((key) => key !== undefined));
|
|
141
144
|
return JSON.stringify(await Promise.all(manifest['shapes'].map(async (shapeManifest, index) => {
|
|
142
|
-
const
|
|
145
|
+
const shapeDataPath = path.join(packagePath, 'shapelibraries', name, 'shapes', `${shapeManifest['shape']}.shape`);
|
|
146
|
+
const rawShapeData = await fs.readFile(shapeDataPath);
|
|
143
147
|
const shapeData = hjson.parse(rawShapeData.toString());
|
|
144
148
|
let shapeName = shapeManifest['key'];
|
|
145
149
|
if (shapeName === undefined) {
|
|
@@ -239,11 +243,7 @@ async function buildShapeLibrary(name) {
|
|
|
239
243
|
}
|
|
240
244
|
}
|
|
241
245
|
else {
|
|
242
|
-
|
|
243
|
-
* On Windows machines '\' is used as the file separator. To ensure that we correctly zip files on Windows
|
|
244
|
-
* machines we replace '\' with '/'.
|
|
245
|
-
*/
|
|
246
|
-
const normalizedSource = path.sep === '\\' ? source.replace(/\\/g, '/') : source;
|
|
246
|
+
const normalizedSource = (0, filesystemutil_1.getNormalizedZipPath)(source);
|
|
247
247
|
zip.file(normalizedSource.replace(`shapelibraries/${name}/`, ''), await fs.readFile(source));
|
|
248
248
|
}
|
|
249
249
|
};
|
|
@@ -262,10 +262,10 @@ async function debugShapeLibraries(packagePath = '.', pickAnyPort = false) {
|
|
|
262
262
|
//shape library, the toolbox doesn't update.
|
|
263
263
|
let shapeLibraryVersion = Date.now();
|
|
264
264
|
app.get('/shapeLibraries', async (req, res) => {
|
|
265
|
-
const manifest = await (0, packagemanifest_1.readManifest)('local', packagePath
|
|
265
|
+
const manifest = await (0, packagemanifest_1.readManifest)('local', packagePath);
|
|
266
266
|
const libraries = manifest['shapeLibraries'] ?? [];
|
|
267
267
|
const output = await Promise.all(libraries.map(async (libraryManifest) => {
|
|
268
|
-
const libraryDefinitionContent = await fs.readFile(packagePath
|
|
268
|
+
const libraryDefinitionContent = await fs.readFile(path.join(packagePath, 'shapelibraries', libraryManifest['name'], 'library.manifest'));
|
|
269
269
|
const libraryDefinition = JSON.parse(libraryDefinitionContent.toString());
|
|
270
270
|
return {
|
|
271
271
|
'uri': `http://localhost:${port}/shapeLibraries/` +
|
|
@@ -295,14 +295,14 @@ async function debugShapeLibraries(packagePath = '.', pickAnyPort = false) {
|
|
|
295
295
|
const oldcwd = process.cwd();
|
|
296
296
|
process.chdir(packagePath);
|
|
297
297
|
//Find all the shapes in the given shape library, and produce JSON for the client
|
|
298
|
-
res.sendFile('shapelibraries
|
|
298
|
+
res.sendFile(path.join('shapelibraries', req.params.libraryName, 'images', req.params.image), {
|
|
299
299
|
root: process.cwd(),
|
|
300
300
|
});
|
|
301
301
|
process.chdir(oldcwd);
|
|
302
302
|
});
|
|
303
303
|
app.get('/shapeLibraries/');
|
|
304
304
|
app.get('/manifest', async (req, res) => {
|
|
305
|
-
const packageManifest = await (0, packagemanifest_1.readManifest)('local', packagePath
|
|
305
|
+
const packageManifest = await (0, packagemanifest_1.readManifest)('local', packagePath);
|
|
306
306
|
res.send(JSON.stringify(packageManifest));
|
|
307
307
|
});
|
|
308
308
|
const listen = () => {
|
|
@@ -314,7 +314,7 @@ async function debugShapeLibraries(packagePath = '.', pickAnyPort = false) {
|
|
|
314
314
|
wss.on('connection', (ws) => {
|
|
315
315
|
sockets.push(ws);
|
|
316
316
|
});
|
|
317
|
-
chokidar.watch(packagePath
|
|
317
|
+
chokidar.watch(path.join(packagePath, 'shapelibraries')).on('all', () => {
|
|
318
318
|
shapeLibraryVersion = Date.now();
|
|
319
319
|
for (const socket of sockets) {
|
|
320
320
|
socket.send('refresh');
|