fabrique 0.2.5 → 0.3.3
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.7.0.cjs} +292 -291
- package/.yarnrc.yml +1 -1
- package/README.md +13 -11
- 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.7.0.cjs} +292 -291
- package/templates/lib/.yarnrc.yml +1 -1
- package/templates/lib/CONTRIBUTING.md +2 -2
- package/templates/lib/LICENSE +1 -1
- package/templates/lib/README.md +5 -0
- package/templates/lib/fabrique/actions/build.js +205 -71
- package/templates/lib/fabrique/actions/publish.js +4 -3
- 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 +12 -0
- package/templates/lib/vitest.config.ts +12 -1
- package/templates/lib/yarn.lock +0 -1734
package/.yarnrc.yml
CHANGED
package/README.md
CHANGED
|
@@ -67,13 +67,13 @@ fabrique [CMD]
|
|
|
67
67
|
#### create
|
|
68
68
|
|
|
69
69
|
```shell
|
|
70
|
-
npx fabrique
|
|
70
|
+
npx fabrique create lib [name]
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
##### example
|
|
74
74
|
|
|
75
75
|
```shell
|
|
76
|
-
npx fabrique create @my-company/my-library
|
|
76
|
+
npx fabrique create lib @my-company/my-library
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
##### action
|
|
@@ -90,6 +90,7 @@ You'll be prompted for a description, author and git url.
|
|
|
90
90
|
#### upgrade
|
|
91
91
|
|
|
92
92
|
```shell
|
|
93
|
+
# from the root of a "fabrique" project
|
|
93
94
|
npx fabrique upgrade
|
|
94
95
|
```
|
|
95
96
|
|
|
@@ -107,6 +108,7 @@ It tries to be non-destructive.
|
|
|
107
108
|
#### refactor
|
|
108
109
|
|
|
109
110
|
```shell
|
|
111
|
+
# from the directory we want to refactor
|
|
110
112
|
npx fabrique refactor [from] [to]
|
|
111
113
|
```
|
|
112
114
|
|
|
@@ -116,10 +118,10 @@ npx fabrique refactor [from] [to]
|
|
|
116
118
|
npx fabrique refactor my-component my-new-component
|
|
117
119
|
```
|
|
118
120
|
|
|
119
|
-
> Refactors all files and directories
|
|
120
|
-
>
|
|
121
|
+
> Refactors all files and directories having `my-component` as name into `my-new-component` (recursively).
|
|
122
|
+
> 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
123
|
|
|
122
|
-
If we run
|
|
124
|
+
If we run this command with the following files structure:
|
|
123
125
|
|
|
124
126
|
- some-component
|
|
125
127
|
- my-component
|
|
@@ -135,7 +137,7 @@ We get:
|
|
|
135
137
|
- my-new-component-abc
|
|
136
138
|
- my-new-component-abc.ts
|
|
137
139
|
|
|
138
|
-
|
|
140
|
+
If `my-component.ts` has this content:
|
|
139
141
|
|
|
140
142
|
```ts
|
|
141
143
|
class MyComponent {}
|
|
@@ -160,7 +162,7 @@ function my_new_component(myNewComponent: MyNewComponent) {}
|
|
|
160
162
|
This command refactors files and directories recursively from the `cwd` (by default, the current directory in which the script is executed).
|
|
161
163
|
It preserves the case of the names (ex: `dash-case`, or `cameCase`).
|
|
162
164
|
|
|
163
|
-
> INFO: run the command inside the
|
|
165
|
+
> INFO: run the command inside the folder that you want to refactor.
|
|
164
166
|
|
|
165
167
|
##### options
|
|
166
168
|
|
|
@@ -175,15 +177,15 @@ It preserves the case of the names (ex: `dash-case`, or `cameCase`).
|
|
|
175
177
|
npx fabrique verdaccio
|
|
176
178
|
```
|
|
177
179
|
|
|
178
|
-
Installs and
|
|
180
|
+
Installs and launches [verdaccio](https://verdaccio.org/). This is useful to debug interdependent libraries.
|
|
179
181
|
|
|
180
182
|
Let's say we have:
|
|
181
183
|
|
|
182
184
|
- a library `my-lib-a`
|
|
183
|
-
-
|
|
185
|
+
- another library `my-lib-b` with `my-lib-a` as `dependency`
|
|
184
186
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
+
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`,
|
|
188
|
+
then, we'll consume this dev version on `my-lib-b`.
|
|
187
189
|
|
|
188
190
|
> We choose verdaccio instead of `npm link` because versions and dev packages are unique with a package registry.
|
|
189
191
|
>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fabrique",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.3",
|
|
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.7.0",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@inquirer/prompts": "^7.
|
|
25
|
-
"prettier": "^3.
|
|
24
|
+
"@inquirer/prompts": "^7.4.0",
|
|
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
|
+
}
|