@meistrari/mise-en-place 2.8.0 → 2.10.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/Makefile +2 -1
- package/README.md +31 -11
- package/dist/cli/cli.mjs +30 -10
- package/package.json +1 -1
package/Makefile
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
default: help
|
|
3
3
|
|
|
4
4
|
_MISE_EN_PLACE_PACKAGE_NAME = @meistrari/mise-en-place
|
|
5
|
+
MISE_EN_PLACE_INSTALL_DIR ?= .
|
|
5
6
|
|
|
6
7
|
# region Public commands
|
|
7
8
|
|
|
@@ -21,7 +22,7 @@ mise-en-place: .editorconfig ## Setup the mise en place to start cooking
|
|
|
21
22
|
.PHONY: help
|
|
22
23
|
help:
|
|
23
24
|
@echo "Make tasks:"
|
|
24
|
-
@grep -hE '^[%a-zA-Z_-]+:.*?## .*$$' Makefile
|
|
25
|
+
@grep -hE '^[%a-zA-Z_-]+:.*?## .*$$' Makefile $(MISE_EN_PLACE_INSTALL_DIR)/node_modules/$(_MISE_EN_PLACE_PACKAGE_NAME)/Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-17s\033[0m %s\n", $$1, $$2}'
|
|
25
26
|
@echo ""
|
|
26
27
|
|
|
27
28
|
# endregion
|
package/README.md
CHANGED
|
@@ -15,30 +15,33 @@ Add `mise-en-place postinstall` to your project's `package.json` `postinstall` s
|
|
|
15
15
|
}
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Then install the package as a development dependency:
|
|
18
|
+
Then install the package as a development dependency and run the postinstall script:
|
|
19
19
|
```sh
|
|
20
|
-
|
|
20
|
+
bun i -D @meistrari/mise-en-place
|
|
21
|
+
bunx mise-en-place postinstall
|
|
21
22
|
```
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
It will also setup the initial _mise-en-place_ in your project.
|
|
24
|
+
It will also setup the initial _mise-en-place_ in your project. Which includes:
|
|
25
|
+
- Adding a `Makefile` with useful commands.
|
|
26
|
+
- Adding an `.editorconfig` file.
|
|
27
|
+
- Adding ESLint configuration.
|
|
28
|
+
- Adding TypeScript configuration.
|
|
29
|
+
- Setting up `postinstall` script to keep all `@meistrari/*` packages up to date.
|
|
30
30
|
|
|
31
31
|
# Features
|
|
32
32
|
|
|
33
33
|
## Keep all @meistrari/* packages up to date
|
|
34
|
-
By adding the `postinstall` script
|
|
34
|
+
By adding the `postinstall` script to run `mise-en-place postinstall`, every time you run install your dependencies, it will check for the latest versions of all `@meistrari/*` packages in your project and update them if necessary.
|
|
35
|
+
|
|
36
|
+
This process will add a leading caret (`^`) to the version range if it is not already present. Which means that it will update to the latest minor and patch versions automatically but never the major version.
|
|
35
37
|
|
|
36
38
|
## Makefile
|
|
37
39
|
Commands with `##` after the target are 'public' commands and are intended to be used by developers and will show up in the help message.
|
|
40
|
+
|
|
38
41
|
The other commands are 'hidden' and are intended to be used by automations or by other 'public' commands.
|
|
39
42
|
|
|
40
43
|
## EditorConfig
|
|
41
|
-
|
|
44
|
+
Since the editorconfig file [don't support extending from other files](https://github.com/editorconfig/editorconfig/issues/236), the postinstall script will always copy the `.editorconfig` file from this project to your project root.
|
|
42
45
|
|
|
43
46
|
## Eslint Config
|
|
44
47
|
Add the following code in your `eslint.config.mjs` to include this project's ESLint configuration:
|
|
@@ -47,6 +50,23 @@ Add the following code in your `eslint.config.mjs` to include this project's ESL
|
|
|
47
50
|
export { default } from '@meistrari/mise-en-place/eslint'
|
|
48
51
|
```
|
|
49
52
|
|
|
53
|
+
> If some rules needs to be updated, you can update the rules in this project (preferrable) or customize them in your own configuration (not preferrable).
|
|
54
|
+
> You probably don't need to customize the configuration, since it is already designed to be a good starting point for most projects.
|
|
55
|
+
> Remember that customizing too much can make your project diverge from the standard and make it harder to maintain.
|
|
56
|
+
|
|
57
|
+
If you understand the risk and NEED to customize the configuration, you can import the default configuration and extend it:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import miseEnPlaceEslintConfig from '@meistrari/mise-en-place/eslint'
|
|
61
|
+
|
|
62
|
+
export default miseEnPlaceEslintConfig
|
|
63
|
+
.append({
|
|
64
|
+
rules: {
|
|
65
|
+
// your custom rules here
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
50
70
|
## TSConfig
|
|
51
71
|
|
|
52
72
|
Add the following code in your `tsconfig.json` to include this project's TypeScript configuration:
|
package/dist/cli/cli.mjs
CHANGED
|
@@ -5,7 +5,6 @@ import { globSync } from 'glob';
|
|
|
5
5
|
import { execSync } from 'node:child_process';
|
|
6
6
|
import { dirname } from 'node:path';
|
|
7
7
|
import { parse } from 'yaml';
|
|
8
|
-
import dedent from 'dedent';
|
|
9
8
|
|
|
10
9
|
function readPackageJson(path) {
|
|
11
10
|
return JSON.parse(readFileSync(path, "utf-8"));
|
|
@@ -241,15 +240,14 @@ function handleMakefileInitialSetup() {
|
|
|
241
240
|
${makefileContent}`;
|
|
242
241
|
writeFileSync("Makefile", newContent);
|
|
243
242
|
}
|
|
244
|
-
const
|
|
243
|
+
const miseEnPlaceTsConfigExtends = "./node_modules/@meistrari/mise-en-place/tsconfig.base.json";
|
|
245
244
|
function handleTsConfig() {
|
|
246
245
|
if (!existsSync("tsconfig.json")) {
|
|
247
246
|
console.log("No tsconfig.json found. Generating one that extends mise-en-place tsconfig.json.");
|
|
248
247
|
writeFileSync(
|
|
249
248
|
"tsconfig.json",
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}`
|
|
249
|
+
`{ "extends": "${miseEnPlaceTsConfigExtends}" }
|
|
250
|
+
`
|
|
253
251
|
);
|
|
254
252
|
return;
|
|
255
253
|
}
|
|
@@ -257,27 +255,27 @@ function handleTsConfig() {
|
|
|
257
255
|
const tsconfigContent = JSON.parse(tsconfigRaw);
|
|
258
256
|
if (!tsconfigContent.extends) {
|
|
259
257
|
console.log("tsconfig.json has no extends field. Adding mise-en-place tsconfig as extends.");
|
|
260
|
-
tsconfigContent.extends =
|
|
258
|
+
tsconfigContent.extends = miseEnPlaceTsConfigExtends;
|
|
261
259
|
writeFileSync("tsconfig.json", `${JSON.stringify(tsconfigContent, null, 4)}
|
|
262
260
|
`);
|
|
263
261
|
return;
|
|
264
262
|
}
|
|
265
263
|
if (typeof tsconfigContent.extends === "string") {
|
|
266
|
-
if (tsconfigContent.extends ===
|
|
264
|
+
if (tsconfigContent.extends === miseEnPlaceTsConfigExtends) {
|
|
267
265
|
return;
|
|
268
266
|
}
|
|
269
267
|
console.log("tsconfig.json extends is a string. Converting to array and adding mise-en-place tsconfig.");
|
|
270
|
-
tsconfigContent.extends = [tsconfigContent.extends,
|
|
268
|
+
tsconfigContent.extends = [tsconfigContent.extends, miseEnPlaceTsConfigExtends];
|
|
271
269
|
writeFileSync("tsconfig.json", `${JSON.stringify(tsconfigContent, null, 4)}
|
|
272
270
|
`);
|
|
273
271
|
return;
|
|
274
272
|
}
|
|
275
273
|
if (Array.isArray(tsconfigContent.extends)) {
|
|
276
|
-
if (tsconfigContent.extends.includes(
|
|
274
|
+
if (tsconfigContent.extends.includes(miseEnPlaceTsConfigExtends)) {
|
|
277
275
|
return;
|
|
278
276
|
}
|
|
279
277
|
console.log("tsconfig.json extends is an array. Adding mise-en-place tsconfig to the extends array.");
|
|
280
|
-
tsconfigContent.extends.push(
|
|
278
|
+
tsconfigContent.extends.push(miseEnPlaceTsConfigExtends);
|
|
281
279
|
writeFileSync("tsconfig.json", `${JSON.stringify(tsconfigContent, null, 4)}
|
|
282
280
|
`);
|
|
283
281
|
return;
|
|
@@ -294,11 +292,33 @@ function handleEditorconfigFile() {
|
|
|
294
292
|
const editorconfigContent = readFileSync(`./node_modules/${packageName}/.editorconfig`, "utf-8");
|
|
295
293
|
writeFileSync(".editorconfig", editorconfigContent);
|
|
296
294
|
}
|
|
295
|
+
function handlePackageJsonScripts() {
|
|
296
|
+
if (!existsSync("package.json")) {
|
|
297
|
+
throw new Error("No package.json found. Skipping package.json scripts setup.");
|
|
298
|
+
}
|
|
299
|
+
const packageJsonRaw = readFileSync("package.json", "utf-8");
|
|
300
|
+
const packageJsonContent = JSON.parse(packageJsonRaw);
|
|
301
|
+
if (!packageJsonContent.scripts) {
|
|
302
|
+
packageJsonContent.scripts = {};
|
|
303
|
+
}
|
|
304
|
+
const {
|
|
305
|
+
postinstall: currentPostinstallScript
|
|
306
|
+
} = packageJsonContent.scripts;
|
|
307
|
+
const miseEnPlacePostinstallScript = "mise-en-place postinstall";
|
|
308
|
+
if (currentPostinstallScript?.includes(miseEnPlacePostinstallScript)) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const newPostinstallScript = currentPostinstallScript ? `${miseEnPlacePostinstallScript} && ${currentPostinstallScript}` : miseEnPlacePostinstallScript;
|
|
312
|
+
packageJsonContent.scripts.postinstall = newPostinstallScript;
|
|
313
|
+
writeFileSync("package.json", `${JSON.stringify(packageJsonContent, null, 4)}
|
|
314
|
+
`);
|
|
315
|
+
}
|
|
297
316
|
function postinstall(args) {
|
|
298
317
|
handleMakefileInitialSetup();
|
|
299
318
|
handleTsConfig();
|
|
300
319
|
handleEslintConfigFile();
|
|
301
320
|
handleEditorconfigFile();
|
|
321
|
+
handlePackageJsonScripts();
|
|
302
322
|
updateMeistrariLibraries(args);
|
|
303
323
|
}
|
|
304
324
|
|