lucid-package 0.0.30 → 0.0.31

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.30",
3
+ "version": "0.0.31",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -114,12 +114,12 @@ async function debugEditorExtension(extensionNames, quiet = false) {
114
114
  app.get(['/scopes', '/editorextension/:name/scopes'], async (req, res) => {
115
115
  var _a, _b, _c;
116
116
  const name = (_a = req.params['name']) !== null && _a !== void 0 ? _a : extensionNames[0];
117
- const manifest = await (0, packagemanifest_1.readManifest)(true);
117
+ const manifest = await (0, packagemanifest_1.readManifest)('local');
118
118
  res.send(JSON.stringify((_c = (_b = manifest['extensions']) === null || _b === void 0 ? void 0 : _b.find((extension) => extension['name'] === name)) === null || _c === void 0 ? void 0 : _c.scopes));
119
119
  });
120
120
  app.get('/packageId', async (req, res) => {
121
121
  var _a;
122
- const manifest = await (0, packagemanifest_1.readManifest)(true);
122
+ const manifest = await (0, packagemanifest_1.readManifest)('local');
123
123
  res.send((_a = manifest['id']) !== null && _a !== void 0 ? _a : '__local__');
124
124
  });
125
125
  app.get(['/editorextension', '/editorextension/:name'], async (req, res) => {
@@ -135,7 +135,7 @@ async function debugEditorExtension(extensionNames, quiet = false) {
135
135
  var _a;
136
136
  const name = req.params['name'];
137
137
  if (name) {
138
- const manifest = await (0, packagemanifest_1.readManifest)(true);
138
+ const manifest = await (0, packagemanifest_1.readManifest)('local');
139
139
  const provider = (_a = manifest['oauthProviders']) === null || _a === void 0 ? void 0 : _a.find((one) => one.name === name);
140
140
  if (provider && oldFs.existsSync(`${name}.credentials.local`)) {
141
141
  const credentials = JSON.parse((await fs.readFile(`${name}.credentials.local`)).toString());
@@ -157,7 +157,7 @@ async function debugEditorExtension(extensionNames, quiet = false) {
157
157
  exports.debugEditorExtension = debugEditorExtension;
158
158
  async function getRawEditorExtension(name) {
159
159
  var _a, _b, _c, _d;
160
- const manifest = await (0, packagemanifest_1.readManifest)(true);
160
+ const manifest = await (0, packagemanifest_1.readManifest)('local');
161
161
  const extensionManifest = (_a = manifest['extensions']) === null || _a === void 0 ? void 0 : _a.find((one) => one['name'] === name);
162
162
  return {
163
163
  id: '__local__',
package/src/index.js CHANGED
@@ -29,6 +29,9 @@ class LucidSuiteExtensionCLI {
29
29
  action: 'store_true',
30
30
  help: argparse_1.SUPPRESS,
31
31
  });
32
+ packageParser.add_argument('--env', {
33
+ help: 'Provide the environment to define which manifest.<env>.json is combined with manifest.json when bundling. If not provided, uses manifest.json only.',
34
+ });
32
35
  const updateSDKParser = subparsers.add_parser('update-sdk', {
33
36
  help: 'Update the editor extension SDK to the latest published version for all editor extensions in this package',
34
37
  });
@@ -95,7 +98,7 @@ class LucidSuiteExtensionCLI {
95
98
  break;
96
99
  case 'bundle':
97
100
  if ((0, package_1.currentlyInPackage)()) {
98
- await (0, package_1.writePackage)(parsed['quiet']);
101
+ await (0, package_1.writePackage)(parsed['quiet'], parsed['env']);
99
102
  }
100
103
  else {
101
104
  console.error('Not currently in a Lucid extension package folder');
package/src/package.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import { PackageManifest } from './packagemanifest';
2
2
  export declare function createEmptyPackage(root: string): Promise<void>;
3
3
  export declare function currentlyInPackage(): boolean;
4
- export declare function modifyManifest(callback: (manifest: PackageManifest) => void | Promise<void>): Promise<void>;
4
+ export declare function modifyManifest(callback: (manifest: PackageManifest) => void | Promise<void>, manifestOverrideEnv?: string): Promise<void>;
5
5
  export declare function updateAllExtensionSDK(): Promise<void>;
6
- export declare function writePackage(quiet?: boolean): Promise<void>;
6
+ /**
7
+ *
8
+ * @param manifestOverrideEnv The environment definine what manifest to read from. `manifest.env.json`
9
+ */
10
+ export declare function writePackage(quiet?: boolean, manifestOverrideEnv?: string): Promise<void>;
package/src/package.js CHANGED
@@ -19,14 +19,14 @@ function currentlyInPackage() {
19
19
  }
20
20
  exports.currentlyInPackage = currentlyInPackage;
21
21
  const allScopes = new Set(['DOWNLOAD', 'NETWORK', 'READ', 'SHOW_MODAL', 'CUSTOM_UI', 'WRITE']);
22
- async function modifyManifest(callback) {
23
- const manifest = await (0, packagemanifest_1.readManifest)(false);
22
+ async function modifyManifest(callback, manifestOverrideEnv) {
23
+ const manifest = await (0, packagemanifest_1.readManifest)(manifestOverrideEnv);
24
24
  await callback(manifest);
25
25
  await fs.writeFile('manifest.json', JSON.stringify(manifest, undefined, 2));
26
26
  }
27
27
  exports.modifyManifest = modifyManifest;
28
28
  async function updateAllExtensionSDK() {
29
- const manifest = await (0, packagemanifest_1.readManifest)(false);
29
+ const manifest = await (0, packagemanifest_1.readManifest)();
30
30
  for (const extension of manifest['extensions'] || []) {
31
31
  const parts = extension['codePath'].split('/');
32
32
  if (parts[0] === 'editorextensions') {
@@ -35,7 +35,11 @@ async function updateAllExtensionSDK() {
35
35
  }
36
36
  }
37
37
  exports.updateAllExtensionSDK = updateAllExtensionSDK;
38
- async function writePackage(quiet = false) {
38
+ /**
39
+ *
40
+ * @param manifestOverrideEnv The environment definine what manifest to read from. `manifest.env.json`
41
+ */
42
+ async function writePackage(quiet = false, manifestOverrideEnv) {
39
43
  const zip = new JSZip();
40
44
  //Increment the patch number automatically on each build
41
45
  await modifyManifest(async (manifest) => {
@@ -84,7 +88,8 @@ async function writePackage(quiet = false) {
84
88
  //Write out the zip file
85
89
  const zipBytes = await zip.generateAsync({ type: 'uint8array' });
86
90
  console.log('Writing file package.zip');
87
- await fs.writeFile('package.zip', zipBytes);
88
- });
91
+ const fileName = `package${manifestOverrideEnv ? `-${manifestOverrideEnv}` : ''}.zip`;
92
+ await fs.writeFile(fileName, zipBytes);
93
+ }, manifestOverrideEnv);
89
94
  }
90
95
  exports.writePackage = writePackage;
@@ -28,4 +28,8 @@ export declare type PackageManifest = {
28
28
  'callbackEvents': string[];
29
29
  }[];
30
30
  };
31
- export declare function readManifest(includeLocalOverrides: boolean, path?: string): Promise<PackageManifest>;
31
+ /**
32
+ * @param manifestOverrideEnv The environment to override the manifest with
33
+ * @param path The path to read the manifest from
34
+ */
35
+ export declare function readManifest(manifestOverrideEnv?: string, path?: string): Promise<PackageManifest>;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readManifest = void 0;
4
- const fs = require("fs/promises");
4
+ const fs = require("fs");
5
+ const fsPromises = require("fs/promises");
5
6
  const checks_1 = require("lucid-extension-sdk/sdk/core/checks");
6
7
  const versionRegex = /^\d+\.\d+\.\d+$/;
7
8
  function validateManifestOrThrow(manifest) {
@@ -133,16 +134,28 @@ function deepMixin(target, mixin) {
133
134
  }
134
135
  }
135
136
  }
136
- async function readManifest(includeLocalOverrides, path = './') {
137
- const raw = JSON.parse((await fs.readFile(path + 'manifest.json')).toString());
138
- if (includeLocalOverrides) {
137
+ /**
138
+ * @param manifestOverrideEnv The environment to override the manifest with
139
+ * @param path The path to read the manifest from
140
+ */
141
+ async function readManifest(manifestOverrideEnv, path = './') {
142
+ const raw = JSON.parse((await fsPromises.readFile(path + 'manifest.json')).toString());
143
+ if (manifestOverrideEnv) {
144
+ const manifestOverridePath = path + `manifest.${manifestOverrideEnv}.json`;
139
145
  try {
140
- const overrides = JSON.parse((await fs.readFile(path + 'manifest.local.json')).toString());
146
+ const overrides = JSON.parse((await fsPromises.readFile(manifestOverridePath)).toString());
141
147
  deepMixin(raw, overrides);
142
148
  }
143
149
  catch (e) {
144
- //No need to do anything; local overrides are just invalid
145
- console.warn('Local manifest overrides could not be applied', e);
150
+ if (manifestOverrideEnv == 'local') {
151
+ // Warn if the file exists (this means it's invalid), otherwise fail silently
152
+ if (fs.existsSync(manifestOverridePath)) {
153
+ console.warn('Local manifest overrides could not be applied', e);
154
+ }
155
+ }
156
+ else {
157
+ throw new Error(`Missing or malformated \"manifest.${manifestOverrideEnv}.json\". Please create and run the command again.`);
158
+ }
146
159
  }
147
160
  }
148
161
  validateManifestOrThrow(raw);
@@ -38,7 +38,7 @@ const defaultNameMap = new Map([
38
38
  //Produce JSON equivalent to the document service's
39
39
  // /shapeLibraries/:name/shapes endpoint
40
40
  async function getShapeListJson(name, packagePath) {
41
- const packageManifest = await (0, packagemanifest_1.readManifest)(true, packagePath + '/');
41
+ const packageManifest = await (0, packagemanifest_1.readManifest)('local', packagePath + '/');
42
42
  const rawManifest = await fs.readFile(packagePath + `/shapelibraries/${name}/library.manifest`);
43
43
  const manifest = hjson.parse(rawManifest.toString());
44
44
  const usedNames = new Set(manifest['shapes'].map((shape) => shape['key']).filter((key) => key !== undefined));
@@ -161,7 +161,7 @@ async function debugShapeLibraries(packagePath = '.') {
161
161
  let shapeLibraryVersion = Date.now();
162
162
  app.get('/shapeLibraries', async (req, res) => {
163
163
  var _a;
164
- const manifest = await (0, packagemanifest_1.readManifest)(true, packagePath + '/');
164
+ const manifest = await (0, packagemanifest_1.readManifest)('local', packagePath + '/');
165
165
  const libraries = (_a = manifest['shapeLibraries']) !== null && _a !== void 0 ? _a : [];
166
166
  const output = await Promise.all(libraries.map(async (libraryManifest) => {
167
167
  const libraryDefinitionContent = await fs.readFile(packagePath + '/shapelibraries/' + libraryManifest['name'] + '/library.manifest');