lucid-package 0.0.55 → 0.0.58

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.55",
3
+ "version": "0.0.58",
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)();
@@ -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>;
@@ -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,97 @@ 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
+ strokeWidth: 0,
72
+ },
73
+ locked: lockedArray,
74
+ };
75
+ shapes.push(manifestShape);
76
+ // create shape file
77
+ const shapeFile = {
78
+ images: {
79
+ imageReference: {
80
+ path: file,
81
+ type: 'file',
82
+ },
83
+ },
84
+ geometry: [
85
+ {
86
+ type: 'rect',
87
+ },
88
+ ],
89
+ style: {
90
+ fill: {
91
+ type: 'image',
92
+ ref: 'imageReference',
93
+ mode: 'stretch',
94
+ },
95
+ },
96
+ };
97
+ fsSync.writeFileSync(path.join(shapeFolder, fileName) + '.shape', JSON.stringify(shapeFile, undefined, 2));
98
+ // copy image
99
+ console.log(`Copying ${curSource} to ${path.join(imageFolder, file)}`);
100
+ (0, filesystemutil_1.copyFileSync)(curSource, path.join(imageFolder, file));
101
+ });
102
+ const manifest = {
103
+ 'name': name,
104
+ 'shapes': shapes,
105
+ };
106
+ fsSync.writeFileSync(path.join('shapelibraries', name, 'library.manifest'), JSON.stringify(manifest, undefined, 2));
107
+ // update extension manifest
108
+ await (0, package_1.modifyManifest)((manifest) => {
109
+ if (!manifest['shapeLibraries']) {
110
+ manifest['shapeLibraries'] = [];
111
+ }
112
+ if (!manifest['shapeLibraries'].some((x) => x.name == name)) {
113
+ manifest['shapeLibraries'].push({
114
+ 'name': name,
115
+ 'product': 'chart',
116
+ 'lcszPath': `shapelibraries/${name}.lcsz`,
117
+ });
118
+ }
119
+ });
120
+ }
121
+ exports.createImageShapeLibrary = createImageShapeLibrary;
29
122
  const defaultNameMap = new Map([
30
123
  ['rounding', 'Rounding'],
31
124
  ['fillColor', 'FillColor'],