@tilua/compiler 4.0.0 → 5.0.0

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,18 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- bundle
4
- } from "./chunk-VZ7XC4BG.js";
3
+ bundle,
4
+ resolveConfig
5
+ } from "./chunk-3J2QMA4W.js";
5
6
 
6
7
  // src/cli.ts
7
- import { writeFileSync } from "fs";
8
- import { relative } from "path";
9
- var usage = "usage: tilua <entry> [--out <file>] [--config <tilua.config.json>] [--noCheck] [--target luau|lua51]";
8
+ import { mkdirSync, writeFileSync } from "fs";
9
+ import { basename, dirname, join, relative, resolve } from "path";
10
+ var usage = "usage: tilua <entry> [--out <file>] [--output single|chunks|modules] [--config <tilua.config.json>] [--noCheck] [--target luau|lua51]";
10
11
  var args = process.argv.slice(2);
11
12
  var entry;
12
13
  var out;
13
14
  var config;
14
15
  var typeCheck = true;
15
16
  var buildTarget;
17
+ var output;
16
18
  for (let i = 0; i < args.length; i++) {
17
19
  const arg = args[i];
18
20
  if (arg === "--out") out = args[++i];
@@ -25,6 +27,13 @@ for (let i = 0; i < args.length; i++) {
25
27
  process.exit(2);
26
28
  }
27
29
  buildTarget = value;
30
+ } else if (arg === "--output") {
31
+ const value = args[++i];
32
+ if (value !== "single" && value !== "chunks" && value !== "modules") {
33
+ console.error(`--output must be 'single', 'chunks' or 'modules', not '${value}'`);
34
+ process.exit(2);
35
+ }
36
+ output = value;
28
37
  } else if (arg === "--help" || arg === "-h") {
29
38
  console.log(usage);
30
39
  process.exit(0);
@@ -35,7 +44,18 @@ if (!entry) {
35
44
  process.exit(2);
36
45
  }
37
46
  async function main(from) {
38
- const result = await bundle({ entry: from, config, typeCheck, target: buildTarget });
47
+ const found = resolveConfig(config, resolve(from)).config;
48
+ const mode = output ?? found?.output ?? "single";
49
+ const entryFile = mode === "modules" ? void 0 : out ?? from.replace(/\.tilua$/, "") + ".luau";
50
+ const folder = entryFile !== void 0 ? dirname(entryFile) : out ?? found?.directory ?? dirname(from);
51
+ const result = await bundle({
52
+ entry: from,
53
+ config,
54
+ typeCheck,
55
+ target: buildTarget,
56
+ output: mode,
57
+ outFile: entryFile !== void 0 ? basename(entryFile) : void 0
58
+ });
39
59
  for (const d of result.diagnostics) {
40
60
  console.error(`${relative(process.cwd(), d.file)}:${d.line}:${d.column} ${d.message}`);
41
61
  }
@@ -43,9 +63,12 @@ async function main(from) {
43
63
  console.error("no bundle written");
44
64
  process.exit(1);
45
65
  }
46
- const target = out ?? from.replace(/\.tilua$/, "") + ".luau";
47
- writeFileSync(target, result.code);
48
- console.log(`${target}: ${result.modules.length} module${result.modules.length === 1 ? "" : "s"}`);
66
+ for (const file of result.files) {
67
+ const target = join(folder, file.path);
68
+ mkdirSync(dirname(target), { recursive: true });
69
+ writeFileSync(target, file.code);
70
+ console.log(`${target}: ${file.modules.length} module${file.modules.length === 1 ? "" : "s"}`);
71
+ }
49
72
  process.exit(result.diagnostics.length ? 1 : 0);
50
73
  }
51
74
  main(entry).catch((error) => {