@tsed/barrels 5.3.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 (3) hide show
  1. package/bin/barrels.js +89 -0
  2. package/package.json +28 -0
  3. package/readme.md +82 -0
package/bin/barrels.js ADDED
@@ -0,0 +1,89 @@
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
+ }
44
+
45
+ async function build() {
46
+ const {
47
+ directory = ["./src"],
48
+ exclude = ["**/__mock__", "**/__mocks__", "**/*.spec.ts", "**/*.benchmark.ts"],
49
+ delete: shouldDelete
50
+ } = await getConfig();
51
+
52
+ const excluded = exclude
53
+ .map((path) => `!${path}`)
54
+ .concat(directory.map((path) => `!${path}/index.ts`));
55
+
56
+ const promises = directory
57
+ .map(async (directory) => {
58
+ const baseIndex = join(process.cwd(), directory);
59
+
60
+ const files = await globby([
61
+ "**/*.ts",
62
+ "!index.ts",
63
+ ...excluded
64
+ ], {
65
+ cwd: directory
66
+ });
67
+
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
+ });
84
+
85
+ await Promise.all(promises);
86
+ }
87
+
88
+
89
+ await build();
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@tsed/barrels",
3
+ "description": "A simple tool to generate barrels for your TypeScript project",
4
+ "version": "5.3.0",
5
+ "type": "module",
6
+ "bin": "bin/barrels.js",
7
+ "files": [],
8
+ "keywords": [
9
+ "Ts.ED",
10
+ "barrels"
11
+ ],
12
+ "engines": {
13
+ "node": ">=20"
14
+ },
15
+ "dependencies": {
16
+ "globby": "14.0.2"
17
+ },
18
+ "devDependencies": {},
19
+ "peerDependencies": {},
20
+ "main": "",
21
+ "repository": "https://github.com/tsedio/tsed-cli",
22
+ "bugs": {
23
+ "url": "https://github.com/tsedio/tsed-cli/issues"
24
+ },
25
+ "homepage": "https://github.com/tsedio/tsed-cli/tree/master/packages/barrels",
26
+ "author": "Romain Lenzotti",
27
+ "license": "MIT"
28
+ }
package/readme.md ADDED
@@ -0,0 +1,82 @@
1
+ # @tsed/barrels
2
+
3
+ <p style="text-align: center" align="center">
4
+ <a href="https://tsed.io" target="_blank"><img src="https://tsed.io/tsed-og.png" width="200" alt="Ts.ED logo"/></a>
5
+ </p>
6
+
7
+ [![Build & Release](https://github.com/tsedio/tsed-cli/workflows/Build%20&%20Release/badge.svg?branch=master)](https://github.com/tsedio/tsed-cli/actions?query=workflow%3A%22Build+%26+Release%22)
8
+ [![npm version](https://badge.fury.io/js/%40tsed%2Fcli.svg)](https://badge.fury.io/js/%40tsed%2Fcli)
9
+ [![Known Vulnerabilities](https://snyk.io/test/github/tsedio/tsed-cli/badge.svg)](https://snyk.io/test/github/tsedio/tsed-cli)
10
+ [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
11
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
12
+ [![backers](https://opencollective.com/tsed/tiers/badge.svg)](https://opencollective.com/tsed)
13
+
14
+ > A simple tool to generate barrels for your TypeScript project
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install -g @tsed/barrels
20
+ ```
21
+
22
+ Then create a `barrels.json` configuration:
23
+
24
+ ```
25
+ {
26
+ "directory": [
27
+ "./src"
28
+ ],
29
+ "exclude": [
30
+ "**/__mock__",
31
+ "**/__mocks__",
32
+ "**/*.spec.ts"
33
+ ],
34
+ "delete": true
35
+ }
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```bash
41
+ Usage: barrels
42
+ ```
43
+
44
+ ```shell
45
+ barrels
46
+ ```
47
+
48
+ ## Contributors
49
+
50
+ Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
51
+
52
+ <a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
53
+
54
+ ## Backers
55
+
56
+ Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
57
+
58
+ <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
59
+
60
+ ## Sponsors
61
+
62
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your
63
+ website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
64
+
65
+ ## License
66
+
67
+ The MIT License (MIT)
68
+
69
+ Copyright (c) 2016 - 2023 Romain Lenzotti
70
+
71
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
72
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
73
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
74
+ persons to whom the Software is furnished to do so, subject to the following conditions:
75
+
76
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
77
+ Software.
78
+
79
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
80
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
81
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
82
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.