@tsed/barrels 5.3.1 → 6.0.0-alpha.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 +21 -39
  2. package/package.json +5 -2
package/bin/barrels.js CHANGED
@@ -1,14 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import {existsSync} from "node:fs";
3
- import {writeFile, readFile} from "node:fs/promises";
3
+ import {readFile, writeFile} from "node:fs/promises";
4
4
  import {join} from "node:path";
5
+
5
6
  import {globby} from "globby";
6
7
 
7
8
  function resolveConfig() {
8
- return [
9
- join(process.cwd(), ".barrelsby.json"),
10
- join(process.cwd(), ".barrels.json")
11
- ].find((path) => {
9
+ return [join(process.cwd(), ".barrelsby.json"), join(process.cwd(), ".barrels.json")].find((path) => {
12
10
  return existsSync(path);
13
11
  });
14
12
  }
@@ -16,7 +14,7 @@ function resolveConfig() {
16
14
  async function readJSON(path) {
17
15
  const content = await readFile(path, "utf-8");
18
16
 
19
- return JSON.parse(content)
17
+ return JSON.parse(content);
20
18
  }
21
19
 
22
20
  function getConfig() {
@@ -30,10 +28,7 @@ function getConfig() {
30
28
  }
31
29
 
32
30
  async function cleanIndex(cwd, excluded) {
33
- const patterns = [
34
- "**/index.ts",
35
- ...excluded
36
- ];
31
+ const patterns = ["**/index.ts", ...excluded];
37
32
 
38
33
  const files = await globby(patterns, {
39
34
  cwd: cwd
@@ -49,41 +44,28 @@ async function build() {
49
44
  delete: shouldDelete
50
45
  } = await getConfig();
51
46
 
52
- const excluded = exclude
53
- .map((path) => `!${path}`)
54
- .concat(directory.map((path) => `!${path}/index.ts`));
47
+ const excluded = exclude.map((path) => `!${path}`).concat(directory.map((path) => `!${path}/index.ts`));
48
+
49
+ const promises = directory.map(async (directory) => {
50
+ const baseIndex = join(process.cwd(), directory);
55
51
 
56
- const promises = directory
57
- .map(async (directory) => {
58
- const baseIndex = join(process.cwd(), directory);
52
+ const files = await globby(["**/*.ts", "!index.ts", ...excluded], {
53
+ cwd: directory
54
+ });
59
55
 
60
- const files = await globby([
61
- "**/*.ts",
62
- "!index.ts",
63
- ...excluded
64
- ], {
65
- cwd: directory
56
+ const exports = files
57
+ .sort((a, b) => a.localeCompare(b))
58
+ .map((file) => {
59
+ // TODO set .js after all configuration are ok to resolve .js
60
+ return `export * from "./${file.replace(".ts", ".js")}";`;
66
61
  });
67
62
 
68
- const exports = files
69
- .sort((a, b) => a.localeCompare(b))
70
- .map((file) => {
71
- // TODO set .js after all configuration are ok to resolve .js
72
- return `export * from "./${file.replace(".ts", ".js")}";`;
73
- });
74
-
75
- const content = [
76
- "/**",
77
- " * @file Automatically generated by @tsed/barrels.",
78
- " */",
79
- ...exports
80
- ];
81
-
82
- await writeFile(join(baseIndex, "index.ts"), content.join("\n") + "\n", {encoding: "utf8"});
83
- });
63
+ const content = ["/**", " * @file Automatically generated by @tsed/barrels.", " */", ...exports];
64
+
65
+ await writeFile(join(baseIndex, "index.ts"), content.join("\n") + "\n", {encoding: "utf8"});
66
+ });
84
67
 
85
68
  await Promise.all(promises);
86
69
  }
87
70
 
88
-
89
71
  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.3.1",
4
+ "version": "6.0.0-alpha.2",
5
5
  "type": "module",
6
6
  "bin": "bin/barrels.js",
7
7
  "files": [],
@@ -24,5 +24,8 @@
24
24
  },
25
25
  "homepage": "https://github.com/tsedio/tsed-cli/tree/master/packages/barrels",
26
26
  "author": "Romain Lenzotti",
27
- "license": "MIT"
27
+ "license": "MIT",
28
+ "publishConfig": {
29
+ "tag": "alpha"
30
+ }
28
31
  }