lucid-package 0.0.53 → 0.0.57
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 +2 -1
- package/src/index.js +34 -0
- package/src/shapelibrary.d.ts +6 -0
- package/src/shapelibrary.js +100 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lucid-package",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.57",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"chokidar": "^3.5.3",
|
|
23
23
|
"express": "^4.17.1",
|
|
24
24
|
"hjson": "^3.2.2",
|
|
25
|
+
"image-size": "^1.0.2",
|
|
25
26
|
"jszip": "^3.7.1",
|
|
26
27
|
"lucid-extension-sdk": "^0.0.112",
|
|
27
28
|
"password-prompt": "^1.1.2",
|
package/src/index.js
CHANGED
|
@@ -6,6 +6,7 @@ const package_1 = require("./package");
|
|
|
6
6
|
const shapelibrary_1 = require("./shapelibrary");
|
|
7
7
|
class LucidSuiteExtensionCLI {
|
|
8
8
|
async run(args) {
|
|
9
|
+
var _a, _b;
|
|
9
10
|
const parser = new argparse_1.ArgumentParser({
|
|
10
11
|
description: 'Create and manage Lucid extension packages',
|
|
11
12
|
});
|
|
@@ -83,6 +84,24 @@ class LucidSuiteExtensionCLI {
|
|
|
83
84
|
help: 'Create a new shape library as part of the current package',
|
|
84
85
|
});
|
|
85
86
|
createShapeLibrary.add_argument('name');
|
|
87
|
+
const generateImageShapeLibrary = subparsers.add_parser('create-image-shape-library', {
|
|
88
|
+
help: 'Create a new shape library as part of the current package',
|
|
89
|
+
});
|
|
90
|
+
generateImageShapeLibrary.add_argument('name');
|
|
91
|
+
generateImageShapeLibrary.add_argument('path');
|
|
92
|
+
generateImageShapeLibrary.add_argument('--width', {
|
|
93
|
+
type: 'str',
|
|
94
|
+
help: argparse_1.SUPPRESS,
|
|
95
|
+
});
|
|
96
|
+
generateImageShapeLibrary.add_argument('--height', {
|
|
97
|
+
type: 'str',
|
|
98
|
+
help: argparse_1.SUPPRESS,
|
|
99
|
+
});
|
|
100
|
+
generateImageShapeLibrary.add_argument('--aspectRatio', {
|
|
101
|
+
default: false,
|
|
102
|
+
action: 'store_true',
|
|
103
|
+
help: 'Lock the aspect ratio of all images',
|
|
104
|
+
});
|
|
86
105
|
const parsed = parser.parse_args(args);
|
|
87
106
|
//For internal development, creating and operating on a "test" package via bazel
|
|
88
107
|
let isInternalTesting = !!parsed['chdir'];
|
|
@@ -146,6 +165,21 @@ class LucidSuiteExtensionCLI {
|
|
|
146
165
|
console.error('Not currently in a Lucid extension package folder');
|
|
147
166
|
}
|
|
148
167
|
break;
|
|
168
|
+
case 'create-image-shape-library':
|
|
169
|
+
if ((0, package_1.currentlyInPackage)()) {
|
|
170
|
+
const width = (_a = Number(parsed['width'])) !== null && _a !== void 0 ? _a : undefined;
|
|
171
|
+
const height = (_b = Number(parsed['height'])) !== null && _b !== void 0 ? _b : undefined;
|
|
172
|
+
const config = {
|
|
173
|
+
width: width,
|
|
174
|
+
height: height,
|
|
175
|
+
lockAspect: parsed['aspectRatio'],
|
|
176
|
+
};
|
|
177
|
+
await (0, shapelibrary_1.createImageShapeLibrary)(parsed['name'], parsed['path'], config);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
console.error('Not currently in a Lucid extension package folder');
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
149
183
|
case 'test-shape-libraries':
|
|
150
184
|
if ((0, package_1.currentlyInPackage)()) {
|
|
151
185
|
await (0, shapelibrary_1.debugShapeLibraries)();
|
package/src/shapelibrary.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
export interface ImageShapeConfig {
|
|
2
|
+
width?: Number;
|
|
3
|
+
height?: Number;
|
|
4
|
+
lockAspect?: Boolean;
|
|
5
|
+
}
|
|
1
6
|
export declare function createEmptyShapeLibrary(name: string): Promise<void>;
|
|
7
|
+
export declare function createImageShapeLibrary(name: string, imagePath: string, config: ImageShapeConfig): Promise<void>;
|
|
2
8
|
export declare function getShapeListJson(name: string, packagePath: string, port?: number): Promise<string>;
|
|
3
9
|
export declare function buildShapeLibrary(name: string): Promise<void>;
|
|
4
10
|
export declare function debugShapeLibraries(packagePath?: string, pickAnyPort?: boolean): Promise<void>;
|
package/src/shapelibrary.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.debugShapeLibraries = exports.buildShapeLibrary = exports.getShapeListJson = exports.createEmptyShapeLibrary = void 0;
|
|
3
|
+
exports.debugShapeLibraries = exports.buildShapeLibrary = exports.getShapeListJson = exports.createImageShapeLibrary = exports.createEmptyShapeLibrary = void 0;
|
|
4
4
|
const express = require("express");
|
|
5
|
+
const fsSync = require("fs");
|
|
5
6
|
const fs = require("fs/promises");
|
|
6
7
|
const JSZip = require("jszip");
|
|
7
8
|
const path = require("path");
|
|
@@ -11,6 +12,7 @@ const packagemanifest_1 = require("./packagemanifest");
|
|
|
11
12
|
const hjson = require('hjson');
|
|
12
13
|
const ws = require('ws');
|
|
13
14
|
const chokidar = require('chokidar');
|
|
15
|
+
const sizeOf = require('image-size');
|
|
14
16
|
async function createEmptyShapeLibrary(name) {
|
|
15
17
|
console.log('Creating shape library in shapelibraries/' + name);
|
|
16
18
|
(0, filesystemutil_1.copyFolderRecursiveSync)(__dirname + '/../templates/shapelibrary', 'shapelibraries/' + name);
|
|
@@ -26,6 +28,96 @@ async function createEmptyShapeLibrary(name) {
|
|
|
26
28
|
});
|
|
27
29
|
}
|
|
28
30
|
exports.createEmptyShapeLibrary = createEmptyShapeLibrary;
|
|
31
|
+
async function createImageShapeLibrary(name, imagePath, config) {
|
|
32
|
+
console.log('Creating image shape library in shapelibraries/' + name);
|
|
33
|
+
if (!fsSync.lstatSync(imagePath).isDirectory()) {
|
|
34
|
+
console.error('The provided path `' + imagePath + '` is not a folder');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const imageFolder = path.join('shapelibraries', name, 'images');
|
|
38
|
+
const shapeFolder = path.join('shapelibraries', name, 'shapes');
|
|
39
|
+
const shapes = [];
|
|
40
|
+
if (!fsSync.existsSync(imageFolder)) {
|
|
41
|
+
fsSync.mkdirSync(imageFolder, { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
if (!fsSync.existsSync(shapeFolder)) {
|
|
44
|
+
fsSync.mkdirSync(shapeFolder, { recursive: true });
|
|
45
|
+
}
|
|
46
|
+
const files = fsSync.readdirSync(imagePath);
|
|
47
|
+
files.forEach((file) => {
|
|
48
|
+
var curSource = path.join(imagePath, file);
|
|
49
|
+
const fileName = file.replace(/\.[^/.]+$/, '');
|
|
50
|
+
// read image
|
|
51
|
+
var dimen = { width: 160, height: 160 };
|
|
52
|
+
if (!config.width || !config.height) {
|
|
53
|
+
try {
|
|
54
|
+
dimen = sizeOf(curSource);
|
|
55
|
+
console.log('dimen of ' + file + ': ' + dimen + ' - ' + JSON.stringify(dimen));
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.log('No dimensions found for ' + file);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const lockedArray = [];
|
|
62
|
+
if (config.lockAspect) {
|
|
63
|
+
lockedArray.push('aspectRatio');
|
|
64
|
+
}
|
|
65
|
+
const manifestShape = {
|
|
66
|
+
shape: fileName,
|
|
67
|
+
name: fileName,
|
|
68
|
+
defaults: {
|
|
69
|
+
width: dimen.width,
|
|
70
|
+
height: dimen.height,
|
|
71
|
+
},
|
|
72
|
+
locked: lockedArray,
|
|
73
|
+
};
|
|
74
|
+
shapes.push(manifestShape);
|
|
75
|
+
// create shape file
|
|
76
|
+
const shapeFile = {
|
|
77
|
+
images: {
|
|
78
|
+
imageReference: {
|
|
79
|
+
path: file,
|
|
80
|
+
type: 'file',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
geometry: [
|
|
84
|
+
{
|
|
85
|
+
type: 'rect',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
style: {
|
|
89
|
+
fill: {
|
|
90
|
+
type: 'image',
|
|
91
|
+
ref: 'imageReference',
|
|
92
|
+
mode: 'stretch',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
fsSync.writeFileSync(path.join(shapeFolder, fileName) + '.shape', JSON.stringify(shapeFile, undefined, 2));
|
|
97
|
+
// copy image
|
|
98
|
+
console.log(`Copying ${curSource} to ${path.join(imageFolder, file)}`);
|
|
99
|
+
(0, filesystemutil_1.copyFileSync)(curSource, path.join(imageFolder, file));
|
|
100
|
+
});
|
|
101
|
+
const manifest = {
|
|
102
|
+
'name': name,
|
|
103
|
+
'shapes': shapes,
|
|
104
|
+
};
|
|
105
|
+
fsSync.writeFileSync(path.join('shapelibraries', name, 'library.manifest'), JSON.stringify(manifest, undefined, 2));
|
|
106
|
+
// update extension manifest
|
|
107
|
+
await (0, package_1.modifyManifest)((manifest) => {
|
|
108
|
+
if (!manifest['shapeLibraries']) {
|
|
109
|
+
manifest['shapeLibraries'] = [];
|
|
110
|
+
}
|
|
111
|
+
if (!manifest['shapeLibraries'].some((x) => x.name == name)) {
|
|
112
|
+
manifest['shapeLibraries'].push({
|
|
113
|
+
'name': name,
|
|
114
|
+
'product': 'chart',
|
|
115
|
+
'lcszPath': `shapelibraries/${name}.lcsz`,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
exports.createImageShapeLibrary = createImageShapeLibrary;
|
|
29
121
|
const defaultNameMap = new Map([
|
|
30
122
|
['rounding', 'Rounding'],
|
|
31
123
|
['fillColor', 'FillColor'],
|
|
@@ -33,6 +125,7 @@ const defaultNameMap = new Map([
|
|
|
33
125
|
['strokeWidth', 'LineWidth'],
|
|
34
126
|
['opacity', 'Opacity'],
|
|
35
127
|
['rotation', 'Rotation'],
|
|
128
|
+
['aspectRatio', 'AspectRatio'],
|
|
36
129
|
]);
|
|
37
130
|
//Produce JSON equivalent to the document service's
|
|
38
131
|
// /shapeLibraries/:name/shapes endpoint
|
|
@@ -42,7 +135,7 @@ async function getShapeListJson(name, packagePath, port = 9901) {
|
|
|
42
135
|
const manifest = hjson.parse(rawManifest.toString());
|
|
43
136
|
const usedNames = new Set(manifest['shapes'].map((shape) => shape['key']).filter((key) => key !== undefined));
|
|
44
137
|
return JSON.stringify(await Promise.all(manifest['shapes'].map(async (shapeManifest, index) => {
|
|
45
|
-
var _a, _b;
|
|
138
|
+
var _a, _b, _c, _d;
|
|
46
139
|
const rawShapeData = await fs.readFile(packagePath + `/shapelibraries/${name}/shapes/${shapeManifest['shape']}.shape`);
|
|
47
140
|
const shapeData = hjson.parse(rawShapeData.toString());
|
|
48
141
|
let shapeName = shapeManifest['key'];
|
|
@@ -71,6 +164,7 @@ async function getShapeListJson(name, packagePath, port = 9901) {
|
|
|
71
164
|
'lcszVersion': '1',
|
|
72
165
|
'name': shapeName,
|
|
73
166
|
'i18n': {},
|
|
167
|
+
'locked': shapeManifest['locked'],
|
|
74
168
|
'sourcePackage': {
|
|
75
169
|
'packageId': (_a = packageManifest['id']) !== null && _a !== void 0 ? _a : '__local__',
|
|
76
170
|
'version': packageManifest['version'],
|
|
@@ -114,6 +208,10 @@ async function getShapeListJson(name, packagePath, port = 9901) {
|
|
|
114
208
|
properties[outName] = shapeManifest['defaults'][key];
|
|
115
209
|
}
|
|
116
210
|
}
|
|
211
|
+
if (((_c = shapeManifest['locked']) === null || _c === void 0 ? void 0 : _c.includes('aspectRatio')) && !properties['AspectRatio']) {
|
|
212
|
+
properties['AspectRatio'] =
|
|
213
|
+
(_d = shapeManifest['defaults']['width'] / shapeManifest['defaults']['height']) !== null && _d !== void 0 ? _d : 1;
|
|
214
|
+
}
|
|
117
215
|
return {
|
|
118
216
|
'class': 'CustomBlock',
|
|
119
217
|
'created': new Date().toISOString(),
|