@tsed/barrels 5.4.0 → 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.
Files changed (2) hide show
  1. package/bin/barrels.js +30 -35
  2. 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 {writeFile, readFile} from "node:fs/promises";
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,42 +53,37 @@ async function build() {
53
53
  .map((path) => `!${path}`)
54
54
  .concat(directory.map((path) => `!${path}/index.ts`));
55
55
 
56
- const directories = await globby(directory, {
57
- cwd: process.cwd(),
58
- onlyDirectories: true
59
- })
60
-
61
- const promises = directories
62
- .map(async (directory) => {
63
- const baseIndex = join(process.cwd(), directory?.path ?? directory);
64
-
65
- const files = await globby([
66
- "**/*.ts",
67
- "!index.ts",
68
- ...excluded
69
- ], {
70
- cwd: directory
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
+ });
73
+
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")}";`;
71
79
  });
72
80
 
73
- const exports = files
74
- .sort((a, b) => a.localeCompare(b))
75
- .map((file) => {
76
- // TODO set .js after all configuration are ok to resolve .js
77
- return `export * from "./${file.replace(".ts", ".js")}";`;
78
- });
79
-
80
- const content = [
81
- "/**",
82
- " * @file Automatically generated by @tsed/barrels.",
83
- " */",
84
- ...exports
85
- ];
86
-
87
- await writeFile(join(baseIndex, "index.ts"), content.join("\n") + "\n", {encoding: "utf8"});
88
- });
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
+ });
89
85
 
90
86
  await Promise.all(promises);
91
87
  }
92
88
 
93
-
94
89
  await build();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsed/barrels",
3
3
  "description": "A simple tool to generate barrels for your TypeScript project",
4
- "version": "5.4.0",
4
+ "version": "5.4.1",
5
5
  "type": "module",
6
6
  "bin": "bin/barrels.js",
7
7
  "files": [],