@tsed/barrels 5.3.2 → 5.4.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.
- package/bin/barrels.js +29 -29
- package/package.json +1 -1
package/bin/barrels.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {existsSync} from "node:fs";
|
|
3
|
-
import {
|
|
4
|
-
import {join} from "node:path";
|
|
3
|
+
import {readFile, writeFile} from "node:fs/promises";
|
|
4
|
+
import {dirname, join} from "node:path";
|
|
5
5
|
import {globby} from "globby";
|
|
6
6
|
|
|
7
7
|
function resolveConfig() {
|
|
@@ -16,7 +16,7 @@ function resolveConfig() {
|
|
|
16
16
|
async function readJSON(path) {
|
|
17
17
|
const content = await readFile(path, "utf-8");
|
|
18
18
|
|
|
19
|
-
return JSON.parse(content)
|
|
19
|
+
return JSON.parse(content);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function getConfig() {
|
|
@@ -53,37 +53,37 @@ async function build() {
|
|
|
53
53
|
.map((path) => `!${path}`)
|
|
54
54
|
.concat(directory.map((path) => `!${path}/index.ts`));
|
|
55
55
|
|
|
56
|
-
const
|
|
57
|
-
.map(
|
|
58
|
-
|
|
56
|
+
const directories = (
|
|
57
|
+
await globby(directory.map((d) => {
|
|
58
|
+
return join(d, "*");
|
|
59
|
+
}),
|
|
60
|
+
{
|
|
61
|
+
cwd: process.cwd()
|
|
62
|
+
})
|
|
63
|
+
).reduce((set, file) => {
|
|
64
|
+
return set.add(dirname(file));
|
|
65
|
+
}, new Set());
|
|
66
|
+
|
|
67
|
+
const promises = [...directories.keys()].map(async (directory) => {
|
|
68
|
+
const baseIndex = join(process.cwd(), directory?.path ?? directory);
|
|
69
|
+
|
|
70
|
+
const files = await globby(["**/*.ts", "!index.ts", ...excluded], {
|
|
71
|
+
cwd: directory
|
|
72
|
+
});
|
|
59
73
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
cwd: directory
|
|
74
|
+
const exports = files
|
|
75
|
+
.sort((a, b) => a.localeCompare(b))
|
|
76
|
+
.map((file) => {
|
|
77
|
+
// TODO set .js after all configuration are ok to resolve .js
|
|
78
|
+
return `export * from "./${file.replace(".ts", ".js")}";`;
|
|
66
79
|
});
|
|
67
80
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return `export * from "./${file.replace(".ts", ".js")}";`;
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const content = [
|
|
76
|
-
"/**",
|
|
77
|
-
" * @file Automatically generated by @tsed/barrels.",
|
|
78
|
-
" */",
|
|
79
|
-
...exports
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
await writeFile(join(baseIndex, "index.ts"), content.join("\n") + "\n", {encoding: "utf8"});
|
|
83
|
-
});
|
|
81
|
+
const content = ["/**", " * @file Automatically generated by @tsed/barrels.", " */", ...exports];
|
|
82
|
+
|
|
83
|
+
await writeFile(join(baseIndex, "index.ts"), content.join("\n") + "\n", {encoding: "utf8"});
|
|
84
|
+
});
|
|
84
85
|
|
|
85
86
|
await Promise.all(promises);
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
|
|
89
89
|
await build();
|