@tutao/licc 3.118.30 → 3.118.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.
Files changed (2) hide show
  1. package/dist/cli.js +0 -84
  2. package/package.json +3 -3
package/dist/cli.js CHANGED
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env node
2
- import { generate } from "./index.js";
3
- import * as fs from "node:fs";
4
- import * as path from "node:path";
5
- import { globby } from "zx";
6
- import { Argument, Option, program } from "commander";
7
- import JSON5 from "json5";
8
- const PLATFORMS = ["ios", "web", "android", "desktop"];
9
- const USAGE = `licc [options] from_dir to_dir
10
-
11
- will recursively take all JSON files from \`from-dir\` and compile them.
12
- output files are written into \`to-dir\`, without preserving subdirectory structure.`;
13
- await program
14
- .usage(USAGE)
15
- .addArgument(new Argument("from_dir").argRequired())
16
- .addArgument(new Argument("to_dir").argOptional())
17
- .addOption(new Option("-p, --platform <platform>", "platform to generate code for. if not specified, from_dir must be omitted as well. In this case, licc will read <from_dir>/.liccc as a json map from platform to output dir. if -p is set, from_dir must be set as well.")
18
- .makeOptionMandatory(false)
19
- .choices(PLATFORMS))
20
- .action(async (from_dir, to_dir, { platform }) => {
21
- assert(!(platform == null && to_dir != null), "can't omit platform and use an explicit output dir. specify both -p <platform> and to_dir or none of them.");
22
- assert(!(platform != null && to_dir == null), "can't use an explicit platform but no output dir. specify both -p <platform> and to_dir or none of them.");
23
- let conf = {};
24
- if (platform != null) {
25
- conf[platform] = path.resolve(process.cwd(), to_dir);
26
- }
27
- else {
28
- // check if there's a .liccc file that states the desired platforms and output dirs
29
- const confPath = path.join(from_dir, ".liccc");
30
- try {
31
- const relConf = JSON5.parse(await fs.promises.readFile(confPath, { encoding: "utf-8" }));
32
- for (let [relPlatform, relPath] of Object.entries(relConf)) {
33
- if (relPlatform === "__comment")
34
- continue;
35
- assert(PLATFORMS.includes(relPlatform), `invalid platform in .liccc: ${relPlatform}`);
36
- conf[relPlatform] = path.resolve(process.cwd(), from_dir, relPath);
37
- }
38
- }
39
- catch (e) {
40
- console.log(`unable to read ${confPath} as JSON: ${e}`);
41
- process.exit(1);
42
- }
43
- }
44
- await run(from_dir, conf);
45
- })
46
- .parseAsync(process.argv);
47
- async function run(from_dir, conf) {
48
- const inputFiles = await globby(["*/**/*.json", "*/**/*.json5"].map((glob) => path.join(process.cwd(), from_dir, glob)));
49
- const inputMap = new Map(inputFiles.map((n) => [path.basename(n, n.endsWith("5") ? ".json5" : ".json"), fs.readFileSync(n, "utf8")]));
50
- // doing it here because some platforms generate into the same dir.
51
- for (let outDir of Object.values(conf)) {
52
- clearDir(outDir);
53
- }
54
- for (let [confPlatform, confOutDir] of Object.entries(conf)) {
55
- console.log("generating for", confPlatform, "into", confOutDir);
56
- try {
57
- await generate(confPlatform, inputMap, confOutDir);
58
- }
59
- catch (e) {
60
- assert(false, `compilation failed with ${e}`);
61
- }
62
- console.log("done; no errors\n");
63
- }
64
- }
65
- function assert(proposition, text) {
66
- if (proposition)
67
- return;
68
- console.log("\nFatal Error:\n", text);
69
- console.log("");
70
- console.log(program.helpInformation());
71
- process.exit(1);
72
- }
73
- function clearDir(dir) {
74
- console.log("clearing dir:", dir);
75
- try {
76
- const files = fs.readdirSync(dir);
77
- for (const file of files) {
78
- fs.unlinkSync(path.join(dir, file));
79
- }
80
- }
81
- catch (e) {
82
- console.log("could not clear dir:", e);
83
- }
84
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tutao/licc",
3
- "version": "3.118.30",
3
+ "version": "3.118.31",
4
4
  "bin": {
5
5
  "licc": "dist/cli.js"
6
6
  },
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "devDependencies": {
23
23
  "typescript": "5.0.3",
24
- "@tutao/tutanota-test-utils": "3.118.30",
25
- "@tutao/otest": "3.118.30"
24
+ "@tutao/tutanota-test-utils": "3.118.31",
25
+ "@tutao/otest": "3.118.31"
26
26
  }
27
27
  }