@lionweb/cli 0.5.0 → 0.6.0-beta.3

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/README.md CHANGED
@@ -40,6 +40,12 @@ It does some implicit validation as it can error out on incorrect serializations
40
40
 
41
41
  ## Changelog
42
42
 
43
+ ### 0.6.0
44
+
45
+ * Add a `repair` command that aligns a JSON serialization chunk with the specification.
46
+ * Add a `textualize` command – that's optionally language-aware – to render a JSON serialization chunk as pure text.
47
+
48
+
43
49
  ### 0.5.0
44
50
 
45
51
  This is the first version corresponding to a release of LionWeb (version: 2023.1) as a whole.
@@ -1,13 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  import { argv } from "process";
3
- import { extractFromSerialization } from "./serialization-extractor.js";
4
3
  import { diagramFromSerialization } from "./m3/diagram-generator.js";
5
4
  import { generateTsTypesWith } from "./m3/ts-types-generator.js";
5
+ import { extractFromSerialization } from "./serialization/extractor.js";
6
+ import { repairSerializationChunk } from "./serialization/repairer.js";
7
+ import { executeTextualizeCommand } from "./serialization/textualizer.js";
6
8
  const main = (args) => {
7
9
  const DIAGRAM_COMMAND = "diagram";
8
10
  const EXTRACT_COMMAND = "extract";
9
11
  const GENERATE_TS_TYPES_COMMAND = "generate-ts-types";
10
- const commands = [DIAGRAM_COMMAND, EXTRACT_COMMAND, GENERATE_TS_TYPES_COMMAND];
12
+ const REPAIR_COMMAND = "repair";
13
+ const TEXTUALIZE_COMMAND = "textualize";
14
+ const commands = [DIAGRAM_COMMAND, EXTRACT_COMMAND, GENERATE_TS_TYPES_COMMAND, REPAIR_COMMAND, TEXTUALIZE_COMMAND].sort();
11
15
  if (args.length <= 2) {
12
16
  console.log(`lionweb-cli is a LionWeb utility around LionWeb-TypeScript
13
17
 
@@ -34,7 +38,7 @@ ${commands.map((command) => ` ${command}\n`).join(``)}
34
38
  case EXTRACT_COMMAND: {
35
39
  if (commandArgs.length === 0) {
36
40
  console.log(`The ${EXTRACT_COMMAND} command extracts the following from a serialization chunk in the form of files: a sorted JSON, and a shortened JSON.
37
- If the chunk is the serialization of a LionCore Language/M2, then a textual rendering is already output.
41
+ If the chunk is the serialization of a LionCore Language/M2, then a textual rendering is also output.
38
42
  (See the README.md for more information.)`);
39
43
  }
40
44
  else {
@@ -51,6 +55,28 @@ If the chunk is the serialization of a LionCore Language/M2, then a textual rend
51
55
  }
52
56
  return;
53
57
  }
58
+ case REPAIR_COMMAND: {
59
+ if (commandArgs.length === 0) {
60
+ console.log(`The ${REPAIR_COMMAND} command "repairs" the given JSON files that represent serialization chunks.
61
+ Right now, that means that the ordering of the key-value pairs is precisely aligned with the specification.`);
62
+ }
63
+ else {
64
+ commandArgs.forEach(repairSerializationChunk);
65
+ }
66
+ return;
67
+ }
68
+ case TEXTUALIZE_COMMAND: {
69
+ if (commandArgs.length === 0) {
70
+ console.log(`The ${TEXTUALIZE_COMMAND} command produces purely textual renderings of the given serialization chunks.
71
+ Chunks given after a '--language' or '--languages' flag (which are synonyms) are assumed to be serializations of languages.
72
+ These languages are then used to try and resolve the keys of languages' entities and their features to names.
73
+ `);
74
+ }
75
+ else {
76
+ executeTextualizeCommand(commandArgs);
77
+ }
78
+ return;
79
+ }
54
80
  // TODO generate schema, import Ecore
55
81
  default: {
56
82
  console.error(`command "${command}" is not recognized`);
@@ -1 +1 @@
1
- {"version":3,"file":"lionweb-cli.js","sourceRoot":"","sources":["../src/lionweb-cli.ts"],"names":[],"mappings":";AAGA,OAAO,EAAC,IAAI,EAAC,MAAM,SAAS,CAAA;AAE5B,OAAO,EAAC,wBAAwB,EAAC,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAC,wBAAwB,EAAC,MAAM,2BAA2B,CAAA;AAClE,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAA;AAG9D,MAAM,IAAI,GAAG,CAAC,IAAc,EAAC,EAAE;IAE3B,MAAM,eAAe,GAAG,SAAS,CAAA;IACjC,MAAM,eAAe,GAAG,SAAS,C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;QAED,KAAK,kBAAkB,CAAC,CAAC,CAAC;YACtB,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC3B,OAAO,CAAC,GAAG,CAC3B,OAAO,kBAAkB;;;CAGxB,CACgB,CAAA;YACL,CAAC;iBAAM,CAAC;gBACJ,wBAAwB,CAAC,WAAW,CAAC,CAAA;YACzC,CAAC;YACD,OAAM;QACV,CAAC;QACD,sCAAsC;QAEtC,OAAO,CAAC,CAAC,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,YAAY,OAAO,qBAAqB,CAAC,CAAA;QAC3D,CAAC;IACL,CAAC;AAEL,CAAC,CAAA;AAED,IAAI,CAAC,IAAI,CAAC,CAAA"}
@@ -1,2 +1,2 @@
1
1
  export declare const extractFromSerialization: (path: string) => Promise<void>;
2
- //# sourceMappingURL=serialization-extractor.d.ts.map
2
+ //# sourceMappingURL=extractor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../src/serialization/extractor.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,wBAAwB,SAAgB,MAAM,kBAU1D,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { writeFileSync } from "fs";
2
+ import { extname } from "path";
3
+ import { deserializeLanguages } from "@lionweb/core";
4
+ import { languagesAsText, looksLikeSerializedLanguages, readChunk, shortenedSerializationChunk, sortedSerializationChunk, writeJsonAsFile } from "@lionweb/utilities";
5
+ export const extractFromSerialization = async (path) => {
6
+ const chunk = await readChunk(path);
7
+ const extLessPath = path.substring(0, path.length - extname(path).length);
8
+ const sortedJson = sortedSerializationChunk(chunk);
9
+ writeJsonAsFile(extLessPath + ".sorted.json", sortedJson);
10
+ writeJsonAsFile(extLessPath + ".shortened.json", shortenedSerializationChunk(chunk)); // (could also sort)
11
+ if (looksLikeSerializedLanguages(chunk)) {
12
+ writeFileSync(extLessPath + ".txt", languagesAsText(deserializeLanguages(chunk)));
13
+ }
14
+ console.log(`extracted: "${path}" -> ${extLessPath}`);
15
+ };
16
+ //# sourceMappingURL=extractor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../src/serialization/extractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,IAAI,CAAA;AAChC,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAA;AAE5B,OAAO,EAAC,oBAAoB,EAAC,MAAM,eAAe,CAAA;AAClD,OAAO,EACH,eAAe,EACf,4BAA4B,EAC5B,SAAS,EACT,2BAA2B,EAC3B,wBAAwB,EACxB,eAAe,EAClB,MAAM,oBAAoB,CAAA;AAG3B,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;IAC3D,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,CAAA;IACnC,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;IACzE,MAAM,UAAU,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAA;IAClD,eAAe,CAAC,WAAW,GAAG,cAAc,EAAE,UAAU,CAAC,CAAA;IACzD,eAAe,CAAC,WAAW,GAAG,iBAAiB,EAAE,2BAA2B,CAAC,KAAK,CAAC,CAAC,CAAA,CAAG,oBAAoB;IAC3G,IAAI,4BAA4B,CAAC,KAAK,CAAC,EAAE,CAAC;QACtC,aAAa,CAAC,WAAW,GAAG,MAAM,EAAE,eAAe,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACrF,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,QAAQ,WAAW,EAAE,CAAC,CAAA;AACzD,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const repairSerializationChunk: (path: string) => Promise<void>;
2
+ //# sourceMappingURL=repairer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repairer.d.ts","sourceRoot":"","sources":["../../src/serialization/repairer.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,wBAAwB,SAAgB,MAAM,kBAI1D,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { orderedSerializationChunk, readChunk, writeJsonAsFile } from "@lionweb/utilities";
2
+ export const repairSerializationChunk = async (path) => {
3
+ const chunk = await readChunk(path);
4
+ writeJsonAsFile(path, orderedSerializationChunk(chunk));
5
+ console.log(`ordered(/"repaired"): ${path}`);
6
+ };
7
+ //# sourceMappingURL=repairer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repairer.js","sourceRoot":"","sources":["../../src/serialization/repairer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,yBAAyB,EAAE,SAAS,EAAE,eAAe,EAAC,MAAM,oBAAoB,CAAA;AAGxF,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;IAC3D,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,CAAA;IACnC,eAAe,CAAC,IAAI,EAAE,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAA;IACvD,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAA;AAChD,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const executeTextualizeCommand: (args: string[]) => Promise<void>;
2
+ //# sourceMappingURL=textualizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textualizer.d.ts","sourceRoot":"","sources":["../../src/serialization/textualizer.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,wBAAwB,SAAgB,MAAM,EAAE,kBAS5D,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { writeFile } from "fs/promises";
2
+ import { extname } from "path";
3
+ import { genericAsTreeText, readChunk, tryLoadAllAsLanguages } from "@lionweb/utilities";
4
+ export const executeTextualizeCommand = async (args) => {
5
+ const indexLanguageArg = args.findIndex((arg) => arg === "--language" || arg === "--languages");
6
+ const languages = indexLanguageArg > -1
7
+ ? await tryLoadAllAsLanguages(args.slice(indexLanguageArg + 1))
8
+ : [];
9
+ const chunkPaths = args.slice(0, indexLanguageArg > -1 ? indexLanguageArg : undefined);
10
+ chunkPaths.forEach((chunkPath) => {
11
+ textualizeSerializationChunk(chunkPath, languages);
12
+ });
13
+ };
14
+ const textualizeSerializationChunk = async (path, languages = []) => {
15
+ const chunk = await readChunk(path);
16
+ const extLessPath = path.substring(0, path.length - extname(path).length);
17
+ await writeFile(extLessPath + ".txt", genericAsTreeText(chunk, languages));
18
+ console.log(`textualized: ${path}`);
19
+ };
20
+ //# sourceMappingURL=textualizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textualizer.js","sourceRoot":"","sources":["../../src/serialization/textualizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAA;AACrC,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAC,iBAAiB,EAAE,SAAS,EAAE,qBAAqB,EAAC,MAAM,oBAAoB,CAAA;AAItF,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAAE,IAAc,EAAE,EAAE;IAC7D,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,YAAY,IAAI,GAAG,KAAK,aAAa,CAAC,CAAA;IAC/F,MAAM,SAAS,GAAG,gBAAgB,GAAG,CAAC,CAAC;QACnC,CAAC,CAAC,MAAM,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAC;QAC/D,CAAC,CAAC,EAAE,CAAA;IACR,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACtF,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QAC7B,4BAA4B,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IACtD,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AAGD,MAAM,4BAA4B,GAAG,KAAK,EAAE,IAAY,EAAE,YAAwB,EAAE,EAAE,EAAE;IACpF,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,CAAA;IACnC,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;IACzE,MAAM,SAAS,CAAC,WAAW,GAAG,MAAM,EAAE,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAA;IAC1E,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAA;AACvC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lionweb/cli",
3
- "version": "0.5.0",
3
+ "version": "0.6.0-beta.3",
4
4
  "description": "LionWeb CLI for {Java|Type}Script",
5
5
  "bin": {
6
6
  "lionweb-cli": "./dist/lionweb-cli.js"
@@ -18,8 +18,8 @@
18
18
  "url": "https://github.com/LionWeb-io/lionweb-typescript/issues"
19
19
  },
20
20
  "dependencies": {
21
- "@lionweb/core": "0.5.0",
22
- "@lionweb/utilities": "0.5.0"
21
+ "@lionweb/core": "0.6.0-beta.3",
22
+ "@lionweb/utilities": "0.6.0-beta.3"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "20.10.4",
@@ -1 +0,0 @@
1
- {"version":3,"file":"serialization-extractor.d.ts","sourceRoot":"","sources":["../src/serialization-extractor.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,wBAAwB,SAAgB,MAAM,kBAU1D,CAAA"}
@@ -1,22 +0,0 @@
1
- import { writeFileSync } from "fs";
2
- import { extname } from "path";
3
- import { currentSerializationFormatVersion, deserializeLanguages, lioncoreKey } from "@lionweb/core";
4
- import { languagesAsText, readChunk, shortenedSerialization, sortedSerialization, writeJsonAsFile } from "@lionweb/utilities";
5
- const isRecord = (json) => typeof json === "object" && !Array.isArray(json);
6
- const isSerializedLanguages = (json) => isRecord(json)
7
- && json["serializationFormatVersion"] === currentSerializationFormatVersion
8
- && "languages" in json
9
- && Array.isArray(json["languages"])
10
- && json["languages"].some((language) => isRecord(language) && language["key"] === lioncoreKey);
11
- export const extractFromSerialization = async (path) => {
12
- const chunk = await readChunk(path);
13
- const extLessPath = path.substring(0, path.length - extname(path).length);
14
- const sortedJson = sortedSerialization(chunk);
15
- writeJsonAsFile(extLessPath + ".sorted.json", sortedJson);
16
- writeJsonAsFile(extLessPath + ".shortened.json", shortenedSerialization(chunk)); // (could also sort)
17
- if (isSerializedLanguages(chunk)) {
18
- writeFileSync(extLessPath + ".txt", languagesAsText(deserializeLanguages(chunk)));
19
- }
20
- console.log(`extracted: "${path}" -> "${extLessPath}"`);
21
- };
22
- //# sourceMappingURL=serialization-extractor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serialization-extractor.js","sourceRoot":"","sources":["../src/serialization-extractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,IAAI,CAAA;AAChC,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAA;AAE5B,OAAO,EAAC,iCAAiC,EAAE,oBAAoB,EAAE,WAAW,EAAC,MAAM,eAAe,CAAA;AAClG,OAAO,EAAC,eAAe,EAAE,SAAS,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,eAAe,EAAC,MAAM,oBAAoB,CAAA;AAG3H,MAAM,QAAQ,GAAG,CAAC,IAAa,EAAmC,EAAE,CAChE,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AAEpD,MAA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