@jay-framework/jay-cli 0.6.7 → 0.6.9
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/index.js +28 -27
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import { rollup } from "rollup";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { generateElementFile } from "@jay-framework/compiler";
|
|
5
|
+
import { jayDefinitions } from "@jay-framework/rollup-plugin";
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
import * as fastGlob from "fast-glob";
|
|
8
|
+
import { JAY_EXTENSION, checkValidationErrors, GenerateTarget, RuntimeMode, JAY_CONTRACT_EXTENSION } from "@jay-framework/compiler-shared";
|
|
9
|
+
import fs, { promises } from "fs";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { parseJayFile, JAY_IMPORT_RESOLVER } from "@jay-framework/compiler-jay-html";
|
|
12
|
+
import { glob as glob$1 } from "glob";
|
|
13
|
+
import path$1 from "node:path";
|
|
14
|
+
const { glob } = fastGlob;
|
|
14
15
|
async function findAllJayFiles(dir) {
|
|
15
|
-
return await
|
|
16
|
+
return await glob(`${dir}/**/*${JAY_EXTENSION}`);
|
|
16
17
|
}
|
|
17
18
|
function checkFileExists(filepath) {
|
|
18
19
|
return new Promise((resolve, reject) => {
|
|
@@ -27,20 +28,20 @@ async function generateFiles(dir, codeGenerationFunction, afterGenerationFunctio
|
|
|
27
28
|
console.log(dir, jayFiles);
|
|
28
29
|
let generationFailed = false;
|
|
29
30
|
for (const jayFile of jayFiles) {
|
|
30
|
-
const content = await
|
|
31
|
-
const parsedFile =
|
|
32
|
-
await
|
|
31
|
+
const content = await promises.readFile(jayFile, "utf-8");
|
|
32
|
+
const parsedFile = checkValidationErrors(
|
|
33
|
+
await parseJayFile(
|
|
33
34
|
content,
|
|
34
35
|
path.basename(jayFile.replace(".jay-html", "")),
|
|
35
36
|
path.dirname(jayFile),
|
|
36
37
|
{},
|
|
37
|
-
|
|
38
|
+
JAY_IMPORT_RESOLVER
|
|
38
39
|
)
|
|
39
40
|
);
|
|
40
|
-
const generateTarget = compilationTarget === "react" ?
|
|
41
|
+
const generateTarget = compilationTarget === "react" ? GenerateTarget.react : GenerateTarget.jay;
|
|
41
42
|
const generatedFile = codeGenerationFunction(
|
|
42
43
|
parsedFile,
|
|
43
|
-
|
|
44
|
+
RuntimeMode.MainTrusted,
|
|
44
45
|
generateTarget
|
|
45
46
|
);
|
|
46
47
|
const generateFileName = jayFile + outputExtension;
|
|
@@ -71,9 +72,9 @@ async function generateFiles(dir, codeGenerationFunction, afterGenerationFunctio
|
|
|
71
72
|
destinationGeneratedFileName = generateFileName;
|
|
72
73
|
let destinationDirName = path.dirname(destinationGeneratedFileName);
|
|
73
74
|
if (!await checkFileExists(destinationDirName)) {
|
|
74
|
-
await
|
|
75
|
+
await promises.mkdir(destinationDirName, { recursive: true });
|
|
75
76
|
}
|
|
76
|
-
await
|
|
77
|
+
await promises.writeFile(destinationGeneratedFileName, generatedFile.val);
|
|
77
78
|
}
|
|
78
79
|
afterGenerationFunction(
|
|
79
80
|
content,
|
|
@@ -87,21 +88,21 @@ async function generateFiles(dir, codeGenerationFunction, afterGenerationFunctio
|
|
|
87
88
|
}
|
|
88
89
|
function getJayHtmlOrContractFileInputs(source) {
|
|
89
90
|
return Object.fromEntries(
|
|
90
|
-
|
|
91
|
-
const moduleName = file.includes(
|
|
91
|
+
glob$1.sync(`${source}/**/*{${JAY_EXTENSION},${JAY_CONTRACT_EXTENSION}}`).map((file) => {
|
|
92
|
+
const moduleName = file.includes(JAY_EXTENSION) ? file.slice(0, file.length - JAY_EXTENSION.length) : file.slice(0, file.length - JAY_CONTRACT_EXTENSION.length);
|
|
92
93
|
return [path$1.relative(source, moduleName), file];
|
|
93
94
|
})
|
|
94
95
|
);
|
|
95
96
|
}
|
|
96
|
-
const program = new
|
|
97
|
+
const program = new Command();
|
|
97
98
|
const noop = () => void 0;
|
|
98
99
|
program.command("definitions").argument("<source>", "source folder to scan for .jay-html files").description("generate definition files (.d.ts) for jay files").action(async (source) => {
|
|
99
|
-
await rollup
|
|
100
|
+
await rollup({
|
|
100
101
|
input: getJayHtmlOrContractFileInputs(source),
|
|
101
|
-
plugins: [
|
|
102
|
+
plugins: [jayDefinitions()]
|
|
102
103
|
});
|
|
103
104
|
});
|
|
104
105
|
program.command("runtime").argument("<source>", "source folder to scan for .jay-html files").argument("[destination]", "destination folder for generated files").argument("[compilationTarget]", "jay | react. target runtime to compile for. Defaults to jay").description("generate code files (.ts) for jay files").action(async (source, dest, compilationTarget) => {
|
|
105
|
-
await generateFiles(source,
|
|
106
|
+
await generateFiles(source, generateElementFile, noop, ".ts", dest, compilationTarget);
|
|
106
107
|
});
|
|
107
108
|
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/jay-cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": "dist/index.js",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"files": [
|
|
8
9
|
"dist",
|
|
9
10
|
"readme.md"
|
|
@@ -20,14 +21,15 @@
|
|
|
20
21
|
"test:watch": ":"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@jay-framework/compiler": "^0.6.
|
|
24
|
-
"@jay-framework/rollup-plugin": "^0.6.
|
|
24
|
+
"@jay-framework/compiler": "^0.6.9",
|
|
25
|
+
"@jay-framework/rollup-plugin": "^0.6.9",
|
|
25
26
|
"chalk": "^4.1.2",
|
|
26
27
|
"commander": "^14.0.0",
|
|
28
|
+
"glob": "^10.4.5",
|
|
27
29
|
"rollup": "^4.9.5"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
|
-
"@jay-framework/dev-environment": "^0.6.
|
|
32
|
+
"@jay-framework/dev-environment": "^0.6.9",
|
|
31
33
|
"@types/node": "^20.11.5",
|
|
32
34
|
"@types/shelljs": "^0.8.15",
|
|
33
35
|
"rimraf": "^5.0.5",
|