@batijs/build 0.0.87 → 0.0.90
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.
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import { loadFile, renderSquirrelly, transformAstAndGenerate } from "@batijs/core";
|
|
1
|
+
// src/index.ts
|
|
3
2
|
import { existsSync } from "fs";
|
|
4
3
|
import { copyFile, mkdir, opendir, readFile, writeFile } from "fs/promises";
|
|
5
4
|
import path from "path";
|
|
5
|
+
import { loadFile, renderSquirrelly, transformAstAndGenerate } from "@batijs/core";
|
|
6
|
+
|
|
7
|
+
// src/queue.ts
|
|
8
|
+
function queue() {
|
|
9
|
+
const tasks = [];
|
|
10
|
+
return {
|
|
11
|
+
add(task) {
|
|
12
|
+
tasks.push(task);
|
|
13
|
+
},
|
|
14
|
+
async run() {
|
|
15
|
+
let task;
|
|
16
|
+
while (task = tasks.shift()) {
|
|
17
|
+
await task();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/index.ts
|
|
6
24
|
var reIgnoreFile = /^(chunk-|asset-|#)/gi;
|
|
7
25
|
var isWin = process.platform === "win32";
|
|
8
26
|
function toDist(filepath, source, dist) {
|
|
@@ -58,9 +76,16 @@ async function fileContainsBatiMeta(filepath) {
|
|
|
58
76
|
const code = await readFile(filepath, { encoding: "utf-8" });
|
|
59
77
|
return code.includes("import.meta.BATI_");
|
|
60
78
|
}
|
|
79
|
+
async function importTransformer(p) {
|
|
80
|
+
const importFile = isWin ? "file://" + p : p;
|
|
81
|
+
const f = await import(importFile);
|
|
82
|
+
return f.default;
|
|
83
|
+
}
|
|
61
84
|
async function main(options, meta) {
|
|
62
85
|
const sources = Array.isArray(options.source) ? options.source : [options.source];
|
|
63
86
|
const targets = /* @__PURE__ */ new Set();
|
|
87
|
+
const simpleCopyQ = queue();
|
|
88
|
+
const transformAndWriteQ = queue();
|
|
64
89
|
for (const source of sources) {
|
|
65
90
|
for await (const p of walk(source)) {
|
|
66
91
|
const target = toDist(p, source, options.dist);
|
|
@@ -73,42 +98,57 @@ async function main(options, meta) {
|
|
|
73
98
|
Please report this issue to https://github.com/magne4000/bati`
|
|
74
99
|
);
|
|
75
100
|
} else if (parsed.name.startsWith("$") && parsed.ext.match(/\.jsx?$/)) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
101
|
+
transformAndWriteQ.add(async () => {
|
|
102
|
+
const transformer = await importTransformer(p);
|
|
103
|
+
const rf = () => {
|
|
104
|
+
return readFile(target, { encoding: "utf-8" });
|
|
105
|
+
};
|
|
106
|
+
const fileContent = transformFileAfterExec(
|
|
107
|
+
target,
|
|
108
|
+
await transformer({
|
|
109
|
+
readfile: targets.has(target) ? rf : void 0,
|
|
110
|
+
meta,
|
|
111
|
+
source,
|
|
112
|
+
target
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
if (fileContent !== null) {
|
|
116
|
+
await safeWriteFile(target, fileContent);
|
|
117
|
+
targets.add(target);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
86
120
|
} else if (await fileContainsBatiMeta(p)) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
121
|
+
transformAndWriteQ.add(async () => {
|
|
122
|
+
let fileContent = "";
|
|
123
|
+
if (parsed.ext.match(/\.[tj]sx?$/)) {
|
|
124
|
+
const mod = await loadFile(p);
|
|
125
|
+
fileContent = await transformAstAndGenerate(mod.$ast, meta, {
|
|
126
|
+
filepath: p
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
const template = await readFile(p, { encoding: "utf-8" });
|
|
130
|
+
try {
|
|
131
|
+
fileContent = renderSquirrelly(template, meta);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
console.error("SquirrellyJS error while rendering", p);
|
|
134
|
+
throw e;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (fileContent) {
|
|
138
|
+
await safeWriteFile(target, fileContent);
|
|
139
|
+
targets.add(target);
|
|
100
140
|
}
|
|
101
|
-
}
|
|
102
|
-
if (fileContent) {
|
|
103
|
-
await safeWriteFile(target, fileContent);
|
|
104
|
-
}
|
|
105
|
-
targets.add(target);
|
|
141
|
+
});
|
|
106
142
|
} else {
|
|
107
|
-
|
|
108
|
-
|
|
143
|
+
simpleCopyQ.add(async () => {
|
|
144
|
+
await safeCopyFile(p, target);
|
|
145
|
+
targets.add(target);
|
|
146
|
+
});
|
|
109
147
|
}
|
|
110
148
|
}
|
|
111
149
|
}
|
|
150
|
+
await simpleCopyQ.run();
|
|
151
|
+
await transformAndWriteQ.run();
|
|
112
152
|
}
|
|
113
153
|
export {
|
|
114
154
|
main as default,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@batijs/build",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.90",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [],
|
|
@@ -10,20 +10,20 @@
|
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@types/node": "^16.18.40",
|
|
12
12
|
"tsup": "^7.2.0",
|
|
13
|
-
"@batijs/tsup": "0.0.
|
|
13
|
+
"@batijs/tsup": "0.0.90"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@batijs/core": "0.0.
|
|
16
|
+
"@batijs/core": "0.0.90"
|
|
17
17
|
},
|
|
18
|
-
"main": "./dist/
|
|
19
|
-
"module": "./dist/
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
20
|
"exports": {
|
|
21
|
-
".": "./dist/
|
|
21
|
+
".": "./dist/index.js"
|
|
22
22
|
},
|
|
23
23
|
"typesVersions": {
|
|
24
24
|
"*": {
|
|
25
25
|
".": [
|
|
26
|
-
"./dist/
|
|
26
|
+
"./dist/index.d.ts"
|
|
27
27
|
]
|
|
28
28
|
}
|
|
29
29
|
},
|
|
File without changes
|