@tsed/barrels 6.0.0 → 6.0.2
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/generate-barrel.js +19 -30
- package/package.json +1 -1
package/bin/generate-barrel.js
CHANGED
|
@@ -3,18 +3,24 @@ import path, {dirname, join} from "node:path";
|
|
|
3
3
|
|
|
4
4
|
import {globby} from "globby";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
|
|
6
|
+
async function generateIndex(directory, {cwd, excluded}) {
|
|
7
|
+
const baseIndex = join(cwd, directory?.path ?? directory);
|
|
8
|
+
|
|
9
|
+
const files = await globby(["**/*.{ts,tsx}", "!index.{ts,tsx}", ...excluded], {
|
|
10
|
+
cwd: path.join(cwd, directory)
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const exports = files
|
|
14
|
+
.sort((a, b) => a.localeCompare(b))
|
|
15
|
+
.map((file) => {
|
|
16
|
+
// TODO set .js after all configuration are ok to resolve .js
|
|
17
|
+
return `export * from "./${file.replace(".ts", ".js")}";`;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const content = ["/**", " * @file Automatically generated by @tsed/barrels.", " */", ...exports];
|
|
21
|
+
|
|
22
|
+
await writeFile(join(baseIndex, "index.ts"), content.join("\n") + "\n", {encoding: "utf8"});
|
|
23
|
+
}
|
|
18
24
|
|
|
19
25
|
export async function generateBarrels({exclude, directory, cwd}) {
|
|
20
26
|
const excluded = exclude.map((path) => `!${path}`).concat(directory.map((path) => `!${path}/index.ts`));
|
|
@@ -32,24 +38,7 @@ export async function generateBarrels({exclude, directory, cwd}) {
|
|
|
32
38
|
return set.add(dirname(file));
|
|
33
39
|
}, new Set());
|
|
34
40
|
|
|
35
|
-
const promises = [...directories.keys()].map(
|
|
36
|
-
const baseIndex = join(cwd, directory?.path ?? directory);
|
|
37
|
-
|
|
38
|
-
const files = await globby(["**/*.{ts,tsx}", "!index.{ts,tsx}", ...excluded], {
|
|
39
|
-
cwd: path.join(cwd, directory)
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const exports = files
|
|
43
|
-
.sort((a, b) => a.localeCompare(b))
|
|
44
|
-
.map((file) => {
|
|
45
|
-
// TODO set .js after all configuration are ok to resolve .js
|
|
46
|
-
return `export * from "./${file.replace(".ts", ".js")}";`;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const content = ["/**", " * @file Automatically generated by @tsed/barrels.", " */", ...exports];
|
|
50
|
-
|
|
51
|
-
await writeFile(join(baseIndex, "index.ts"), content.join("\n") + "\n", {encoding: "utf8"});
|
|
52
|
-
});
|
|
41
|
+
const promises = [...directories.keys()].map((directory) => generateIndex(directory, {excluded, cwd}));
|
|
53
42
|
|
|
54
43
|
await Promise.all(promises);
|
|
55
44
|
}
|