@tutao/licc 3.98.12 → 3.98.13

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/dist/cli.js CHANGED
@@ -1,83 +0,0 @@
1
- #!/usr/bin/env node
2
- import { generate } from "./index.js";
3
- import * as fs from "fs";
4
- import * as path from "path";
5
- import { globby } from "zx";
6
- import { Argument, Option, program } from "commander";
7
- const PLATFORMS = ["ios", "web", "android", "desktop"];
8
- const USAGE = `licc [options] from_dir to_dir
9
-
10
- will recursively take all JSON files from \`from-dir\` and compile them.
11
- output files are written into \`to-dir\`, without preserving subdirectory structure.`;
12
- await program
13
- .usage(USAGE)
14
- .addArgument(new Argument("from_dir").argRequired())
15
- .addArgument(new Argument("to_dir").argOptional())
16
- .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.')
17
- .makeOptionMandatory(false)
18
- .choices(PLATFORMS))
19
- .action(async (from_dir, to_dir, { platform }) => {
20
- 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.");
21
- 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.");
22
- let conf = {};
23
- if (platform != null) {
24
- conf[platform] = path.resolve(process.cwd(), to_dir);
25
- }
26
- else {
27
- // check if there's a .liccc file that states the desired platforms and output dirs
28
- const confPath = path.join(from_dir, ".liccc");
29
- try {
30
- const relConf = JSON.parse(await fs.promises.readFile(confPath, { encoding: "utf-8" }));
31
- for (let [relPlatform, relPath] of Object.entries(relConf)) {
32
- if (relPlatform === "__comment")
33
- continue;
34
- assert(PLATFORMS.includes(relPlatform), `invalid platform in .liccc: ${relPlatform}`);
35
- conf[relPlatform] = path.resolve(process.cwd(), from_dir, relPath);
36
- }
37
- }
38
- catch (e) {
39
- console.log(`unable to read ${confPath} as JSON: ${e}`);
40
- process.exit(1);
41
- }
42
- }
43
- await run(from_dir, conf);
44
- })
45
- .parseAsync(process.argv);
46
- async function run(from_dir, conf) {
47
- const inputFiles = await globby(path.join(process.cwd(), from_dir, "*/**/*.json"));
48
- const inputMap = new Map(inputFiles.map((n) => ([path.basename(n, ".json"), fs.readFileSync(n, "utf8")])));
49
- // doing it here because some platforms generate into the same dir.
50
- for (let outDir of Object.values(conf)) {
51
- clearDir(outDir);
52
- }
53
- for (let [confPlatform, confOutDir] of Object.entries(conf)) {
54
- console.log("generating for", confPlatform, "into", confOutDir);
55
- try {
56
- await generate(confPlatform, inputMap, confOutDir);
57
- }
58
- catch (e) {
59
- assert(false, `compilation failed with ${e}`);
60
- }
61
- console.log("done; no errors\n");
62
- }
63
- }
64
- function assert(proposition, text) {
65
- if (proposition)
66
- return;
67
- console.log("\nFatal Error:\n", text);
68
- console.log("");
69
- console.log(program.helpInformation());
70
- process.exit(1);
71
- }
72
- function clearDir(dir) {
73
- console.log("clearing dir:", dir);
74
- try {
75
- const files = fs.readdirSync(dir);
76
- for (const file of files) {
77
- fs.unlinkSync(path.join(dir, file));
78
- }
79
- }
80
- catch (e) {
81
- console.log("could not clear dir:", e);
82
- }
83
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tutao/licc",
3
- "version": "3.98.12",
3
+ "version": "3.98.13",
4
4
  "bin": {
5
5
  "licc": "dist/cli.js"
6
6
  },
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "build": "tsc -b",
12
12
  "test": "rm -rf ./test/build && tsc -b test && cd test/build && node test/Suite.js",
13
- "preinstall": "mkdir -p dist && touch dist/cli.js"
13
+ "preinstall": "node preinstall.js"
14
14
  },
15
15
  "author": "",
16
16
  "license": "GPL-3.0",
@@ -19,7 +19,7 @@
19
19
  "commander": "9.3.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@tutao/tutanota-test-utils": "3.98.12",
22
+ "@tutao/tutanota-test-utils": "3.98.13",
23
23
  "ospec": "https://github.com/tutao/ospec.git#0472107629ede33be4c4d19e89f237a6d7b0cb11"
24
24
  }
25
25
  }
package/preinstall.js ADDED
@@ -0,0 +1,9 @@
1
+ /** @file little script to prepare licc install. Implemented as a node script to please Windows. */
2
+ import * as fs from "fs"
3
+
4
+ // mkdir -p dist
5
+ fs.mkdirSync("dist", {recursive: true})
6
+ // touch dist/cli.js
7
+ fs.closeSync(fs.openSync("dist/cli.js", 'w'))
8
+
9
+