@constela/cli 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +90 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Constela Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
|
|
6
|
+
// src/commands/compile.ts
|
|
7
|
+
import { compile } from "@constela/compiler";
|
|
8
|
+
import { readFileSync, writeFileSync, mkdirSync, statSync } from "fs";
|
|
9
|
+
import { dirname, basename, join } from "path";
|
|
10
|
+
function getOutputPath(inputPath, options) {
|
|
11
|
+
if (options.out) {
|
|
12
|
+
return options.out;
|
|
13
|
+
}
|
|
14
|
+
const dir = dirname(inputPath);
|
|
15
|
+
const base = basename(inputPath);
|
|
16
|
+
if (base.endsWith(".json")) {
|
|
17
|
+
const nameWithoutExt = base.slice(0, -5);
|
|
18
|
+
return join(dir, `${nameWithoutExt}.compiled.json`);
|
|
19
|
+
}
|
|
20
|
+
return join(dir, `${base}.compiled.json`);
|
|
21
|
+
}
|
|
22
|
+
async function compileCommand(inputPath, options) {
|
|
23
|
+
try {
|
|
24
|
+
const stat = statSync(inputPath);
|
|
25
|
+
if (!stat.isFile()) {
|
|
26
|
+
console.error(`Error: Input path is not a regular file: ${inputPath}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
const error = err;
|
|
31
|
+
if (error.code === "ENOENT") {
|
|
32
|
+
console.error(`Error: File not found: ${inputPath}`);
|
|
33
|
+
} else {
|
|
34
|
+
console.error(`Error: Could not access file: ${inputPath} - ${error.message}`);
|
|
35
|
+
}
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
let fileContent;
|
|
39
|
+
try {
|
|
40
|
+
fileContent = readFileSync(inputPath, "utf-8");
|
|
41
|
+
} catch (err) {
|
|
42
|
+
const error = err;
|
|
43
|
+
console.error(`Error: Could not read file: ${inputPath} - ${error.message}`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
let inputJson;
|
|
47
|
+
try {
|
|
48
|
+
inputJson = JSON.parse(fileContent);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
const error = err;
|
|
51
|
+
console.error(`Error: Invalid JSON: ${error.message}`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
const result = compile(inputJson);
|
|
55
|
+
if (!result.ok) {
|
|
56
|
+
for (const error of result.errors) {
|
|
57
|
+
const pathInfo = error.path ? ` at ${error.path}` : "";
|
|
58
|
+
console.error(`Error [${error.code}]: ${error.message}${pathInfo}`);
|
|
59
|
+
}
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
const outputPath = getOutputPath(inputPath, options);
|
|
63
|
+
const outputDir = dirname(outputPath);
|
|
64
|
+
try {
|
|
65
|
+
mkdirSync(outputDir, { recursive: true });
|
|
66
|
+
} catch (err) {
|
|
67
|
+
const error = err;
|
|
68
|
+
console.error(`Error: Could not create output directory: ${outputDir} - ${error.message}`);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
const outputContent = options.pretty ? JSON.stringify(result.program, null, 2) : JSON.stringify(result.program);
|
|
72
|
+
try {
|
|
73
|
+
writeFileSync(outputPath, outputContent, "utf-8");
|
|
74
|
+
} catch (err) {
|
|
75
|
+
const error = err;
|
|
76
|
+
console.error(`Error: Could not write output file: ${outputPath} - ${error.message}`);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
console.log(`Compiled ${inputPath} \u2192 ${outputPath}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/index.ts
|
|
83
|
+
var program = new Command();
|
|
84
|
+
program.name("constela").description("Constela UI framework CLI").version("0.1.0");
|
|
85
|
+
program.command("compile <input>").description("Compile a Constela DSL file").option("-o, --out <path>", "Output file path").option("--pretty", "Pretty-print JSON output").action(compileCommand);
|
|
86
|
+
if (process.argv.length <= 2) {
|
|
87
|
+
program.outputHelp();
|
|
88
|
+
process.exit(0);
|
|
89
|
+
}
|
|
90
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@constela/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI tools for Constela UI framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"constela": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"commander": "^12.0.0",
|
|
22
|
+
"@constela/compiler": "0.1.0",
|
|
23
|
+
"@constela/core": "0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^20.10.0",
|
|
27
|
+
"tsup": "^8.0.0",
|
|
28
|
+
"typescript": "^5.3.0",
|
|
29
|
+
"vitest": "^2.0.0"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=20.0.0"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
37
|
+
"type-check": "tsc --noEmit",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"test:watch": "vitest",
|
|
40
|
+
"clean": "rm -rf dist"
|
|
41
|
+
}
|
|
42
|
+
}
|