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/.yarnrc.yml CHANGED
@@ -3,4 +3,4 @@ nodeLinker: node-modules
3
3
  unsafeHttpWhitelist:
4
4
  - localhost
5
5
 
6
- yarnPath: .yarn/releases/yarn-4.6.0.cjs
6
+ yarnPath: .yarn/releases/yarn-4.7.0.cjs
package/README.md CHANGED
@@ -67,13 +67,13 @@ fabrique [CMD]
67
67
  #### create
68
68
 
69
69
  ```shell
70
- npx fabrique upgrade lib [name]
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 containing `my-component` as name into `my-new-component` (recursively).
120
- > And all text content `my-component` (or derived cases) into `my-new-component` (keeping the same case).
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 it with the following files:
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
- And with this file content:
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 folder that you want to refactor.
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 lauches [verdaccio](https://verdaccio.org/). This is useful to debug interdependent libraries.
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
- - a library `my-lib-b` with `my-lib-a` as `dependency`
185
+ - another library `my-lib-b` with `my-lib-a` as `dependency`
184
186
 
185
- If we're working on `my-lib-a`, and want to test if it works on `my-lib-b`, we'll publish a `dev` version of `my-lib-a` on a local `verdaccio`.
186
- And consume this dev version on `my-lib-b`.
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.2.5",
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.6.0",
22
+ "packageManager": "yarn@4.7.0",
23
23
  "devDependencies": {
24
- "@inquirer/prompts": "^7.2.1",
25
- "prettier": "^3.4.2",
24
+ "@inquirer/prompts": "^7.4.0",
25
+ "prettier": "^3.5.3",
26
26
  "prettier-plugin-organize-imports": "^4.1.0",
27
- "typescript": "^5.7.2"
27
+ "typescript": "^5.8.2"
28
28
  },
29
29
  "dependencies": {
30
30
  "chalk": "^5.4.1",
31
- "commander": "^13.0.0"
31
+ "commander": "^13.1.0"
32
32
  }
33
33
  }
@@ -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 { explore } from '../helpers/fs/explore.js';
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 refactor = createRefactorFunction(from, to);
17
-
18
- for await (const [path, stats] of explore(cwd)) {
19
- if (stats.isFile()) {
20
- await refactorFileContent(path, refactor, dry);
21
- await refactorFileName(path, refactor, dry);
22
- } else if (stats.isDirectory()) {
23
- await refactorFileName(path, refactor, dry);
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
  /*----------*/
@@ -1,4 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import process from 'node:process';
2
3
 
3
4
  /**
4
5
  * Runs "command" into the terminal.
@@ -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
+ }
@@ -2,6 +2,6 @@
2
2
  "singleQuote": true,
3
3
  "printWidth": 100,
4
4
  "singleAttributePerLine": true,
5
- "organizeImportsSkipDestructiveCodeActions": true,
5
+ "organizeImportsSkipDestructiveCodeActions": false,
6
6
  "plugins": ["prettier-plugin-organize-imports"]
7
7
  }