@xessa/cli 0.0.0-stage → 0.1.1

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 (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -2
  3. package/dist/args.d.ts +43 -0
  4. package/dist/args.d.ts.map +1 -0
  5. package/dist/args.js +202 -0
  6. package/dist/args.js.map +1 -0
  7. package/dist/commands/build.d.ts +44 -0
  8. package/dist/commands/build.d.ts.map +1 -0
  9. package/dist/commands/build.js +533 -0
  10. package/dist/commands/build.js.map +1 -0
  11. package/dist/commands/check.d.ts +11 -0
  12. package/dist/commands/check.d.ts.map +1 -0
  13. package/dist/commands/check.js +35 -0
  14. package/dist/commands/check.js.map +1 -0
  15. package/dist/commands/clean.d.ts +12 -0
  16. package/dist/commands/clean.d.ts.map +1 -0
  17. package/dist/commands/clean.js +140 -0
  18. package/dist/commands/clean.js.map +1 -0
  19. package/dist/commands/format.d.ts +41 -0
  20. package/dist/commands/format.d.ts.map +1 -0
  21. package/dist/commands/format.js +127 -0
  22. package/dist/commands/format.js.map +1 -0
  23. package/dist/commands/watch.d.ts +38 -0
  24. package/dist/commands/watch.d.ts.map +1 -0
  25. package/dist/commands/watch.js +338 -0
  26. package/dist/commands/watch.js.map +1 -0
  27. package/dist/compiler.d.ts +20 -0
  28. package/dist/compiler.d.ts.map +1 -0
  29. package/dist/compiler.js +57 -0
  30. package/dist/compiler.js.map +1 -0
  31. package/dist/config.d.ts +93 -0
  32. package/dist/config.d.ts.map +1 -0
  33. package/dist/config.js +331 -0
  34. package/dist/config.js.map +1 -0
  35. package/dist/formatter.d.ts +21 -0
  36. package/dist/formatter.d.ts.map +1 -0
  37. package/dist/formatter.js +38 -0
  38. package/dist/formatter.js.map +1 -0
  39. package/dist/glob.d.ts +52 -0
  40. package/dist/glob.d.ts.map +1 -0
  41. package/dist/glob.js +214 -0
  42. package/dist/glob.js.map +1 -0
  43. package/dist/index.d.ts +34 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +114 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/manifest.d.ts +56 -0
  48. package/dist/manifest.d.ts.map +1 -0
  49. package/dist/manifest.js +138 -0
  50. package/dist/manifest.js.map +1 -0
  51. package/dist/paths.d.ts +24 -0
  52. package/dist/paths.d.ts.map +1 -0
  53. package/dist/paths.js +42 -0
  54. package/dist/paths.js.map +1 -0
  55. package/dist/project.d.ts +44 -0
  56. package/dist/project.d.ts.map +1 -0
  57. package/dist/project.js +92 -0
  58. package/dist/project.js.map +1 -0
  59. package/dist/report.d.ts +128 -0
  60. package/dist/report.d.ts.map +1 -0
  61. package/dist/report.js +128 -0
  62. package/dist/report.js.map +1 -0
  63. package/dist/setup.d.ts +58 -0
  64. package/dist/setup.d.ts.map +1 -0
  65. package/dist/setup.js +181 -0
  66. package/dist/setup.js.map +1 -0
  67. package/dist/writer.d.ts +32 -0
  68. package/dist/writer.d.ts.map +1 -0
  69. package/dist/writer.js +93 -0
  70. package/dist/writer.js.map +1 -0
  71. package/package.json +40 -4
  72. package/src/args.ts +246 -0
  73. package/src/commands/build.ts +682 -0
  74. package/src/commands/check.ts +45 -0
  75. package/src/commands/clean.ts +168 -0
  76. package/src/commands/format.ts +169 -0
  77. package/src/commands/watch.ts +366 -0
  78. package/src/compiler-api.d.ts +261 -0
  79. package/src/compiler.ts +65 -0
  80. package/src/config.ts +443 -0
  81. package/src/formatter.ts +56 -0
  82. package/src/glob.ts +230 -0
  83. package/src/index.ts +137 -0
  84. package/src/manifest.ts +176 -0
  85. package/src/paths.ts +50 -0
  86. package/src/project.ts +122 -0
  87. package/src/report.ts +230 -0
  88. package/src/setup.ts +218 -0
  89. package/src/writer.ts +102 -0
package/dist/setup.js ADDED
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Effective output setup resolution for CLI planning.
3
+ *
4
+ * The compiler returns artifacts but not the output plan it used
5
+ * (`CompileResult` has no destination list), so the CLI must build the same
6
+ * `PlanOutputsInput` the compiler builds internally: defaults, project
7
+ * configuration and decoded file `@setup` values, in that order. This module
8
+ * mirrors the documented precedence and the planner's provenance rules from
9
+ * `.ai/reports/CSSX-A10.md`. A future public plan on `CompileResult` would
10
+ * remove the duplication.
11
+ */
12
+ import { decodeSetupList } from "@xessa/compiler";
13
+ import { basenamePosix, dirnamePosix } from "./paths.js";
14
+ const STRING_SETUP_KEYS = ["prefix", "css-name", "map-dir", "map-name"];
15
+ const BOOLEAN_SETUP_KEYS = [
16
+ "emit-css",
17
+ "emit-map",
18
+ "map-types",
19
+ "emit-types",
20
+ "source-map",
21
+ "minify",
22
+ "module",
23
+ "map-inherit",
24
+ "import-css",
25
+ ];
26
+ /** Decode every top-level `@setup` block of an entry, first occurrence winning. */
27
+ export function decodeFileSetup(ast) {
28
+ const values = {};
29
+ const seen = new Set();
30
+ let cssDir;
31
+ let cssDirs;
32
+ for (const item of ast.items) {
33
+ if (!isSetupBlock(item))
34
+ continue;
35
+ for (const setting of item.settings) {
36
+ const key = setting.key;
37
+ if (seen.has(key))
38
+ continue;
39
+ if (key === "css-dir") {
40
+ seen.add(key);
41
+ const decoded = decodeSetupList(setting.value, setting.valueSpan);
42
+ const first = decoded.entries[0];
43
+ if (first !== undefined)
44
+ cssDir = first.value;
45
+ if (decoded.entries.length > 1) {
46
+ cssDirs = decoded.entries.map((entry) => entry.value);
47
+ }
48
+ continue;
49
+ }
50
+ if (isStringKey(key)) {
51
+ seen.add(key);
52
+ values[key] = decodeScalar(setting.value);
53
+ }
54
+ else if (isBooleanKey(key)) {
55
+ const decoded = decodeBoolean(setting.value);
56
+ if (decoded === undefined)
57
+ continue;
58
+ seen.add(key);
59
+ values[key] = decoded;
60
+ }
61
+ }
62
+ }
63
+ // `map-types` is the canonical declaration flag; `emit-types` is its legacy
64
+ // alias, so the canonical key wins when both are authored in one layer.
65
+ const types = typeof values["map-types"] === "boolean"
66
+ ? values["map-types"]
67
+ : typeof values["emit-types"] === "boolean"
68
+ ? values["emit-types"]
69
+ : undefined;
70
+ return {
71
+ ...(typeof values.prefix === "string" ? { prefix: values.prefix } : {}),
72
+ ...(cssDir === undefined ? {} : { cssDir }),
73
+ ...(cssDirs === undefined ? {} : { cssDirs }),
74
+ ...(typeof values["css-name"] === "string" ? { cssName: values["css-name"] } : {}),
75
+ ...(typeof values["map-dir"] === "string" ? { mapDir: values["map-dir"] } : {}),
76
+ ...(typeof values["map-name"] === "string" ? { mapName: values["map-name"] } : {}),
77
+ ...(typeof values["emit-css"] === "boolean" ? { emitCss: values["emit-css"] } : {}),
78
+ ...(typeof values["emit-map"] === "boolean" ? { emitMap: values["emit-map"] } : {}),
79
+ ...(types === undefined ? {} : { emitTypes: types }),
80
+ ...(typeof values["source-map"] === "boolean" ? { sourceMap: values["source-map"] } : {}),
81
+ ...(typeof values.minify === "boolean" ? { minify: values.minify } : {}),
82
+ ...(typeof values.module === "boolean" ? { module: values.module } : {}),
83
+ ...(typeof values["map-inherit"] === "boolean" ? { mapInherit: values["map-inherit"] } : {}),
84
+ ...(typeof values["import-css"] === "boolean" ? { importCss: values["import-css"] } : {}),
85
+ };
86
+ }
87
+ /**
88
+ * Built-in setup defaults for a workspace-relative source path.
89
+ *
90
+ * Directories default to the source directory and names to `<stem>.css` /
91
+ * `<stem>.map.js`, matching SPECIFICATION.md §9 and the planner's defaults.
92
+ */
93
+ export function defaultSetupFor(relativeFile) {
94
+ const base = basenamePosix(relativeFile);
95
+ const dot = base.lastIndexOf(".");
96
+ const stem = dot > 0 ? base.slice(0, dot) : base;
97
+ const directory = dirnamePosix(relativeFile);
98
+ return {
99
+ prefix: "",
100
+ cssDir: directory,
101
+ mapDir: directory,
102
+ cssName: `${stem}.css`,
103
+ mapName: `${stem}.map.js`,
104
+ emitCss: true,
105
+ emitMap: true,
106
+ emitTypes: false,
107
+ sourceMap: false,
108
+ minify: true,
109
+ mapInherit: true,
110
+ importCss: false,
111
+ };
112
+ }
113
+ /**
114
+ * Merge built-in defaults, project configuration and file `@setup` into the
115
+ * effective setup for one entry.
116
+ *
117
+ * Precedence is defaults < project config < `module: true` suppression < file
118
+ * `@setup` < explicit overrides. The optional `--minify`/`--no-minify` flag is
119
+ * applied last for reporting; the compiler's project API cannot place it above
120
+ * file `@setup`, which the caller reports as a warning when a file authors a
121
+ * conflicting value. `@setup { module: true }` (ADR-0014) removes the default
122
+ * CSS, map and type outputs of a rule-bearing module; authoring one of those
123
+ * keys explicitly restores it.
124
+ */
125
+ export function resolveEffectiveSetup(relativeFile, config, fileSetup, minifyFlag) {
126
+ const defaults = defaultSetupFor(relativeFile);
127
+ const project = config?.output;
128
+ const strategy = config?.classes?.strategy ?? "prefix";
129
+ const prefix = strategy === "none" ? "" : (fileSetup.prefix ?? config?.classes?.prefix ?? "");
130
+ const moduleDefaults = fileSetup.module === true;
131
+ const emitCssDefault = moduleDefaults ? false : (project?.emitCss ?? defaults.emitCss);
132
+ const emitMapDefault = moduleDefaults ? false : (project?.emitMap ?? defaults.emitMap);
133
+ const emitTypesDefault = moduleDefaults
134
+ ? false
135
+ : (project?.mapTypes ?? project?.emitTypes ?? defaults.emitTypes);
136
+ return {
137
+ prefix,
138
+ cssDir: fileSetup.cssDir ?? project?.cssDir ?? defaults.cssDir,
139
+ ...(fileSetup.cssDirs === undefined ? {} : { cssDirs: fileSetup.cssDirs }),
140
+ cssName: fileSetup.cssName ?? project?.cssName ?? defaults.cssName,
141
+ mapDir: fileSetup.mapDir ?? project?.mapDir ?? defaults.mapDir,
142
+ mapName: fileSetup.mapName ?? project?.mapName ?? defaults.mapName,
143
+ emitCss: fileSetup.emitCss ?? emitCssDefault,
144
+ emitMap: fileSetup.emitMap ?? emitMapDefault,
145
+ emitTypes: fileSetup.emitTypes ?? emitTypesDefault,
146
+ sourceMap: fileSetup.sourceMap ?? project?.sourceMap ?? defaults.sourceMap,
147
+ minify: minifyFlag ?? fileSetup.minify ?? project?.minify ?? defaults.minify,
148
+ mapInherit: fileSetup.mapInherit ?? project?.mapInherit ?? defaults.mapInherit,
149
+ importCss: fileSetup.importCss ?? project?.importCss ?? defaults.importCss,
150
+ };
151
+ }
152
+ function isSetupBlock(item) {
153
+ return item.kind === "setup" && Array.isArray(item.settings);
154
+ }
155
+ function isStringKey(key) {
156
+ return STRING_SETUP_KEYS.includes(key);
157
+ }
158
+ function isBooleanKey(key) {
159
+ return BOOLEAN_SETUP_KEYS.includes(key);
160
+ }
161
+ function decodeBoolean(raw) {
162
+ const value = raw.trim();
163
+ if (value === "true")
164
+ return true;
165
+ if (value === "false")
166
+ return false;
167
+ return undefined;
168
+ }
169
+ /** Decode a quoted CSS string scalar; unquoted scalars are trimmed verbatim. */
170
+ function decodeScalar(raw) {
171
+ const trimmed = raw.trim();
172
+ if (trimmed.length >= 2) {
173
+ const first = trimmed.charAt(0);
174
+ const last = trimmed.charAt(trimmed.length - 1);
175
+ if ((first === '"' && last === '"') || (first === "'" && last === "'")) {
176
+ return trimmed.slice(1, -1).replace(/\\(.)/g, "$1");
177
+ }
178
+ }
179
+ return trimmed;
180
+ }
181
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAyBzD,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,CAAU,CAAC;AACjF,MAAM,kBAAkB,GAAG;IACzB,UAAU;IACV,UAAU;IACV,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,aAAa;IACb,YAAY;CACJ,CAAC;AAEX,mFAAmF;AACnF,MAAM,UAAU,eAAe,CAAC,GAAe;IAC7C,MAAM,MAAM,GAAqC,EAAE,CAAC;IACpD,MAAM,IAAI,GAAG,IAAI,GAAG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,GAAG,CAAC,EAAE,CAAC;YACvE,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Per-file atomic output writes.
3
+ *
4
+ * Each artifact is written to a temporary file in its destination directory and
5
+ * renamed into place, so a crash or failure leaves the previous artifact intact.
6
+ * This is per-file atomicity, never cross-file transactionality (SPECIFICATION.md
7
+ * §9.2). Missing destination directories are created.
8
+ */
9
+ /** SHA-256 content hash in a stable, comparable form. */
10
+ export declare function hashContent(content: string): string;
11
+ /** Hash of an existing file, or `null` when it does not exist or cannot be read. */
12
+ export declare function hashFile(path: string): Promise<string | null>;
13
+ /**
14
+ * Write `content` atomically and return its content hash.
15
+ *
16
+ * The temporary file lives in the destination directory so the final rename
17
+ * stays on one filesystem. A failure removes the temporary file and rethrows,
18
+ * leaving any previous artifact untouched.
19
+ */
20
+ export declare function atomicWrite(path: string, content: string): Promise<string>;
21
+ /** Remove a file if it exists. */
22
+ export declare function removeFile(path: string): Promise<void>;
23
+ /**
24
+ * Remove stale writer temporaries from `directories` and return the removed paths.
25
+ *
26
+ * A process killed between `writeFile` and `rename` cannot run its own cleanup,
27
+ * so every build and `clean` sweeps the output directories it owns. Only the
28
+ * documented writer pattern matches; unreadable or missing directories are
29
+ * skipped, and the sweep is silent because the files were never artifacts.
30
+ */
31
+ export declare function sweepTemporaries(directories: readonly string[]): Promise<readonly string[]>;
32
+ //# sourceMappingURL=writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAiBH,yDAAyD;AACzD,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,oFAAoF;AACpF,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAOnE;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBhF;AAED,kCAAkC;AAClC,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5D;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAqBjG"}
package/dist/writer.js ADDED
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Per-file atomic output writes.
3
+ *
4
+ * Each artifact is written to a temporary file in its destination directory and
5
+ * renamed into place, so a crash or failure leaves the previous artifact intact.
6
+ * This is per-file atomicity, never cross-file transactionality (SPECIFICATION.md
7
+ * §9.2). Missing destination directories are created.
8
+ */
9
+ import { createHash } from "node:crypto";
10
+ import { mkdir, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
11
+ import { basename, dirname, join } from "node:path";
12
+ let temporaryCounter = 0;
13
+ /**
14
+ * The writer's temporary-file name shape: `.<artifact>.<pid>.<counter>.cssx-tmp`.
15
+ *
16
+ * Only names created by {@link atomicWrite} match, so a sweep can never remove a
17
+ * user file even when it happens to share a directory with generated artifacts.
18
+ */
19
+ const TEMPORARY_PATTERN = /^\..+\.[0-9]+\.[0-9]+\.cssx-tmp$/;
20
+ /** SHA-256 content hash in a stable, comparable form. */
21
+ export function hashContent(content) {
22
+ return `sha256:${createHash("sha256").update(content, "utf8").digest("hex")}`;
23
+ }
24
+ /** Hash of an existing file, or `null` when it does not exist or cannot be read. */
25
+ export async function hashFile(path) {
26
+ try {
27
+ const data = await readFile(path);
28
+ return `sha256:${createHash("sha256").update(data).digest("hex")}`;
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ }
34
+ /**
35
+ * Write `content` atomically and return its content hash.
36
+ *
37
+ * The temporary file lives in the destination directory so the final rename
38
+ * stays on one filesystem. A failure removes the temporary file and rethrows,
39
+ * leaving any previous artifact untouched.
40
+ */
41
+ export async function atomicWrite(path, content) {
42
+ const directory = dirname(path);
43
+ await mkdir(directory, { recursive: true });
44
+ temporaryCounter += 1;
45
+ const temporary = join(directory, `.${basename(path)}.${process.pid}.${temporaryCounter}.cssx-tmp`);
46
+ try {
47
+ await writeFile(temporary, content, "utf8");
48
+ await rename(temporary, path);
49
+ }
50
+ catch (error) {
51
+ await rm(temporary, { force: true }).catch(() => undefined);
52
+ throw error;
53
+ }
54
+ return hashContent(content);
55
+ }
56
+ /** Remove a file if it exists. */
57
+ export async function removeFile(path) {
58
+ await rm(path, { force: true });
59
+ }
60
+ /**
61
+ * Remove stale writer temporaries from `directories` and return the removed paths.
62
+ *
63
+ * A process killed between `writeFile` and `rename` cannot run its own cleanup,
64
+ * so every build and `clean` sweeps the output directories it owns. Only the
65
+ * documented writer pattern matches; unreadable or missing directories are
66
+ * skipped, and the sweep is silent because the files were never artifacts.
67
+ */
68
+ export async function sweepTemporaries(directories) {
69
+ const removed = [];
70
+ for (const directory of new Set(directories)) {
71
+ let entries;
72
+ try {
73
+ entries = await readdir(directory, { withFileTypes: true });
74
+ }
75
+ catch {
76
+ continue;
77
+ }
78
+ for (const entry of entries) {
79
+ if (!entry.isFile() || !TEMPORARY_PATTERN.test(entry.name))
80
+ continue;
81
+ const path = join(directory, entry.name);
82
+ try {
83
+ await rm(path, { force: true });
84
+ removed.push(path);
85
+ }
86
+ catch {
87
+ // Another process may hold it; a later build retries.
88
+ }
89
+ }
90
+ }
91
+ return removed;
92
+ }
93
+ //# sourceMappingURL=writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.js","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA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CAAC;gBAChC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;YAAC,MAAM,CAAC;gBACP,sDAAsD;YACxD,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@xessa/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Xessa command line interface: build, check, watch, format and clean.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "engines": {
8
+ "node": ">=20"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/MARKjotep/xessa.git",
13
+ "directory": "packages/cli"
14
+ },
15
+ "homepage": "https://github.com/MARKjotep/xessa#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/MARKjotep/xessa/issues"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "dependencies": {
23
+ "@xessa/compiler": "0.1.1"
24
+ },
25
+ "bin": {
26
+ "xessa": "./dist/index.js"
27
+ },
28
+ "main": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "default": "./dist/index.js"
35
+ }
36
+ },
37
+ "files": ["dist", "src"],
38
+ "scripts": {
39
+ "typecheck": "tsc -p tsconfig.json --noEmit",
40
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && node -e \"const fs=require('node:fs');if(process.platform!=='win32')fs.chmodSync('dist/index.js',0o755)\""
41
+ }
42
+ }
package/src/args.ts ADDED
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Command-line argument parsing for `xessa`.
3
+ *
4
+ * Parsing is strict: unknown flags, missing flag values, extra positional
5
+ * arguments and a missing command all fail with exit code 2 (invocation error).
6
+ * `--help` and `--version` short-circuit every other rule.
7
+ */
8
+
9
+ /** Commands the CLI dispatches. */
10
+ export type CommandName = "build" | "check" | "watch" | "clean" | "format" | "help";
11
+
12
+ /** Parsed CLI invocation. */
13
+ export interface CliInvocation {
14
+ /** Selected command; `help` when only `--help`/`--version` was requested. */
15
+ readonly command: CommandName;
16
+ /** Optional source file for single-entry build/check/watch. */
17
+ readonly file?: string;
18
+ /** Explicit `--config` path, absolute or relative to the working directory. */
19
+ readonly configPath?: string;
20
+ /** Emit machine-readable JSON (build/check/clean) or NDJSON (watch). */
21
+ readonly json: boolean;
22
+ /** Report planned work without writing or deleting. */
23
+ readonly dryRun: boolean;
24
+ /** `true` for `--minify`, `false` for `--no-minify`, `undefined` when unset. */
25
+ readonly minify?: boolean;
26
+ /** `true` for `--check`: report files that `format` would change, write nothing. */
27
+ readonly check?: boolean;
28
+ }
29
+
30
+ /** Parse outcome for {@link parseArgs}. */
31
+ export type ParseOutcome =
32
+ | {
33
+ readonly ok: true;
34
+ readonly invocation: CliInvocation;
35
+ readonly help: boolean;
36
+ readonly version: boolean;
37
+ }
38
+ | {
39
+ readonly ok: false;
40
+ readonly message: string;
41
+ /** Whether `--json` was seen before the failure, so callers can emit JSON. */
42
+ readonly json: boolean;
43
+ };
44
+
45
+ /** Usage text written by `--help`. */
46
+ export const USAGE = `xessa — compile Xessa stylesheets
47
+
48
+ Usage:
49
+ xessa build [file] [flags]
50
+ xessa check [file] [flags]
51
+ xessa watch [file] [flags]
52
+ xessa clean [flags]
53
+ xessa format [file] [flags]
54
+ xessa --help
55
+ xessa --version
56
+
57
+ Commands:
58
+ build Compile the project (config include globs) or one file and write outputs
59
+ check Report diagnostics and planned outputs without writing anything
60
+ watch Rebuild changed entries until interrupted
61
+ clean Delete compiler-owned outputs that were not modified since generation
62
+ format Format sources canonically (with --check to report without writing)
63
+
64
+ Flags:
65
+ --config <path> Use a specific xessa.config.json instead of the nearest one
66
+ --json Print machine-readable results
67
+ --dry-run Report planned work without writing files or deleting them
68
+ --minify Emit compact CSS
69
+ --no-minify Emit expanded CSS
70
+ --check With format: list files that would change; write nothing
71
+ -h, --help Show this help
72
+ -v, --version Print the CLI version
73
+
74
+ Exit codes:
75
+ 0 success
76
+ 1 compile, validation or formatting errors (or --check found changes)
77
+ 2 invocation or configuration errors
78
+ `;
79
+
80
+ const COMMANDS: ReadonlySet<string> = new Set([
81
+ "build",
82
+ "check",
83
+ "watch",
84
+ "clean",
85
+ "format",
86
+ "help",
87
+ ]);
88
+
89
+ const VALUE_FLAGS: ReadonlySet<string> = new Set(["--config"]);
90
+
91
+ /** Parse process arguments (without `node`/script) into an invocation. */
92
+ export function parseArgs(argv: readonly string[]): ParseOutcome {
93
+ let command: CommandName | undefined;
94
+ const positionals: string[] = [];
95
+ let configPath: string | undefined;
96
+ let json = false;
97
+ let dryRun = false;
98
+ let minify: boolean | undefined;
99
+ let check = false;
100
+ let help = false;
101
+ let version = false;
102
+ let flagsEnded = false;
103
+ let index = 0;
104
+
105
+ while (index < argv.length) {
106
+ const raw = argv[index];
107
+ index += 1;
108
+ if (raw === undefined) break;
109
+
110
+ if (!flagsEnded && raw === "--") {
111
+ flagsEnded = true;
112
+ continue;
113
+ }
114
+
115
+ if (!flagsEnded && raw.startsWith("-") && raw !== "-") {
116
+ const equals = raw.indexOf("=");
117
+ const name = equals < 0 ? raw : raw.slice(0, equals);
118
+ const inlineValue = equals < 0 ? undefined : raw.slice(equals + 1);
119
+
120
+ if (name === "-h" || name === "--help") {
121
+ help = true;
122
+ continue;
123
+ }
124
+ if (name === "-v" || name === "--version") {
125
+ version = true;
126
+ continue;
127
+ }
128
+ if (name === "--json") {
129
+ if (inlineValue !== undefined) return fail("--json does not take a value.", json);
130
+ json = true;
131
+ continue;
132
+ }
133
+ if (name === "--dry-run") {
134
+ if (inlineValue !== undefined) return fail("--dry-run does not take a value.", json);
135
+ dryRun = true;
136
+ continue;
137
+ }
138
+ if (name === "--minify") {
139
+ if (inlineValue !== undefined) return fail("--minify does not take a value.", json);
140
+ minify = true;
141
+ continue;
142
+ }
143
+ if (name === "--no-minify") {
144
+ if (inlineValue !== undefined) return fail("--no-minify does not take a value.", json);
145
+ minify = false;
146
+ continue;
147
+ }
148
+ if (name === "--check") {
149
+ if (inlineValue !== undefined) return fail("--check does not take a value.", json);
150
+ check = true;
151
+ continue;
152
+ }
153
+ if (VALUE_FLAGS.has(name)) {
154
+ // A value flag never consumes another option as its value: `--config
155
+ // --json` is a missing path, not a configuration named `--json`. A bare
156
+ // `-` is a legal value (standard input / literal dash).
157
+ if (inlineValue === undefined) {
158
+ const next = argv[index];
159
+ if (next === undefined || next === "" || (next.startsWith("-") && next !== "-")) {
160
+ return fail(`${name} requires a path.`, json);
161
+ }
162
+ index += 1;
163
+ if (name === "--config") {
164
+ if (configPath !== undefined) return fail("--config may be given only once.", json);
165
+ configPath = next;
166
+ }
167
+ continue;
168
+ }
169
+ if (inlineValue === "") return fail(`${name} requires a path.`, json);
170
+ if (name === "--config") {
171
+ if (configPath !== undefined) return fail("--config may be given only once.", json);
172
+ configPath = inlineValue;
173
+ }
174
+ continue;
175
+ }
176
+ return fail(`Unknown option "${raw}".`, json);
177
+ }
178
+
179
+ if (command === undefined) {
180
+ if (!COMMANDS.has(raw)) return fail(`Unknown command "${raw}".`, json);
181
+ command = raw as CommandName;
182
+ continue;
183
+ }
184
+ positionals.push(raw);
185
+ }
186
+
187
+ if (help || version) {
188
+ return {
189
+ ok: true,
190
+ invocation: {
191
+ command: "help",
192
+ ...(configPath === undefined ? {} : { configPath }),
193
+ json,
194
+ dryRun,
195
+ ...(minify === undefined ? {} : { minify }),
196
+ ...(check ? { check: true } : {}),
197
+ },
198
+ help,
199
+ version,
200
+ };
201
+ }
202
+
203
+ if (command === undefined) {
204
+ return fail("Missing command. Run xessa --help for usage.", json);
205
+ }
206
+
207
+ if (check && command !== "format") {
208
+ return fail("--check is only valid for xessa format.", json);
209
+ }
210
+
211
+ // `check` never writes, so `--dry-run` cannot change its behaviour; accepting
212
+ // it silently made the JSON report contradict the invocation (CSSX-T12).
213
+ if (dryRun && command === "check") {
214
+ return fail("--dry-run is not valid for xessa check.", json);
215
+ }
216
+
217
+ const maxPositionals = command === "clean" ? 0 : 1;
218
+ if (positionals.length > maxPositionals) {
219
+ return fail(
220
+ maxPositionals === 0
221
+ ? `xessa ${command} does not take a file argument.`
222
+ : `xessa ${command} accepts at most one file argument.`,
223
+ json,
224
+ );
225
+ }
226
+
227
+ const file = positionals[0];
228
+ return {
229
+ ok: true,
230
+ invocation: {
231
+ command,
232
+ ...(file === undefined ? {} : { file }),
233
+ ...(configPath === undefined ? {} : { configPath }),
234
+ json,
235
+ dryRun,
236
+ ...(minify === undefined ? {} : { minify }),
237
+ ...(check ? { check: true } : {}),
238
+ },
239
+ help: false,
240
+ version: false,
241
+ };
242
+ }
243
+
244
+ function fail(message: string, json: boolean): ParseOutcome {
245
+ return { ok: false, message, json };
246
+ }