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
package/.yarnrc.yml
CHANGED
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ The library requires [Node.js](https://nodejs.org/en) `22+` and [yarn](https://y
|
|
|
47
47
|
We recommend to use [npx](https://docs.npmjs.com/cli/v8/commands/npx):
|
|
48
48
|
|
|
49
49
|
```shell
|
|
50
|
-
npx fabrique [
|
|
50
|
+
npx fabrique [cmd]
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
But, you may prefer to install globally `fabrique`:
|
|
@@ -58,38 +58,44 @@ npm install -g fabrique
|
|
|
58
58
|
And run a command with:
|
|
59
59
|
|
|
60
60
|
```shell
|
|
61
|
-
fabrique [
|
|
61
|
+
fabrique [cmd]
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
### List of commands
|
|
66
66
|
|
|
67
|
-
#### create
|
|
67
|
+
#### \[cmd\]: create
|
|
68
68
|
|
|
69
69
|
```shell
|
|
70
|
-
npx fabrique
|
|
70
|
+
npx fabrique create [type] [name]
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
#####
|
|
73
|
+
##### \[type\]: lib
|
|
74
|
+
|
|
75
|
+
###### example
|
|
74
76
|
|
|
75
77
|
```shell
|
|
76
|
-
npx fabrique create @my-company/my-library
|
|
78
|
+
npx fabrique create lib @my-company/my-library
|
|
77
79
|
```
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
###### action
|
|
80
82
|
|
|
81
83
|
This command creates a new library with the name `[name]` inside the folder `./[name]` (in our example: `./@my-company/my-library`).
|
|
82
84
|
You'll be prompted for a description, author and git url.
|
|
83
85
|
|
|
84
86
|
> INFO: run the command where you want to create your project.
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
###### options
|
|
87
89
|
|
|
88
90
|
- `[name]`: the library name
|
|
89
91
|
|
|
90
|
-
|
|
92
|
+
|
|
93
|
+
> NOTE: currently only the `lib` type is supported. More architectures may be developed in the future.
|
|
94
|
+
|
|
95
|
+
#### \[cmd\]: upgrade
|
|
91
96
|
|
|
92
97
|
```shell
|
|
98
|
+
# from the root of a "fabrique" project
|
|
93
99
|
npx fabrique upgrade
|
|
94
100
|
```
|
|
95
101
|
|
|
@@ -104,9 +110,10 @@ It tries to be non-destructive.
|
|
|
104
110
|
|
|
105
111
|
- `--force`: forces an upgrade even if the lib is not a `fabrique` project or if the version is identical. _Use with caution._
|
|
106
112
|
|
|
107
|
-
#### refactor
|
|
113
|
+
#### \[cmd\]: refactor
|
|
108
114
|
|
|
109
115
|
```shell
|
|
116
|
+
# from the directory we want to refactor
|
|
110
117
|
npx fabrique refactor [from] [to]
|
|
111
118
|
```
|
|
112
119
|
|
|
@@ -116,10 +123,10 @@ npx fabrique refactor [from] [to]
|
|
|
116
123
|
npx fabrique refactor my-component my-new-component
|
|
117
124
|
```
|
|
118
125
|
|
|
119
|
-
> Refactors all files and directories
|
|
120
|
-
>
|
|
126
|
+
> Refactors all files and directories having `my-component` as name into `my-new-component` (recursively).
|
|
127
|
+
> AND all text-based files (ex: html, js, ts, css, etc...) containing `my-component` (or derived cases) into `my-new-component` (keeping the same case).
|
|
121
128
|
|
|
122
|
-
If we run
|
|
129
|
+
If we run this command with the following files structure:
|
|
123
130
|
|
|
124
131
|
- some-component
|
|
125
132
|
- my-component
|
|
@@ -135,7 +142,7 @@ We get:
|
|
|
135
142
|
- my-new-component-abc
|
|
136
143
|
- my-new-component-abc.ts
|
|
137
144
|
|
|
138
|
-
|
|
145
|
+
If `my-component.ts` has this content:
|
|
139
146
|
|
|
140
147
|
```ts
|
|
141
148
|
class MyComponent {}
|
|
@@ -160,7 +167,7 @@ function my_new_component(myNewComponent: MyNewComponent) {}
|
|
|
160
167
|
This command refactors files and directories recursively from the `cwd` (by default, the current directory in which the script is executed).
|
|
161
168
|
It preserves the case of the names (ex: `dash-case`, or `cameCase`).
|
|
162
169
|
|
|
163
|
-
> INFO: run the command inside the
|
|
170
|
+
> INFO: run the command inside the folder that you want to refactor.
|
|
164
171
|
|
|
165
172
|
##### options
|
|
166
173
|
|
|
@@ -169,28 +176,28 @@ It preserves the case of the names (ex: `dash-case`, or `cameCase`).
|
|
|
169
176
|
- `--dry` (default: false): runs without modifying the files. This is useful to check if your refactoring is safe or not.
|
|
170
177
|
- `--cwd` (default: current folder): specifies the directory to start from.
|
|
171
178
|
|
|
172
|
-
#### verdaccio
|
|
179
|
+
#### \[cmd\]: verdaccio
|
|
173
180
|
|
|
174
181
|
```shell
|
|
175
182
|
npx fabrique verdaccio
|
|
176
183
|
```
|
|
177
184
|
|
|
178
|
-
Installs and
|
|
185
|
+
Installs and launches [verdaccio](https://verdaccio.org/). This is useful to debug interdependent libraries.
|
|
179
186
|
|
|
180
187
|
Let's say we have:
|
|
181
188
|
|
|
182
189
|
- a library `my-lib-a`
|
|
183
|
-
-
|
|
190
|
+
- another library `my-lib-b` with `my-lib-a` as `dependency`
|
|
184
191
|
|
|
185
|
-
|
|
186
|
-
|
|
192
|
+
When working on `my-lib-a`, if we want to test if our changes works properly on `my-lib-b`, we'll publish a `dev` version of `my-lib-a` on a local `verdaccio`,
|
|
193
|
+
then, we'll consume this dev version on `my-lib-b`.
|
|
187
194
|
|
|
188
195
|
> We choose verdaccio instead of `npm link` because versions and dev packages are unique with a package registry.
|
|
189
196
|
>
|
|
190
197
|
> Thus, we may have `my-lib-b` consuming `my-lib-a-dev.0` and `my-lib-c` consuming `my-lib-a-dev.1`, which is not possible with `npm link`.
|
|
191
198
|
|
|
192
199
|
|
|
193
|
-
#### version
|
|
200
|
+
#### --version
|
|
194
201
|
|
|
195
202
|
```shell
|
|
196
203
|
npx fabrique --version
|
|
@@ -200,7 +207,7 @@ npx fabrique -v
|
|
|
200
207
|
|
|
201
208
|
Returns the current `fabrique` version.
|
|
202
209
|
|
|
203
|
-
#### help
|
|
210
|
+
#### --help
|
|
204
211
|
|
|
205
212
|
```shell
|
|
206
213
|
npx fabrique --help
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fabrique",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"bin": "./src/index.js",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "https://github.com/lifaon74/fabrique"
|
|
21
21
|
},
|
|
22
|
-
"packageManager": "yarn@4.
|
|
22
|
+
"packageManager": "yarn@4.8.1",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@inquirer/prompts": "^7.
|
|
25
|
-
"prettier": "^3.
|
|
24
|
+
"@inquirer/prompts": "^7.4.1",
|
|
25
|
+
"prettier": "^3.5.3",
|
|
26
26
|
"prettier-plugin-organize-imports": "^4.1.0",
|
|
27
|
-
"typescript": "^5.
|
|
27
|
+
"typescript": "^5.8.2"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"chalk": "^5.4.1",
|
|
31
|
-
"commander": "^13.
|
|
31
|
+
"commander": "^13.1.0"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/actions/refactor.js
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { readFile, rename, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { basename, dirname, join } from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { exploreDirectorySequentially } from '../helpers/fs/explore-directory-sequentially.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Refactor recursively many files
|
|
8
8
|
*
|
|
9
|
-
* @param {string} cwd
|
|
10
9
|
* @param {string} from
|
|
11
10
|
* @param {string} to
|
|
12
11
|
* @param {{dry?: boolean, cwd?: string }} options
|
|
13
12
|
* @return {Promise<void>}
|
|
14
13
|
*/
|
|
15
14
|
export async function refactor(from, to, { dry = false, cwd = process.cwd() }) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
await refactorFileContent(
|
|
21
|
-
await refactorFileName(
|
|
22
|
-
} else if (
|
|
23
|
-
await refactorFileName(
|
|
15
|
+
const refactorFnc = createRefactorFunction(from, to);
|
|
16
|
+
|
|
17
|
+
await exploreDirectorySequentially(cwd, async (entryPath, entry) => {
|
|
18
|
+
if (entry.isFile()) {
|
|
19
|
+
await refactorFileContent(entryPath, refactorFnc, dry);
|
|
20
|
+
await refactorFileName(entryPath, refactorFnc, dry);
|
|
21
|
+
} else if (entry.isDirectory()) {
|
|
22
|
+
return await refactorFileName(entryPath, refactorFnc, dry);
|
|
24
23
|
}
|
|
25
|
-
}
|
|
24
|
+
});
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
/*----------*/
|
package/src/helpers/cmd.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { readdir } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} path
|
|
6
|
+
* @param {(path: string, entry: Dirent) => Promise<void | string> | void | string} callback
|
|
7
|
+
* @return {Promise<void>}
|
|
8
|
+
*/
|
|
9
|
+
export async function exploreDirectorySequentially(path, callback) {
|
|
10
|
+
const entries = await readdir(path, { withFileTypes: true });
|
|
11
|
+
|
|
12
|
+
for (const entry of entries) {
|
|
13
|
+
const subPath = join(path, entry.name);
|
|
14
|
+
const newPath = (await callback(subPath, entry)) ?? subPath;
|
|
15
|
+
if (entry.isDirectory()) {
|
|
16
|
+
await exploreDirectorySequentially(newPath, callback);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|