@aeriajs/compiler 0.0.7 → 0.0.8
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/compile.d.ts +3 -3
- package/dist/compile.js +13 -9
- package/dist/compile.mjs +12 -8
- package/package.json +1 -1
package/dist/compile.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type * as AST from './ast.js';
|
|
|
2
2
|
import { Diagnostic } from './diagnostic.js';
|
|
3
3
|
export type CompilationResult = {
|
|
4
4
|
success: boolean;
|
|
5
|
-
ast
|
|
5
|
+
ast?: AST.ProgramNode;
|
|
6
6
|
errors: Diagnostic[];
|
|
7
7
|
errorCount: number;
|
|
8
8
|
};
|
|
@@ -12,10 +12,10 @@ export type CompilationOptions = {
|
|
|
12
12
|
};
|
|
13
13
|
export declare const parseAndCheck: (sources: Record<string, string>) => Promise<CompilationResult>;
|
|
14
14
|
export declare const generateScaffolding: (options: CompilationOptions) => Promise<string[]>;
|
|
15
|
-
export declare const compileFromFiles: (schemaDir: string, options: CompilationOptions) => Promise<{
|
|
15
|
+
export declare const compileFromFiles: (schemaDir: string, options: CompilationOptions) => Promise<CompilationResult | {
|
|
16
16
|
emittedFiles: Record<string, string>;
|
|
17
17
|
success: boolean;
|
|
18
|
-
ast
|
|
18
|
+
ast?: AST.ProgramNode;
|
|
19
19
|
errors: Diagnostic[];
|
|
20
20
|
errorCount: number;
|
|
21
21
|
}>;
|
package/dist/compile.js
CHANGED
|
@@ -40,7 +40,7 @@ const parser_js_1 = require("./parser.js");
|
|
|
40
40
|
const semantic_js_1 = require("./semantic.js");
|
|
41
41
|
const codegen_js_1 = require("./codegen.js");
|
|
42
42
|
const path = __importStar(require("node:path"));
|
|
43
|
-
const
|
|
43
|
+
const fs = __importStar(require("node:fs"));
|
|
44
44
|
const parseAndCheck = async (sources) => {
|
|
45
45
|
const errors = [];
|
|
46
46
|
let errorCount = 0;
|
|
@@ -65,14 +65,14 @@ const parseAndCheck = async (sources) => {
|
|
|
65
65
|
success: errorCount === 0,
|
|
66
66
|
errors,
|
|
67
67
|
errorCount,
|
|
68
|
-
ast
|
|
68
|
+
ast,
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
71
|
exports.parseAndCheck = parseAndCheck;
|
|
72
72
|
const generateScaffolding = async (options) => {
|
|
73
73
|
const directories = [path.join(options.outDir, 'collections')];
|
|
74
74
|
for (const dir of directories) {
|
|
75
|
-
await
|
|
75
|
+
await fs.promises.mkdir(dir, {
|
|
76
76
|
recursive: true,
|
|
77
77
|
});
|
|
78
78
|
}
|
|
@@ -80,16 +80,20 @@ const generateScaffolding = async (options) => {
|
|
|
80
80
|
};
|
|
81
81
|
exports.generateScaffolding = generateScaffolding;
|
|
82
82
|
const compileFromFiles = async (schemaDir, options) => {
|
|
83
|
-
const fileList = await
|
|
83
|
+
const fileList = await fs.promises.readdir(schemaDir);
|
|
84
84
|
const sources = {};
|
|
85
85
|
for (const file of fileList) {
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
sources[file] = await fs.promises.readFile(`${schemaDir}/${file}`, {
|
|
87
|
+
encoding: 'utf-8',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const result = await (0, exports.parseAndCheck)(sources);
|
|
91
|
+
if (!result.ast) {
|
|
92
|
+
return result;
|
|
88
93
|
}
|
|
89
|
-
const
|
|
90
|
-
const emittedFiles = await (0, codegen_js_1.generateCode)(parsed.ast, options);
|
|
94
|
+
const emittedFiles = await (0, codegen_js_1.generateCode)(result.ast, options);
|
|
91
95
|
return {
|
|
92
|
-
...
|
|
96
|
+
...result,
|
|
93
97
|
emittedFiles,
|
|
94
98
|
};
|
|
95
99
|
};
|
package/dist/compile.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { parse } from "./parser.mjs";
|
|
|
5
5
|
import { analyze } from "./semantic.mjs";
|
|
6
6
|
import { generateCode } from "./codegen.mjs";
|
|
7
7
|
import * as path from "node:path";
|
|
8
|
-
import * as
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
9
|
export const parseAndCheck = async (sources) => {
|
|
10
10
|
const errors = [];
|
|
11
11
|
let errorCount = 0;
|
|
@@ -35,23 +35,27 @@ export const parseAndCheck = async (sources) => {
|
|
|
35
35
|
export const generateScaffolding = async (options) => {
|
|
36
36
|
const directories = [path.join(options.outDir, "collections")];
|
|
37
37
|
for (const dir of directories) {
|
|
38
|
-
await
|
|
38
|
+
await fs.promises.mkdir(dir, {
|
|
39
39
|
recursive: true
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
return directories;
|
|
43
43
|
};
|
|
44
44
|
export const compileFromFiles = async (schemaDir, options) => {
|
|
45
|
-
const fileList = await
|
|
45
|
+
const fileList = await fs.promises.readdir(schemaDir);
|
|
46
46
|
const sources = {};
|
|
47
47
|
for (const file of fileList) {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
sources[file] = await fs.promises.readFile(`${schemaDir}/${file}`, {
|
|
49
|
+
encoding: "utf-8"
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const result = await parseAndCheck(sources);
|
|
53
|
+
if (!result.ast) {
|
|
54
|
+
return result;
|
|
50
55
|
}
|
|
51
|
-
const
|
|
52
|
-
const emittedFiles = await generateCode(parsed.ast, options);
|
|
56
|
+
const emittedFiles = await generateCode(result.ast, options);
|
|
53
57
|
return {
|
|
54
|
-
...
|
|
58
|
+
...result,
|
|
55
59
|
emittedFiles
|
|
56
60
|
};
|
|
57
61
|
};
|