@meistrari/mise-en-place 2.7.0 → 2.8.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 CHANGED
@@ -3,10 +3,7 @@ default: help
3
3
 
4
4
  _MISE_EN_PLACE_PACKAGE_NAME = @meistrari/mise-en-place
5
5
 
6
- ## Public commands
7
-
8
- .editorconfig: ./node_modules/$(_MISE_EN_PLACE_PACKAGE_NAME)/.editorconfig ## Copy/update .editorconfig file from @meistrari/mise-en-place package
9
- @cp ./node_modules/$(_MISE_EN_PLACE_PACKAGE_NAME)/.editorconfig .editorconfig
6
+ # region Public commands
10
7
 
11
8
  .PHONY: update-meistrari-libs
12
9
  update-meistrari-libs: ## Update @meistrari/* packages recursively in the workspace
@@ -14,13 +11,17 @@ update-meistrari-libs: ## Update @meistrari/* packages recursively in the worksp
14
11
 
15
12
  .PHONY: mise-en-place
16
13
  mise-en-place: .editorconfig ## Setup the mise en place to start cooking
17
- @echo "export { default } from '$(_MISE_EN_PLACE_PACKAGE_NAME)/eslint'" > eslint.config.mjs
14
+ @npx mise-en-place postinstall
18
15
  @echo "Mise en place is ready! 🍳"
19
16
 
20
- ## Hidden commands
17
+ # endregion
18
+
19
+ # region Hidden
21
20
 
22
21
  .PHONY: help
23
22
  help:
24
23
  @echo "Make tasks:"
