@meistrari/mise-en-place 2.8.0 → 2.9.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/dist/cli/cli.mjs +30 -10
- package/package.json +1 -1
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
|
|