@bottomlessmargaritas/formatting-configs 1.1.0 → 2.1.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.
- package/bin/cli.js +36 -6
- package/package.json +15 -7
package/bin/cli.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
readFileSync,
|
|
7
7
|
writeFileSync,
|
|
8
8
|
readdirSync,
|
|
9
|
+
unlinkSync,
|
|
9
10
|
} from "node:fs";
|
|
10
11
|
import { dirname, join, resolve, extname, basename } from "node:path";
|
|
11
12
|
import { fileURLToPath } from "node:url";
|
|
@@ -90,6 +91,7 @@ function projectUsesReact(projectRoot) {
|
|
|
90
91
|
|
|
91
92
|
function copyConfigFiles(projectRoot) {
|
|
92
93
|
const configFiles = readdirSync(CONFIGS_DIR);
|
|
94
|
+
const currentNamespacedFiles = new Set(configFiles.map(namespacedFileName));
|
|
93
95
|
let copied = 0;
|
|
94
96
|
let skipped = 0;
|
|
95
97
|
|
|
@@ -116,7 +118,22 @@ function copyConfigFiles(projectRoot) {
|
|
|
116
118
|
copied++;
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
|
|
121
|
+
// Remove stale namespaced config files from previous versions
|
|
122
|
+
const namespacedPattern = `.${NAMESPACE}.`;
|
|
123
|
+
let removed = 0;
|
|
124
|
+
|
|
125
|
+
for (const file of readdirSync(projectRoot)) {
|
|
126
|
+
if (file.includes(namespacedPattern) && !currentNamespacedFiles.has(file)) {
|
|
127
|
+
if (isDryRun) {
|
|
128
|
+
console.log(`[dry-run] Would remove stale config: ${file}`);
|
|
129
|
+
} else {
|
|
130
|
+
unlinkSync(join(projectRoot, file));
|
|
131
|
+
}
|
|
132
|
+
removed++;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
console.log(`${PKG_NAME}: ${copied} config(s) written, ${skipped} unchanged, ${removed} stale removed`);
|
|
120
137
|
}
|
|
121
138
|
|
|
122
139
|
function updatePackageJsonScripts(projectRoot) {
|
|
@@ -128,23 +145,36 @@ function updatePackageJsonScripts(projectRoot) {
|
|
|
128
145
|
pkg.scripts = {};
|
|
129
146
|
}
|
|
130
147
|
|
|
148
|
+
const currentScriptNames = new Set(Object.keys(SCRIPTS_TO_ADD));
|
|
131
149
|
let added = 0;
|
|
150
|
+
let removed = 0;
|
|
151
|
+
|
|
152
|
+
// Add/update current scripts
|
|
132
153
|
for (const [name, command] of Object.entries(SCRIPTS_TO_ADD)) {
|
|
133
|
-
if (
|
|
154
|
+
if (pkg.scripts[name] !== command) {
|
|
134
155
|
pkg.scripts[name] = command;
|
|
135
156
|
added++;
|
|
136
157
|
}
|
|
137
158
|
}
|
|
138
159
|
|
|
139
|
-
|
|
160
|
+
// Remove stale namespaced scripts from previous versions
|
|
161
|
+
for (const name of Object.keys(pkg.scripts)) {
|
|
162
|
+
if (name.startsWith(`${NAMESPACE}:`) && !currentScriptNames.has(name)) {
|
|
163
|
+
delete pkg.scripts[name];
|
|
164
|
+
removed++;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (added > 0 || removed > 0) {
|
|
140
169
|
if (isDryRun) {
|
|
141
|
-
console.log(`[dry-run] Would add ${added} script(s)
|
|
170
|
+
if (added > 0) console.log(`[dry-run] Would add/update ${added} script(s) in package.json`);
|
|
171
|
+
if (removed > 0) console.log(`[dry-run] Would remove ${removed} stale script(s) from package.json`);
|
|
142
172
|
} else {
|
|
143
173
|
writeFileSync(pkgPath, JSON.stringify(pkg, null, 4) + "\n", "utf8");
|
|
144
174
|
}
|
|
145
|
-
console.log(`${PKG_NAME}:
|
|
175
|
+
console.log(`${PKG_NAME}: ${added} script(s) added/updated, ${removed} stale removed in package.json`);
|
|
146
176
|
} else {
|
|
147
|
-
console.log(`${PKG_NAME}: All namespaced scripts already
|
|
177
|
+
console.log(`${PKG_NAME}: All namespaced scripts already up to date in package.json`);
|
|
148
178
|
}
|
|
149
179
|
}
|
|
150
180
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bottomlessmargaritas/formatting-configs",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Canonical Prettier and ESLint configs for @
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Canonical Prettier and ESLint configs for @bottomlessmargaritas projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"formatting-configs": "./bin/cli.js"
|
|
@@ -29,10 +29,18 @@
|
|
|
29
29
|
"typescript-eslint": ">=8"
|
|
30
30
|
},
|
|
31
31
|
"peerDependenciesMeta": {
|
|
32
|
-
"@babel/eslint-parser": {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"eslint-plugin-
|
|
32
|
+
"@babel/eslint-parser": {
|
|
33
|
+
"optional": true
|
|
34
|
+
},
|
|
35
|
+
"eslint-plugin-jsx-a11y": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"eslint-plugin-react": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"eslint-plugin-react-hooks": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
36
44
|
},
|
|
37
45
|
"keywords": [
|
|
38
46
|
"prettier",
|
|
@@ -40,7 +48,7 @@
|
|
|
40
48
|
"formatting",
|
|
41
49
|
"config"
|
|
42
50
|
],
|
|
43
|
-
"author": "
|
|
51
|
+
"author": "bottomlessmargaritas",
|
|
44
52
|
"license": "MIT",
|
|
45
53
|
"engines": {
|
|
46
54
|
"node": ">=18"
|