fabrique 0.2.5 → 0.3.5
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.
- package/.yarn/releases/{yarn-4.6.0.cjs → yarn-4.8.1.cjs} +346 -345
- package/.yarnrc.yml +1 -1
- package/README.md +29 -22
- package/package.json +6 -6
- package/src/actions/refactor.js +10 -11
- package/src/helpers/cmd.js +1 -0
- package/src/helpers/fs/explore-directory-sequentially.js +19 -0
- package/templates/lib/.prettierrc +1 -1
- package/templates/lib/.yarn/releases/{yarn-4.6.0.cjs → yarn-4.8.1.cjs} +346 -345
- package/templates/lib/.yarnrc.yml +1 -1
- package/templates/lib/CONTRIBUTING.md +33 -4
- package/templates/lib/LICENSE +1 -1
- package/templates/lib/README.md +5 -0
- package/templates/lib/fabrique/actions/build-and-publish.js +5 -0
- package/templates/lib/fabrique/actions/build.js +205 -71
- package/templates/lib/fabrique/actions/cli/generate-changelog.cli.js +3 -0
- package/templates/lib/fabrique/actions/cli/git-tag.cli.js +1 -0
- package/templates/lib/fabrique/actions/generate-changelog.js +7 -0
- package/templates/lib/fabrique/actions/git-tag.js +27 -0
- package/templates/lib/fabrique/actions/publish.js +5 -4
- package/templates/lib/fabrique/constants/root-path.constant.js +4 -0
- package/templates/lib/fabrique/helpers/cmd.js +1 -0
- package/templates/lib/fabrique/helpers/explore-directory.js +5 -2
- package/templates/lib/fabrique/test/tools.ts +9 -1
- package/templates/lib/package.json +9 -4
- package/templates/lib/tsconfig.build.json +6 -11
- package/templates/lib/tsconfig.json +46 -19
- package/templates/lib/typedoc.json +17 -0
- package/templates/lib/vitest.config.ts +12 -1
- package/templates/lib/yarn.lock +0 -1734
|
@@ -6,7 +6,7 @@ This projet is open to everyone. Feel free to test the library, share it, improv
|
|
|
6
6
|
|
|
7
7
|
The library requires [Node.js](https://nodejs.org/en) `22+` and [yarn](https://yarnpkg.com/).
|
|
8
8
|
|
|
9
|
-
First, we have to
|
|
9
|
+
First, we have to use the correct version of node:
|
|
10
10
|
|
|
11
11
|
```shell
|
|
12
12
|
nvm use
|
|
@@ -20,6 +20,12 @@ Then, we have to use the proper package manager (here `yarn`):
|
|
|
20
20
|
corepack enable
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
Start a local verdaccio:
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
npx fabrique verdaccio
|
|
27
|
+
```
|
|
28
|
+
|
|
23
29
|
And install the dependencies:
|
|
24
30
|
|
|
25
31
|
```shell
|
|
@@ -30,17 +36,40 @@ yarn install
|
|
|
30
36
|
|
|
31
37
|
- The source code is located in the `src` directory.
|
|
32
38
|
- The projet uses [prettier](https://prettier.io/) to format the code. You'll want to enable and configure it in your IDE.
|
|
33
|
-
- The tests
|
|
39
|
+
- The tests run with [vitest](https://vitest.dev)
|
|
34
40
|
|
|
35
41
|
### Commands
|
|
36
42
|
|
|
37
43
|
- `fb:build`: builds the library.
|
|
38
44
|
- converts the typescript files into javascript files, copies the scss files, and assembles all the assets to create a package ready to be published.
|
|
45
|
+
- some files are handled differently:
|
|
46
|
+
- `*.protected.{ts,scss}` or `**/*.protected/**`: these files are exported under `package-name/protected`
|
|
47
|
+
- this is indented to expose parts of the code that should be restricted to advanced users only, or shared to other libraries requiring _internal_ control.
|
|
48
|
+
- `*.private.{ts,scss}` or `/*.private/**`: these files are **not** exported.
|
|
49
|
+
- this is indented to consume parts of the code internally, and not expose them publicly.
|
|
39
50
|
- `fb:format`: formats the code using `prettier`.
|
|
40
51
|
- `fb:test`: runs the tests using `vitest`.
|
|
52
|
+
- `fb:test:coverage`: runs the tests with coverage.
|
|
53
|
+
- by default, 100% code coverage is required, to enforce good quality.
|
|
54
|
+
- `fb:bench`: runs the bench tests.
|
|
55
|
+
- `fb:typedoc`: generates the documentation.
|
|
56
|
+
- if the library exposes publicly only a few and/or simple parts, the documentation may be defined in the `README.md` instead.
|
|
41
57
|
- `fb:prod`: builds the lib in `prod` mode.
|
|
42
58
|
- builds and publishes the lib on npm as a _prod_ version.
|
|
43
|
-
- `fb:dev`: builds the lib in `dev` .
|
|
59
|
+
- `fb:dev`: builds the lib in `dev` mode.
|
|
44
60
|
- builds and publishes the lib on a local `verdaccio` with a `dev` tag.
|
|
45
|
-
-
|
|
61
|
+
- a local `verdaccio` is used to debug/test your library in another project:
|
|
62
|
+
- it is better than `npm link`, as it enforce a specific version, and allows some dependencies to be `dev` too.
|
|
63
|
+
- `fb:rc`: builds the lib in `rc` mode.
|
|
46
64
|
- builds and publishes the lib on npm with a `rc` tag.
|
|
65
|
+
- to test before production and final release
|
|
66
|
+
|
|
67
|
+
### To create an MR
|
|
68
|
+
|
|
69
|
+
1. fork the repository
|
|
70
|
+
1. add the feature/fix by modifying the code in the `src/` directory
|
|
71
|
+
1. add/write some tests until 100% code coverage is reached (run the tests with `yarn fb:test:coverage`)
|
|
72
|
+
1. format the code, using the command `yarn fb:format`
|
|
73
|
+
1. commit and push your work following the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) convention
|
|
74
|
+
1. create an MR from your repository to the upstream repository, explaining clearly what was added/fixed.
|
|
75
|
+
|
package/templates/lib/LICENSE
CHANGED
package/templates/lib/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { build } from './build.js';
|
|
2
|
+
import { gitTag } from './git-tag.js';
|
|
2
3
|
import { publish } from './publish.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -9,4 +10,8 @@ import { publish } from './publish.js';
|
|
|
9
10
|
export async function buildAndPublish(options) {
|
|
10
11
|
await build(options);
|
|
11
12
|
await publish(options);
|
|
13
|
+
|
|
14
|
+
if (options.mode === 'prod') {
|
|
15
|
+
await gitTag();
|
|
16
|
+
}
|
|
12
17
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { isAbsolute, join } from 'node:path';
|
|
3
3
|
import process from 'node:process';
|
|
4
|
+
import { ROOT_PATH } from '../constants/root-path.constant.js';
|
|
4
5
|
import { cmd } from '../helpers/cmd.js';
|
|
5
6
|
import { exploreDirectoryFiles } from '../helpers/explore-directory.js';
|
|
6
7
|
|
|
@@ -10,9 +11,8 @@ import { exploreDirectoryFiles } from '../helpers/explore-directory.js';
|
|
|
10
11
|
* @return {Promise<void>}
|
|
11
12
|
*/
|
|
12
13
|
export async function build({ mode = 'prod' } = {}) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const destinationPath = './dist';
|
|
14
|
+
const sourcePath = join(ROOT_PATH, 'src');
|
|
15
|
+
const destinationPath = join(ROOT_PATH, 'dist');
|
|
16
16
|
|
|
17
17
|
await removeDestination(destinationPath);
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ export async function build({ mode = 'prod' } = {}) {
|
|
|
20
20
|
const [withProtected] = await Promise.all([
|
|
21
21
|
buildTypescript(sourcePath),
|
|
22
22
|
buildScss(sourcePath, destinationPath),
|
|
23
|
-
copyOtherFiles(
|
|
23
|
+
copyOtherFiles(ROOT_PATH, destinationPath),
|
|
24
24
|
]);
|
|
25
25
|
|
|
26
26
|
await buildPackageJsonFile(destinationPath, {
|
|
@@ -45,6 +45,49 @@ async function removeDestination(destinationPath) {
|
|
|
45
45
|
await rm(destinationPath, { recursive: true, force: true });
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Returns true if `path` is a `protected` directory.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} path
|
|
52
|
+
* @return boolean
|
|
53
|
+
*/
|
|
54
|
+
function isProtectedDirectory(path) {
|
|
55
|
+
return path.endsWith('.protected');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns true if `path` is inside a `protected` directory.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} path
|
|
62
|
+
* @return boolean
|
|
63
|
+
*/
|
|
64
|
+
function isInProtectedDirectory(path) {
|
|
65
|
+
return path.includes('.protected/');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Returns true if `path` is a `private` directory.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} path
|
|
72
|
+
* @return boolean
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
function isPrivateDirectory(path) {
|
|
76
|
+
return path.endsWith('.private');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns true if `path` is inside a `private` directory.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} path
|
|
83
|
+
* @return boolean
|
|
84
|
+
*/
|
|
85
|
+
function isInPrivateDirectory(path) {
|
|
86
|
+
return path.includes('.private/');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* TYPESCRIPT */
|
|
90
|
+
|
|
48
91
|
/**
|
|
49
92
|
* Builds the typescript part.
|
|
50
93
|
*
|
|
@@ -68,46 +111,86 @@ async function buildTypescript(sourcePath) {
|
|
|
68
111
|
return typescriptProtectedIndexFilePath !== null;
|
|
69
112
|
}
|
|
70
113
|
|
|
114
|
+
function generateExportEsmLine(path) {
|
|
115
|
+
return `export * from './${path.replaceAll('\\', '/').slice(0, -3)}.js';\n`;
|
|
116
|
+
}
|
|
117
|
+
|
|
71
118
|
/**
|
|
72
|
-
*
|
|
119
|
+
* Returns true if `path` is a `typescript` file.
|
|
73
120
|
*
|
|
74
|
-
* @param {string}
|
|
75
|
-
* @
|
|
76
|
-
* @return {Promise<void>}
|
|
121
|
+
* @param {string} path
|
|
122
|
+
* @return boolean
|
|
77
123
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
await buildScssIndexFile(destinationPath);
|
|
124
|
+
function isTsFile(path) {
|
|
125
|
+
return path.endsWith('.ts');
|
|
81
126
|
}
|
|
82
127
|
|
|
83
|
-
|
|
84
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Returns true if `path` is a typescript `test or spec` file.
|
|
130
|
+
*
|
|
131
|
+
* @param {string} path
|
|
132
|
+
* @return boolean
|
|
133
|
+
*/
|
|
134
|
+
function isTsTestOrSpecFile(path) {
|
|
135
|
+
return path.endsWith('.test.ts') || path.endsWith('.spec.ts');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns true if `path` is a typescript `bench` file.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} path
|
|
142
|
+
* @return boolean
|
|
143
|
+
*/
|
|
144
|
+
function isTsBenchFile(path) {
|
|
145
|
+
return path.endsWith('.bench.ts');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Returns true if `path` is a typescript `protected` file.
|
|
150
|
+
*
|
|
151
|
+
* @param {string} path
|
|
152
|
+
* @return boolean
|
|
153
|
+
*/
|
|
154
|
+
function isTsProtectedFile(path) {
|
|
155
|
+
return path.endsWith('.protected.ts');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Returns true if `path` is a typescript `private` file.
|
|
160
|
+
*
|
|
161
|
+
* @param {string} path
|
|
162
|
+
* @return boolean
|
|
163
|
+
*/
|
|
164
|
+
function isTsPrivateFile(path) {
|
|
165
|
+
return path.endsWith('.private.ts');
|
|
85
166
|
}
|
|
86
167
|
|
|
87
168
|
/**
|
|
88
169
|
* Builds the typescript index file used to export all public APIs.
|
|
89
170
|
*
|
|
90
|
-
* @param {string}
|
|
171
|
+
* @param {string} sourcePath
|
|
91
172
|
* @return {Promise<string>}
|
|
92
173
|
*/
|
|
93
|
-
async function buildTypescriptIndexFile(
|
|
174
|
+
async function buildTypescriptIndexFile(sourcePath) {
|
|
94
175
|
console.log('Building typescript index file...');
|
|
95
176
|
|
|
96
177
|
let content = '';
|
|
97
178
|
|
|
98
|
-
for await (const path of exploreDirectoryFiles(
|
|
99
|
-
relativeTo:
|
|
179
|
+
for await (const path of exploreDirectoryFiles(sourcePath, {
|
|
180
|
+
relativeTo: sourcePath,
|
|
100
181
|
pick: (path, { isFile }) => {
|
|
101
182
|
if (isFile) {
|
|
102
183
|
return (
|
|
103
|
-
path
|
|
104
|
-
!
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
184
|
+
isTsFile(path) &&
|
|
185
|
+
!(
|
|
186
|
+
isTsTestOrSpecFile(path) ||
|
|
187
|
+
isTsBenchFile(path) ||
|
|
188
|
+
isTsProtectedFile(path) ||
|
|
189
|
+
isTsPrivateFile(path)
|
|
190
|
+
)
|
|
108
191
|
);
|
|
109
192
|
} else {
|
|
110
|
-
return !path
|
|
193
|
+
return !(isProtectedDirectory(path) || isPrivateDirectory(path));
|
|
111
194
|
}
|
|
112
195
|
},
|
|
113
196
|
})) {
|
|
@@ -118,7 +201,7 @@ async function buildTypescriptIndexFile(cwd = process.cwd()) {
|
|
|
118
201
|
throw new Error('Nothing exported.');
|
|
119
202
|
}
|
|
120
203
|
|
|
121
|
-
const indexFilePath = join(
|
|
204
|
+
const indexFilePath = join(sourcePath, 'index.ts');
|
|
122
205
|
await writeFile(indexFilePath, content + '\n');
|
|
123
206
|
|
|
124
207
|
return indexFilePath;
|
|
@@ -127,23 +210,26 @@ async function buildTypescriptIndexFile(cwd = process.cwd()) {
|
|
|
127
210
|
/**
|
|
128
211
|
* Builds the typescript index file used to export all protected APIs.
|
|
129
212
|
*
|
|
130
|
-
* @param {string}
|
|
213
|
+
* @param {string} sourcePath
|
|
131
214
|
* @return {Promise<string | null>}
|
|
132
215
|
*/
|
|
133
|
-
async function buildTypescriptProtectedIndexFile(
|
|
216
|
+
async function buildTypescriptProtectedIndexFile(sourcePath) {
|
|
134
217
|
console.log('Building typescript protected index file...');
|
|
135
218
|
|
|
136
219
|
let content = '';
|
|
137
220
|
|
|
138
|
-
for await (const path of exploreDirectoryFiles(
|
|
139
|
-
relativeTo:
|
|
221
|
+
for await (const path of exploreDirectoryFiles(sourcePath, {
|
|
222
|
+
relativeTo: sourcePath,
|
|
140
223
|
pick: (path, { isFile }) => {
|
|
141
224
|
if (isFile) {
|
|
142
225
|
return (
|
|
143
|
-
path
|
|
226
|
+
isTsProtectedFile(path) ||
|
|
227
|
+
(isInProtectedDirectory(path) &&
|
|
228
|
+
isTsFile(path) &&
|
|
229
|
+
!(isTsTestOrSpecFile(path) || isTsBenchFile(path) || isTsPrivateFile(path)))
|
|
144
230
|
);
|
|
145
231
|
} else {
|
|
146
|
-
return !path
|
|
232
|
+
return !isPrivateDirectory(path);
|
|
147
233
|
}
|
|
148
234
|
},
|
|
149
235
|
})) {
|
|
@@ -154,7 +240,7 @@ async function buildTypescriptProtectedIndexFile(cwd = process.cwd()) {
|
|
|
154
240
|
return null;
|
|
155
241
|
}
|
|
156
242
|
|
|
157
|
-
const indexFilePath = join(
|
|
243
|
+
const indexFilePath = join(sourcePath, 'index.protected.ts');
|
|
158
244
|
await writeFile(indexFilePath, content + '\n');
|
|
159
245
|
|
|
160
246
|
return indexFilePath;
|
|
@@ -163,13 +249,13 @@ async function buildTypescriptProtectedIndexFile(cwd = process.cwd()) {
|
|
|
163
249
|
/**
|
|
164
250
|
* Compiles the typescript files.
|
|
165
251
|
*
|
|
166
|
-
* @param {string | undefined }
|
|
252
|
+
* @param {string | undefined } rootPath
|
|
167
253
|
* @return {Promise<void>}
|
|
168
254
|
*/
|
|
169
|
-
async function compileTypescript(
|
|
255
|
+
async function compileTypescript(rootPath = process.cwd()) {
|
|
170
256
|
console.log('Compiling typescript...');
|
|
171
257
|
|
|
172
|
-
await cmd('tsc', ['-p', './tsconfig.build.json'], { cwd });
|
|
258
|
+
await cmd('tsc', ['-p', './tsconfig.build.json'], { cwd: rootPath });
|
|
173
259
|
}
|
|
174
260
|
|
|
175
261
|
/**
|
|
@@ -182,46 +268,102 @@ async function compileTypescript(cwd = process.cwd()) {
|
|
|
182
268
|
async function copyTypescriptFiles(sourcePath, destinationPath) {
|
|
183
269
|
console.log('Copying typescript files...');
|
|
184
270
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
271
|
+
throw 'TODO';
|
|
272
|
+
// for await (const path of exploreDirectoryFiles(sourcePath, {
|
|
273
|
+
// relativeTo: sourcePath,
|
|
274
|
+
// pick: (path, { isFile }) => {
|
|
275
|
+
// if (isFile) {
|
|
276
|
+
// return (
|
|
277
|
+
// path.endsWith('.ts') &&
|
|
278
|
+
// !path.endsWith('.spec.ts') &&
|
|
279
|
+
// !path.endsWith('.test.ts') &&
|
|
280
|
+
// !path.endsWith('.bench.ts')
|
|
281
|
+
// );
|
|
282
|
+
// } else {
|
|
283
|
+
// return true;
|
|
284
|
+
// }
|
|
285
|
+
// },
|
|
286
|
+
// })) {
|
|
287
|
+
// await cp(join(sourcePath, path), join(destinationPath, path));
|
|
288
|
+
// }
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Removes the index file.
|
|
293
|
+
*
|
|
294
|
+
* @param {string} indexFilePath
|
|
295
|
+
* @return {Promise<void>}
|
|
296
|
+
*/
|
|
297
|
+
async function removeTypescriptIndexFile(indexFilePath) {
|
|
298
|
+
await rm(indexFilePath);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/* SCSS*/
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Builds the scss part.
|
|
305
|
+
*
|
|
306
|
+
* @param {string} sourcePath
|
|
307
|
+
* @param {string} destinationPath
|
|
308
|
+
* @return {Promise<void>}
|
|
309
|
+
*/
|
|
310
|
+
async function buildScss(sourcePath, destinationPath) {
|
|
311
|
+
await copyScssFiles(sourcePath, destinationPath);
|
|
312
|
+
await buildScssIndexFile(destinationPath);
|
|
197
313
|
}
|
|
198
314
|
|
|
199
315
|
function generateExportScssLine(path) {
|
|
200
316
|
return `@forward './${path.slice(0, -5)}';\n`;
|
|
201
317
|
}
|
|
202
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Returns true if `path` is a `scss` file.
|
|
321
|
+
*
|
|
322
|
+
* @param {string} path
|
|
323
|
+
* @return boolean
|
|
324
|
+
*/
|
|
325
|
+
function isScssFile(path) {
|
|
326
|
+
return path.endsWith('.scss');
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Returns true if `path` is a scss `protected` file.
|
|
331
|
+
*
|
|
332
|
+
* @param {string} path
|
|
333
|
+
* @return boolean
|
|
334
|
+
*/
|
|
335
|
+
function isScssProtectedFile(path) {
|
|
336
|
+
return path.endsWith('.protected.scss');
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Returns true if `path` is a scss `private` file.
|
|
341
|
+
*
|
|
342
|
+
* @param {string} path
|
|
343
|
+
* @return boolean
|
|
344
|
+
*/
|
|
345
|
+
function isScssPrivateFile(path) {
|
|
346
|
+
return path.endsWith('.private.scss');
|
|
347
|
+
}
|
|
348
|
+
|
|
203
349
|
/**
|
|
204
350
|
* Builds the scss index file used to export all public styles.
|
|
205
351
|
*
|
|
206
|
-
* @param {string}
|
|
352
|
+
* @param {string} sourcePath
|
|
207
353
|
* @return {Promise<void>}
|
|
208
354
|
*/
|
|
209
|
-
async function buildScssIndexFile(
|
|
355
|
+
async function buildScssIndexFile(sourcePath) {
|
|
210
356
|
console.log('Building scss index file...');
|
|
211
357
|
|
|
212
358
|
let content = '';
|
|
213
359
|
|
|
214
|
-
for await (const path of exploreDirectoryFiles(
|
|
215
|
-
relativeTo:
|
|
360
|
+
for await (const path of exploreDirectoryFiles(sourcePath, {
|
|
361
|
+
relativeTo: sourcePath,
|
|
216
362
|
pick: (path, { isFile }) => {
|
|
217
363
|
if (isFile) {
|
|
218
|
-
return (
|
|
219
|
-
path.endsWith('.scss') &&
|
|
220
|
-
!path.endsWith('.protected.scss') &&
|
|
221
|
-
!path.endsWith('.private.scss')
|
|
222
|
-
);
|
|
364
|
+
return isScssFile(path) && !(isScssProtectedFile(path) && isScssPrivateFile(path));
|
|
223
365
|
} else {
|
|
224
|
-
return !path
|
|
366
|
+
return !(isProtectedDirectory(path) || isPrivateDirectory(path));
|
|
225
367
|
}
|
|
226
368
|
},
|
|
227
369
|
})) {
|
|
@@ -231,7 +373,7 @@ async function buildScssIndexFile(cwd = process.cwd()) {
|
|
|
231
373
|
if (content === '') {
|
|
232
374
|
console.log('=> No scss file to export.');
|
|
233
375
|
} else {
|
|
234
|
-
const indexFilePath = join(
|
|
376
|
+
const indexFilePath = join(sourcePath, 'index.scss');
|
|
235
377
|
await writeFile(indexFilePath, content + '\n');
|
|
236
378
|
}
|
|
237
379
|
}
|
|
@@ -250,7 +392,7 @@ async function copyScssFiles(sourcePath, destinationPath) {
|
|
|
250
392
|
relativeTo: sourcePath,
|
|
251
393
|
pick: (path, { isFile }) => {
|
|
252
394
|
if (isFile) {
|
|
253
|
-
return path
|
|
395
|
+
return isScssFile(path);
|
|
254
396
|
} else {
|
|
255
397
|
return true;
|
|
256
398
|
}
|
|
@@ -312,6 +454,8 @@ function fixScssFilePath(path) {
|
|
|
312
454
|
return path;
|
|
313
455
|
}
|
|
314
456
|
|
|
457
|
+
/* OTHER */
|
|
458
|
+
|
|
315
459
|
/**
|
|
316
460
|
* Copies other files.
|
|
317
461
|
*
|
|
@@ -331,26 +475,16 @@ async function copyOtherFiles(rootPath, destinationPath) {
|
|
|
331
475
|
);
|
|
332
476
|
}
|
|
333
477
|
|
|
334
|
-
/**
|
|
335
|
-
* Removes the index file.
|
|
336
|
-
*
|
|
337
|
-
* @param {string} indexFilePath
|
|
338
|
-
* @return {Promise<void>}
|
|
339
|
-
*/
|
|
340
|
-
async function removeTypescriptIndexFile(indexFilePath) {
|
|
341
|
-
await rm(indexFilePath);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
478
|
/**
|
|
345
479
|
* Generates the package.json to publish.
|
|
346
480
|
*
|
|
347
481
|
* @param {string} destinationPath
|
|
348
|
-
* @param {{
|
|
482
|
+
* @param {{ rootPath?: string; mode?: 'dev' | 'rc' | 'prod', withProtected?: boolean }} options
|
|
349
483
|
* @return {Promise<void>}
|
|
350
484
|
*/
|
|
351
485
|
async function buildPackageJsonFile(
|
|
352
486
|
destinationPath,
|
|
353
|
-
{
|
|
487
|
+
{ rootPath = process.cwd(), mode = 'prod', withProtected = false } = {},
|
|
354
488
|
) {
|
|
355
489
|
console.log('Building package.json...');
|
|
356
490
|
|
|
@@ -359,7 +493,7 @@ async function buildPackageJsonFile(
|
|
|
359
493
|
/**
|
|
360
494
|
* @type any
|
|
361
495
|
*/
|
|
362
|
-
const pkg = JSON.parse(await readFile(join(
|
|
496
|
+
const pkg = JSON.parse(await readFile(join(rootPath, fileName), { encoding: 'utf8' }));
|
|
363
497
|
|
|
364
498
|
const indexTypesPath = './index.d.ts';
|
|
365
499
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
gitTag();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { ROOT_PATH } from '../constants/root-path.constant.js';
|
|
4
|
+
import { cmd } from '../helpers/cmd.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Git tag and push
|
|
8
|
+
* @return {Promise<void>}
|
|
9
|
+
*/
|
|
10
|
+
export async function gitTag() {
|
|
11
|
+
const packageJsonPath = join(ROOT_PATH, 'package.json');
|
|
12
|
+
|
|
13
|
+
const version = JSON.parse(
|
|
14
|
+
await readFile(packageJsonPath, {
|
|
15
|
+
encoding: 'utf8',
|
|
16
|
+
}),
|
|
17
|
+
).version;
|
|
18
|
+
|
|
19
|
+
console.log(`Git tag v${version}...`);
|
|
20
|
+
|
|
21
|
+
await cmd('git', ['tag', '-a', `v${version}`, '-m', `release v${version}`], {
|
|
22
|
+
cwd: resolve(ROOT_PATH),
|
|
23
|
+
});
|
|
24
|
+
await cmd('git', ['push', '--tags'], { cwd: resolve(ROOT_PATH) });
|
|
25
|
+
|
|
26
|
+
console.log('Tag published with success !');
|
|
27
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
1
|
+
import { join, resolve } from 'node:path';
|
|
2
|
+
import { ROOT_PATH } from '../constants/root-path.constant.js';
|
|
2
3
|
import { cmd } from '../helpers/cmd.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* Publishes the lib.
|
|
6
7
|
* @param {{ mode?: 'dev' | 'rc' | 'prod'; }} options
|
|
7
8
|
* @return {Promise<void>}
|
|
8
9
|
*/
|
|
9
10
|
export async function publish({ mode = 'prod' } = {}) {
|
|
10
|
-
const packagePath = '
|
|
11
|
+
const packagePath = join(ROOT_PATH, 'dist');
|
|
11
12
|
|
|
12
13
|
console.log('Publishing library...');
|
|
13
14
|
|
|
@@ -55,7 +56,7 @@ export async function publish({ mode = 'prod' } = {}) {
|
|
|
55
56
|
args.push('--tag', options.tag);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
await cmd('npm', args, { cwd:
|
|
59
|
+
await cmd('npm', args, { cwd: resolve(packagePath) });
|
|
59
60
|
|
|
60
61
|
console.log('Library published with success !');
|
|
61
62
|
}
|
|
@@ -6,7 +6,7 @@ import process from 'node:process';
|
|
|
6
6
|
* Runs "command" into the terminal.
|
|
7
7
|
* @param {string} path
|
|
8
8
|
* @param {{relativeTo?: string; pick?: (path: string, type: { isFile: boolean; isDirectory: boolean; }) => boolean; }?} options
|
|
9
|
-
* @return {
|
|
9
|
+
* @return {AsyncGenerator<string>}
|
|
10
10
|
*/
|
|
11
11
|
export async function* exploreDirectoryFiles(path, options) {
|
|
12
12
|
const dir = await opendir(resolve(process.cwd(), path));
|
|
@@ -17,7 +17,10 @@ export async function* exploreDirectoryFiles(path, options) {
|
|
|
17
17
|
options?.relativeTo === undefined ? path : relative(options.relativeTo, path);
|
|
18
18
|
|
|
19
19
|
if (
|
|
20
|
-
options?.pick(relativePath, {
|
|
20
|
+
options?.pick?.(relativePath, {
|
|
21
|
+
isFile: dirent.isFile(),
|
|
22
|
+
isDirectory: dirent.isDirectory(),
|
|
23
|
+
}) ??
|
|
21
24
|
true
|
|
22
25
|
) {
|
|
23
26
|
if (dirent.isFile()) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export namespace testTools {
|
|
2
2
|
export function sleep(t: number): Promise<void> {
|
|
3
|
-
return new Promise((
|
|
3
|
+
return new Promise((resolve) => setTimeout(resolve, t));
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export function polyfillRequestIdleCallback(): void {
|
|
@@ -15,4 +15,12 @@ export namespace testTools {
|
|
|
15
15
|
clearTimeout(handle);
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
export function gc(): void {
|
|
20
|
+
if (typeof (globalThis as any).gc === 'function') {
|
|
21
|
+
return (globalThis as any).gc!();
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error('Missing `gc` function. Did you `--expose-gc` ?');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
18
26
|
}
|