25
24
  @grep -hE '^[%a-zA-Z_-]+:.*?## .*$$' Makefile ./node_modules/$(_MISE_EN_PLACE_PACKAGE_NAME)/Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-17s\033[0m %s\n", $$1, $$2}'
26
25
  @echo ""
26
+
27
+ # endregion
package/README.md CHANGED
@@ -9,9 +9,9 @@ Add `mise-en-place postinstall` to your project's `package.json` `postinstall` s
9
9
 
10
10
  ```json
11
11
  {
12
- "scripts": {
13
- "postinstall": "mise-en-place postinstall"
14
- }
12
+ "scripts": {
13
+ "postinstall": "mise-en-place postinstall"
14
+ }
15
15
  }
16
16
  ```
17
17
 
@@ -53,6 +53,6 @@ Add the following code in your `tsconfig.json` to include this project's TypeScr
53
53
 
54
54
  ```json
55
55
  {
56
- "extends": "./node_modules/@meistrari/mise-en-place/tsconfig.base.json"
56
+ "extends": "./node_modules/@meistrari/mise-en-place/tsconfig.base.json"
57
57
  }
58
58
  ```
package/dist/cli/cli.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { argv } from 'node:process';
3
3
  import { existsSync, readFileSync, writeFileSync } from 'node:fs';
4
- import { execSync } from 'node:child_process';
5
4
  import { globSync } from 'glob';
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';
8
9
 
9
10
  function readPackageJson(path) {
10
11
  return JSON.parse(readFileSync(path, "utf-8"));
@@ -209,17 +210,95 @@ function updateMeistrariLibraries(args) {
209
210
  }
210
211
  }
211
212
 
213
+ const name = "@meistrari/mise-en-place";
214
+ const packageJson = {
215
+ name: name};
216
+
217
+ const {
218
+ name: packageName
219
+ } = packageJson;
220
+ const oldMakefileIncludeLine = "include ./node_modules/@meistrari/mise-en-place/Makefile";
221
+ const makeFileIncludeLine = "-include ./node_modules/@meistrari/mise-en-place/Makefile";
212
222
  function handleMakefileInitialSetup() {
213
- if (existsSync("Makefile")) {
214
- console.log("Makefile already exists. Skipping initial setup");
223
+ if (!existsSync("Makefile")) {
224
+ console.log("No Makefile found. Generating one that includes mise-en-place Makefile.");
225
+ writeFileSync("Makefile", `${makeFileIncludeLine}
226
+ `);
215
227
  return;
216
228
  }
217
- console.log("No Makefile found. Generating one that includes mise-en-place Makefile.");
218
- writeFileSync("Makefile", "-include ./node_modules/@meistrari/mise-en-place/Makefile\n");
219
- execSync("make mise-en-place", { stdio: "inherit" });
229
+ const makefileContent = readFileSync("Makefile", "utf-8");
230
+ if (makefileContent.includes(makeFileIncludeLine.trim())) {
231
+ return;
232
+ }
233
+ if (makefileContent.includes(oldMakefileIncludeLine)) {
234
+ console.log();
235
+ writeFileSync("Makefile", makefileContent.replace(oldMakefileIncludeLine, makeFileIncludeLine));
236
+ return;
237
+ }
238
+ console.log("Adding mise-en-place Makefile include to existing Makefile.");
239
+ const newContent = `${makeFileIncludeLine}
240
+
241
+ ${makefileContent}`;
242
+ writeFileSync("Makefile", newContent);
243
+ }
244
+ const miseEnPlaceExtends = "./node_modules/@meistrari/mise-en-place/tsconfig.base.json";
245
+ function handleTsConfig() {
246
+ if (!existsSync("tsconfig.json")) {
247
+ console.log("No tsconfig.json found. Generating one that extends mise-en-place tsconfig.json.");
248
+ writeFileSync(
249
+ "tsconfig.json",
250
+ dedent`{
251
+ "extends": "${miseEnPlaceExtends}"
252
+ }`
253
+ );
254
+ return;
255
+ }
256
+ const tsconfigRaw = readFileSync("tsconfig.json", "utf-8");
257
+ const tsconfigContent = JSON.parse(tsconfigRaw);
258
+ if (!tsconfigContent.extends) {
259
+ console.log("tsconfig.json has no extends field. Adding mise-en-place tsconfig as extends.");
260
+ tsconfigContent.extends = miseEnPlaceExtends;
261
+ writeFileSync("tsconfig.json", `${JSON.stringify(tsconfigContent, null, 4)}
262
+ `);
263
+ return;
264
+ }
265
+ if (typeof tsconfigContent.extends === "string") {
266
+ if (tsconfigContent.extends === miseEnPlaceExtends) {
267
+ return;
268
+ }
269
+ console.log("tsconfig.json extends is a string. Converting to array and adding mise-en-place tsconfig.");
270
+ tsconfigContent.extends = [tsconfigContent.extends, miseEnPlaceExtends];
271
+ writeFileSync("tsconfig.json", `${JSON.stringify(tsconfigContent, null, 4)}
272
+ `);
273
+ return;
274
+ }
275
+ if (Array.isArray(tsconfigContent.extends)) {
276
+ if (tsconfigContent.extends.includes(miseEnPlaceExtends)) {
277
+ return;
278
+ }
279
+ console.log("tsconfig.json extends is an array. Adding mise-en-place tsconfig to the extends array.");
280
+ tsconfigContent.extends.push(miseEnPlaceExtends);
281
+ writeFileSync("tsconfig.json", `${JSON.stringify(tsconfigContent, null, 4)}
282
+ `);
283
+ return;
284
+ }
285
+ console.error(tsconfigContent.extends);
286
+ throw new Error("Unhandled tsconfig.json extends field type");
287
+ }
288
+ function handleEslintConfigFile() {
289
+ const eslintContent = `export { default } from '${packageName}/eslint'
290
+ `;
291
+ writeFileSync("eslint.config.mjs", eslintContent);
292
+ }
293
+ function handleEditorconfigFile() {
294
+ const editorconfigContent = readFileSync(`./node_modules/${packageName}/.editorconfig`, "utf-8");
295
+ writeFileSync(".editorconfig", editorconfigContent);
220
296
  }
221
297
  function postinstall(args) {
222
298
  handleMakefileInitialSetup();
299
+ handleTsConfig();
300
+ handleEslintConfigFile();
301
+ handleEditorconfigFile();
223
302
  updateMeistrariLibraries(args);
224
303
  }
225
304
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/mise-en-place",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,6 +35,7 @@
35
35
  "homepage": "https://github.com/meistrari/mise-en-place#readme",
36
36
  "dependencies": {
37
37
  "@antfu/eslint-config": "6.2.0",
38
+ "dedent": "1.7.1",
38
39
  "eslint": "9.39.1",
39
40
  "eslint-plugin-diff": "2.0.3",
40
41
  "eslint-plugin-drizzle": "0.2.3",