lucid-package 0.0.48 → 0.0.49

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.48",
3
+ "version": "0.0.49",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -12,4 +12,4 @@ export declare function watchEditorExtension(name: string, isInternalTesting: bo
12
12
  * @param extensionNames The names of the editor extensions
13
13
  * @param quiet If true, will only show errors in output
14
14
  */
15
- export declare function debugEditorExtension(extensionNames: string[], quiet?: boolean): Promise<void>;
15
+ export declare function debugEditorExtension(extensionNames: string[], quiet?: boolean, pickAnyPort?: boolean): Promise<void>;
@@ -88,7 +88,8 @@ exports.watchEditorExtension = watchEditorExtension;
88
88
  * @param extensionNames The names of the editor extensions
89
89
  * @param quiet If true, will only show errors in output
90
90
  */
91
- async function debugEditorExtension(extensionNames, quiet = false) {
91
+ async function debugEditorExtension(extensionNames, quiet = false, pickAnyPort = false) {
92
+ let port = 9900;
92
93
  await Promise.all(extensionNames.map(async (name) => {
93
94
  const child = child_process.spawn(`${process.argv[0]} ${process.argv[1]} watch-editor-extension ${name} ${quiet ? '--quiet ' : ''}`, {
94
95
  stdio: 'inherit',
@@ -127,11 +128,11 @@ async function debugEditorExtension(extensionNames, quiet = false) {
127
128
  app.get(['/editorextension', '/editorextension/:name'], async (req, res) => {
128
129
  var _a;
129
130
  const name = (_a = req.params['name']) !== null && _a !== void 0 ? _a : extensionNames[0];
130
- const rawExtension = await getRawEditorExtension(name);
131
+ const rawExtension = await getRawEditorExtension(name, port);
131
132
  res.send(rawExtension);
132
133
  });
133
134
  app.get('/editorextensions', async (req, res) => {
134
- res.send(await Promise.all(extensionNames.map((name) => getRawEditorExtension(name))));
135
+ res.send(await Promise.all(extensionNames.map((name) => getRawEditorExtension(name, port))));
135
136
  });
136
137
  app.get('/settings', async (req, res) => {
137
138
  var _a;
@@ -167,10 +168,25 @@ async function debugEditorExtension(extensionNames, quiet = false) {
167
168
  res.sendStatus(404);
168
169
  }
169
170
  });
170
- app.listen(9900, 'localhost', () => {
171
- console.log('Listening at http://localhost:9900/extension.js');
172
- });
173
- (0, shapelibrary_1.debugShapeLibraries)();
171
+ const listen = () => {
172
+ app.listen(port, 'localhost', () => {
173
+ console.log('Listening at http://localhost:' + port + '/extension.js');
174
+ (0, shapelibrary_1.debugShapeLibraries)(undefined, pickAnyPort);
175
+ }).on('error', (err) => {
176
+ if (err.code === 'EADDRINUSE') {
177
+ if (pickAnyPort && port < 15000) {
178
+ port++;
179
+ listen();
180
+ }
181
+ else {
182
+ console.error('Failed to listen for extension');
183
+ console.error(err);
184
+ process.exit(1);
185
+ }
186
+ }
187
+ });
188
+ };
189
+ listen();
174
190
  }
175
191
  exports.debugEditorExtension = debugEditorExtension;
176
192
  async function getExtensionManifest(name) {
@@ -202,7 +218,7 @@ async function getExtensionCodeDirectoryNameFromCodePath(codePath) {
202
218
  }
203
219
  return undefined;
204
220
  }
205
- async function getRawEditorExtension(name) {
221
+ async function getRawEditorExtension(name, port) {
206
222
  var _a, _b, _c;
207
223
  const { manifest, extensionManifest } = await getExtensionManifest(name);
208
224
  const codePath = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['codePath'];
@@ -219,7 +235,7 @@ async function getRawEditorExtension(name) {
219
235
  title: (_c = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['title']) !== null && _c !== void 0 ? _c : 'Local dev extension',
220
236
  products: products,
221
237
  scopes: extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['scopes'],
222
- codeUrl: `http://localhost:9900/editorextension/${directory}/extension.js`,
238
+ codeUrl: `http://localhost:${port}/editorextension/${directory}/extension.js`,
223
239
  };
224
240
  }
225
241
  function getExtensionProducts(product, products) {
package/src/index.js CHANGED
@@ -62,6 +62,11 @@ class LucidSuiteExtensionCLI {
62
62
  action: 'store_true',
63
63
  help: argparse_1.SUPPRESS,
64
64
  });
65
+ testExtensionParser.add_argument('--anyport', {
66
+ default: false,
67
+ action: 'store_true',
68
+ help: argparse_1.SUPPRESS,
69
+ });
65
70
  const watchExtensionParser = subparsers.add_parser('watch-editor-extension', {
66
71
  help: 'Compile an editor extension in debug mode',
67
72
  });
@@ -151,7 +156,7 @@ class LucidSuiteExtensionCLI {
151
156
  break;
152
157
  case 'test-editor-extension':
153
158
  if ((0, package_1.currentlyInPackage)()) {
154
- await (0, editorextension_1.debugEditorExtension)(parsed['name'], parsed['quiet']);
159
+ await (0, editorextension_1.debugEditorExtension)(parsed['name'], parsed['quiet'], parsed['anyport']);
155
160
  }
156
161
  else {
157
162
  console.error('Not currently in a Lucid extension package folder');
@@ -1,4 +1,4 @@
1
1
  export declare function createEmptyShapeLibrary(name: string): Promise<void>;
2
- export declare function getShapeListJson(name: string, packagePath: string): Promise<string>;
2
+ export declare function getShapeListJson(name: string, packagePath: string, port?: number): Promise<string>;
3
3
  export declare function buildShapeLibrary(name: string): Promise<void>;
4
- export declare function debugShapeLibraries(packagePath?: string): Promise<void>;
4
+ export declare function debugShapeLibraries(packagePath?: string, pickAnyPort?: boolean): Promise<void>;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.debugShapeLibraries = exports.buildShapeLibrary = exports.getShapeListJson = exports.createEmptyShapeLibrary = void 0;
4
4
  const express = require("express");
5
5
  const fs = require("fs/promises");
6
- const http = require("http");
7
6
  const JSZip = require("jszip");
8
7
  const path = require("path");
9
8
  const filesystemutil_1 = require("./filesystemutil");
@@ -37,7 +36,7 @@ const defaultNameMap = new Map([
37
36
  ]);
38
37
  //Produce JSON equivalent to the document service's
39
38
  // /shapeLibraries/:name/shapes endpoint
40
- async function getShapeListJson(name, packagePath) {
39
+ async function getShapeListJson(name, packagePath, port = 9901) {
41
40
  const packageManifest = await (0, packagemanifest_1.readManifest)('local', packagePath + '/');
42
41
  const rawManifest = await fs.readFile(packagePath + `/shapelibraries/${name}/library.manifest`);
43
42
  const manifest = hjson.parse(rawManifest.toString());
@@ -101,7 +100,7 @@ async function getShapeListJson(name, packagePath) {
101
100
  }
102
101
  else if (imageMap[key]['type'] == 'file') {
103
102
  finalImageMap[key] =
104
- 'http://localhost:9901/shapeLibraries/' +
103
+ `http://localhost:${port}/shapeLibraries/` +
105
104
  encodeURIComponent(name) +
106
105
  '/images/' +
107
106
  encodeURIComponent(imageMap[key]['path']);
@@ -121,8 +120,8 @@ async function getShapeListJson(name, packagePath) {
121
120
  'name': shapeManifest['name'],
122
121
  'order': index,
123
122
  'properties': JSON.stringify(properties),
124
- 'shapeLibrary': 'http://localhost:9901/shapeLibraries/' + encodeURIComponent(name),
125
- 'uri': `http://localhost:9901/shapeLibraries/${encodeURIComponent(name)}/shapes/${encodeURIComponent(shapeName)}`,
123
+ 'shapeLibrary': `http://localhost:${port}/shapeLibraries/` + encodeURIComponent(name),
124
+ 'uri': `http://localhost:${port}/shapeLibraries/${encodeURIComponent(name)}/shapes/${encodeURIComponent(shapeName)}`,
126
125
  };
127
126
  })));
128
127
  }
@@ -148,7 +147,8 @@ async function buildShapeLibrary(name) {
148
147
  await fs.writeFile(`shapelibraries/${name}.lcsz`, zipBytes);
149
148
  }
150
149
  exports.buildShapeLibrary = buildShapeLibrary;
151
- async function debugShapeLibraries(packagePath = '.') {
150
+ async function debugShapeLibraries(packagePath = '.', pickAnyPort = false) {
151
+ let port = 9901;
152
152
  const app = express();
153
153
  app.use((req, res, next) => {
154
154
  res.header('Access-Control-Allow-Origin', '*');
@@ -167,7 +167,7 @@ async function debugShapeLibraries(packagePath = '.') {
167
167
  const libraryDefinitionContent = await fs.readFile(packagePath + '/shapelibraries/' + libraryManifest['name'] + '/library.manifest');
168
168
  const libraryDefinition = JSON.parse(libraryDefinitionContent.toString());
169
169
  return {
170
- 'uri': 'http://localhost:9901/shapeLibraries/' +
170
+ 'uri': `http://localhost:${port}/shapeLibraries/` +
171
171
  encodeURIComponent(libraryManifest['name']) +
172
172
  '?version=' +
173
173
  shapeLibraryVersion,
@@ -176,7 +176,7 @@ async function debugShapeLibraries(packagePath = '.') {
176
176
  'name': libraryDefinition['name'],
177
177
  'size': 0,
178
178
  'accountId': 0,
179
- 'shapes': 'http://localhost:9901/shapeLibraries/' +
179
+ 'shapes': `http://localhost:${port}/shapeLibraries/` +
180
180
  encodeURIComponent(libraryManifest['name']) +
181
181
  '/shapes',
182
182
  'shared': false,
@@ -188,7 +188,7 @@ async function debugShapeLibraries(packagePath = '.') {
188
188
  });
189
189
  app.get('/shapeLibraries/:libraryName/shapes', async (req, res) => {
190
190
  //Find all the shapes in the given shape library, and produce JSON for the client
191
- res.send(await getShapeListJson(req.params.libraryName, packagePath));
191
+ res.send(await getShapeListJson(req.params.libraryName, packagePath, port));
192
192
  });
193
193
  app.get('/shapeLibraries/:libraryName/images/:image', async (req, res) => {
194
194
  const oldcwd = process.cwd();
@@ -200,21 +200,36 @@ async function debugShapeLibraries(packagePath = '.') {
200
200
  process.chdir(oldcwd);
201
201
  });
202
202
  app.get('/shapeLibraries/');
203
- const server = http.createServer(app);
204
- //Watch for any shape library changes, and inform watchers that they need to refresh them.
205
- const wss = new ws.Server({ server, path: '/shapeLibraries/changes' });
206
- const sockets = [];
207
- wss.on('connection', (ws) => {
208
- sockets.push(ws);
209
- });
210
- chokidar.watch(packagePath + '/shapelibraries').on('all', () => {
211
- shapeLibraryVersion = Date.now();
212
- for (const socket of sockets) {
213
- socket.send('refresh');
214
- }
215
- });
216
- server.listen(9901, 'localhost', () => {
217
- console.log('Listening at http://localhost:9901/shapeLibraries');
218
- });
203
+ const listen = () => {
204
+ const server = app.listen(port, 'localhost', () => {
205
+ console.log('Listening at http://localhost:' + port + '/shapeLibraries');
206
+ //Watch for any shape library changes, and inform watchers that they need to refresh them.
207
+ const wss = new ws.Server({ server, path: '/shapeLibraries/changes' });
208
+ const sockets = [];
209
+ wss.on('connection', (ws) => {
210
+ sockets.push(ws);
211
+ });
212
+ chokidar.watch(packagePath + '/shapelibraries').on('all', () => {
213
+ shapeLibraryVersion = Date.now();
214
+ for (const socket of sockets) {
215
+ socket.send('refresh');
216
+ }
217
+ });
218
+ });
219
+ server.on('error', (err) => {
220
+ if (err.code === 'EADDRINUSE') {
221
+ if (pickAnyPort && port < 15000) {
222
+ port++;
223
+ listen();
224
+ }
225
+ else {
226
+ console.error('Failed to listen for shapes');
227
+ console.error(err);
228
+ process.exit(1);
229
+ }
230
+ }
231
+ });
232
+ };
233
+ listen();
219
234
  }
220
235
  exports.debugShapeLibraries = debugShapeLibraries;