@tsed/barrels 7.71.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.
Files changed (2) hide show
  1. package/index.mjs +84 -0
  2. package/package.json +19 -0
package/index.mjs ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ts-node
2
+ import fs from "fs-extra";
3
+ import globby from "globby";
4
+ import {join} from "node:path";
5
+
6
+ function resolveConfig() {
7
+ return [
8
+ join(process.cwd(), ".barrelsby.json"),
9
+ join(process.cwd(), ".barrels.json")
10
+ ].find((path) => {
11
+ return fs.existsSync(path);
12
+ });
13
+ }
14
+
15
+ function getConfig() {
16
+ const configPath = resolveConfig();
17
+
18
+ if (!configPath) {
19
+ return {};
20
+ }
21
+
22
+ return fs.readJSON(configPath, "utf8");
23
+ }
24
+
25
+ async function cleanIndex(cwd, excluded) {
26
+ const patterns = [
27
+ "**/index.ts",
28
+ ...excluded
29
+ ];
30
+
31
+ const files = await globby(patterns, {
32
+ cwd: cwd
33
+ });
34
+
35
+ return Promise.all(files.map((file) => fs.unlink(join(cwd, file))));
36
+ }
37
+
38
+ async function build() {
39
+ const {
40
+ directory = ["./src"],
41
+ exclude = ["**/__mock__", "**/__mocks__", "**/*.spec.ts", "**/*.benchmark.ts"],
42
+ delete: shouldDelete
43
+ } = await getConfig();
44
+ const excluded = exclude
45
+ .map((path) => `!${path}`)
46
+ .concat(directory.map((path) => `!${path}/index.ts`));
47
+
48
+ const promises = directory
49
+ .map(async (directory) => {
50
+ const baseIndex = join(process.cwd(), directory);
51
+
52
+ // if (shouldDelete) {
53
+ // await cleanIndex(directory, excluded);
54
+ // }
55
+
56
+ const files = await globby([
57
+ "**/*.ts",
58
+ "!index.ts",
59
+ ...excluded
60
+ ], {
61
+ cwd: directory
62
+ });
63
+
64
+ const exports = files
65
+ .sort((a, b) => a.localeCompare(b))
66
+ .map((file) => {
67
+ return `export * from "./${file.replace(".ts", ".js")}";`;
68
+ });
69
+
70
+ const content = [
71
+ "/**",
72
+ " * @file Automatically generated by @tsed/barrels.",
73
+ " */",
74
+ ...exports
75
+ ];
76
+
77
+ await fs.writeFile(join(baseIndex, "index.ts"), content.join("\n") + "\n", {encoding: "utf8"});
78
+ });
79
+
80
+ await Promise.all(promises);
81
+ }
82
+
83
+
84
+ await build();
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@tsed/barrels",
3
+ "version": "7.71.0",
4
+ "bin": "./index.mjs",
5
+ "type": "module",
6
+ "dependencies": {
7
+ "commander": "12.1.0"
8
+ },
9
+ "devDependencies": {},
10
+ "peerDependencies": {},
11
+ "main": "",
12
+ "repository": "https://github.com/tsedio/tsed",
13
+ "bugs": {
14
+ "url": "https://github.com/tsedio/tsed/issues"
15
+ },
16
+ "homepage": "https://github.com/tsedio/tsed/tree/production/tools/barrels",
17
+ "author": "Romain Lenzotti",
18
+ "license": "MIT"
19
+ }