@tsed/barrels 5.4.0 → 5.4.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.
Files changed (2) hide show
  1. package/bin/barrels.js +3 -84
  2. package/package.json +4 -1
package/bin/barrels.js CHANGED
@@ -1,94 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import {existsSync} from "node:fs";
3
- import {writeFile, readFile} from "node:fs/promises";
4
- import {join} from "node:path";
5
- import {globby} from "globby";
6
-
7
- function resolveConfig() {
8
- return [
9
- join(process.cwd(), ".barrelsby.json"),
10
- join(process.cwd(), ".barrels.json")
11
- ].find((path) => {
12
- return existsSync(path);
13
- });
14
- }
15
-
16
- async function readJSON(path) {
17
- const content = await readFile(path, "utf-8");
18
-
19
- return JSON.parse(content)
20
- }
21
-
22
- function getConfig() {
23
- const configPath = resolveConfig();
24
-
25
- if (!configPath) {
26
- return {};
27
- }
28
-
29
- return readJSON(configPath);
30
- }
31
-
32
- async function cleanIndex(cwd, excluded) {
33
- const patterns = [
34
- "**/index.ts",
35
- ...excluded
36
- ];
37
-
38
- const files = await globby(patterns, {
39
- cwd: cwd
40
- });
41
-
42
- return Promise.all(files.map((file) => fs.unlink(join(cwd, file))));
43
- }
2
+ import {generateBarrels} from "../src/generate-barrel.js";
3
+ import {getConfig} from "../src/get-config.js";
44
4
 
45
5
  async function build() {
46
6
  const {
47
7
  directory = ["./src"],
48
8
  exclude = ["**/__mock__", "**/__mocks__", "**/*.spec.ts", "**/*.benchmark.ts"],
49
- delete: shouldDelete
50
9
  } = await getConfig();
51
-
52
- const excluded = exclude
53
- .map((path) => `!${path}`)
54
- .concat(directory.map((path) => `!${path}/index.ts`));
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
71
- });
72
-
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
- });
89
-
90
- await Promise.all(promises);
10
+ await generateBarrels({exclude, directory, cwd: process.cwd()});
91
11
  }
92
12
 
93
-
94
13
  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.2",
5
5
  "type": "module",
6
6
  "bin": "bin/barrels.js",
7
7
  "files": [],
@@ -15,6 +15,9 @@
15
15
  "dependencies": {
16
16
  "globby": "14.0.2"
17
17
  },
18
+ "scripts": {
19
+ "test": "node --test test/barrels.integration.spec.js"
20
+ },
18
21
  "devDependencies": {},
19
22
  "peerDependencies": {},
20
23
  "main": "",