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