@kitschpatrol/mdat-config 5.0.0 → 5.0.2
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 +59 -16
- package/package.json +3 -2
package/bin/cli.js
CHANGED
|
@@ -627,7 +627,7 @@ var source_default = chalk;
|
|
|
627
627
|
import { cosmiconfig } from "cosmiconfig";
|
|
628
628
|
import { execa } from "execa";
|
|
629
629
|
import fse2 from "fs-extra";
|
|
630
|
-
import
|
|
630
|
+
import fs3 from "node:fs";
|
|
631
631
|
import path3 from "node:path";
|
|
632
632
|
import { PassThrough } from "node:stream";
|
|
633
633
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
@@ -5541,7 +5541,7 @@ var Yargs = YargsFactory(esm_default);
|
|
|
5541
5541
|
var yargs_default = Yargs;
|
|
5542
5542
|
|
|
5543
5543
|
// ../../package.json
|
|
5544
|
-
var version = "5.0.
|
|
5544
|
+
var version = "5.0.2";
|
|
5545
5545
|
|
|
5546
5546
|
// ../../src/execa-utils.ts
|
|
5547
5547
|
function isErrorExecaError(error) {
|
|
@@ -5743,6 +5743,29 @@ function getCwdOverride(option) {
|
|
|
5743
5743
|
return process.cwd();
|
|
5744
5744
|
}
|
|
5745
5745
|
|
|
5746
|
+
// ../../src/prettier-utils.ts
|
|
5747
|
+
import fs2 from "node:fs/promises";
|
|
5748
|
+
async function formatTextAndSaveFile(filePath, content) {
|
|
5749
|
+
try {
|
|
5750
|
+
const { default: prettier } = await import("prettier");
|
|
5751
|
+
const prettierConfig = await prettier.resolveConfig(filePath);
|
|
5752
|
+
const formattedContent = await prettier.format(content, {
|
|
5753
|
+
filepath: filePath,
|
|
5754
|
+
...prettierConfig
|
|
5755
|
+
});
|
|
5756
|
+
await fs2.writeFile(filePath, formattedContent, "utf8");
|
|
5757
|
+
} catch {
|
|
5758
|
+
console.warn(`Skipped formatting ${filePath} since Prettier is not installed.`);
|
|
5759
|
+
}
|
|
5760
|
+
}
|
|
5761
|
+
async function formatFileInPlace(filePath) {
|
|
5762
|
+
try {
|
|
5763
|
+
const content = await fs2.readFile(filePath, "utf8");
|
|
5764
|
+
await formatTextAndSaveFile(filePath, content);
|
|
5765
|
+
} catch {
|
|
5766
|
+
}
|
|
5767
|
+
}
|
|
5768
|
+
|
|
5746
5769
|
// ../../src/stream-utils.ts
|
|
5747
5770
|
import { Transform } from "node:stream";
|
|
5748
5771
|
function createStreamTransform(logPrefix, logColor) {
|
|
@@ -5788,7 +5811,11 @@ async function executeFunctionCommand(logStream, positionalArguments, optionFlag
|
|
|
5788
5811
|
targetStream = subStream;
|
|
5789
5812
|
}
|
|
5790
5813
|
if (verbose) {
|
|
5791
|
-
targetStream.write(
|
|
5814
|
+
targetStream.write(
|
|
5815
|
+
source_default.bold(
|
|
5816
|
+
`Running: "${command2.name}() with Positional arguments: ${String(positionalArguments)} and Option flags: ${String(optionFlags)}"`
|
|
5817
|
+
)
|
|
5818
|
+
);
|
|
5792
5819
|
}
|
|
5793
5820
|
try {
|
|
5794
5821
|
exitCode = await command2.execute(targetStream, positionalArguments, optionFlags);
|
|
@@ -5906,9 +5933,6 @@ async function copyAndMergeInitFiles(logStream, location, configFile, configPack
|
|
|
5906
5933
|
const source = path3.join(path3.dirname(sourcePackage), "init");
|
|
5907
5934
|
const destination = path3.dirname(destinationPackage);
|
|
5908
5935
|
const hasConfigLocationOption = (location === "file" || location === "package") && configFile !== void 0 && configPackageJson !== void 0;
|
|
5909
|
-
logStream.write(`Adding initial configuration files from:
|
|
5910
|
-
"${source}" \u2192 "${destination}"
|
|
5911
|
-
`);
|
|
5912
5936
|
try {
|
|
5913
5937
|
if (hasConfigLocationOption) {
|
|
5914
5938
|
const configKey = Object.keys(configPackageJson)[0];
|
|
@@ -5920,7 +5944,8 @@ Package config key "${configKey}" \u2192 "${destination}" (Because --location is
|
|
|
5920
5944
|
`
|
|
5921
5945
|
);
|
|
5922
5946
|
const mergedPackageJson = merge(destinationPackageJson, configPackageJson);
|
|
5923
|
-
fse2.writeJSONSync(destinationPackage, mergedPackageJson, { spaces:
|
|
5947
|
+
fse2.writeJSONSync(destinationPackage, mergedPackageJson, { spaces: " " });
|
|
5948
|
+
await formatFileInPlace(destinationPackage);
|
|
5924
5949
|
} else {
|
|
5925
5950
|
const destinationPackageJson = fse2.readJsonSync(destinationPackage);
|
|
5926
5951
|
if (Object.keys(destinationPackageJson).includes(configKey)) {
|
|
@@ -5930,14 +5955,28 @@ Package config key "${configKey}" in "${destination}" (Because --location is set
|
|
|
5930
5955
|
`
|
|
5931
5956
|
);
|
|
5932
5957
|
delete destinationPackageJson[configKey];
|
|
5933
|
-
fse2.writeJSONSync(destinationPackage, destinationPackageJson, { spaces:
|
|
5958
|
+
fse2.writeJSONSync(destinationPackage, destinationPackageJson, { spaces: " " });
|
|
5959
|
+
await formatFileInPlace(destinationPackage);
|
|
5934
5960
|
}
|
|
5935
5961
|
}
|
|
5936
5962
|
}
|
|
5963
|
+
const sourceExists = await fse2.pathExists(source);
|
|
5964
|
+
if (!sourceExists) {
|
|
5965
|
+
return 0;
|
|
5966
|
+
}
|
|
5967
|
+
const sourceFiles = await fse2.readdir(source);
|
|
5968
|
+
if (sourceFiles.length === 0) {
|
|
5969
|
+
logStream.write(`Source directory "${source}" is empty.
|
|
5970
|
+
`);
|
|
5971
|
+
return 0;
|
|
5972
|
+
}
|
|
5973
|
+
logStream.write(`Adding initial configuration files from:
|
|
5974
|
+
"${source}" \u2192 "${destination}"
|
|
5975
|
+
`);
|
|
5937
5976
|
await fse2.copy(source, destination, {
|
|
5938
|
-
filter(source2, destination2) {
|
|
5939
|
-
const isFile =
|
|
5940
|
-
const destinationExists =
|
|
5977
|
+
async filter(source2, destination2) {
|
|
5978
|
+
const isFile = fs3.statSync(source2).isFile();
|
|
5979
|
+
const destinationExists = fs3.existsSync(destination2);
|
|
5941
5980
|
if (isFile) {
|
|
5942
5981
|
if (hasConfigLocationOption && location === "package" && source2.includes(configFile)) {
|
|
5943
5982
|
if (destinationExists) {
|
|
@@ -5956,25 +5995,28 @@ Package config key "${configKey}" in "${destination}" (Because --location is set
|
|
|
5956
5995
|
}
|
|
5957
5996
|
return false;
|
|
5958
5997
|
}
|
|
5959
|
-
if (destinationExists && destination2.includes(".vscode/") && path3.extname(destination2) === ".json") {
|
|
5998
|
+
if (destinationExists && (destination2.includes(".vscode/") || destination2.includes("package.json")) && path3.extname(destination2) === ".json") {
|
|
5960
5999
|
logStream.write(`Merging:
|
|
5961
6000
|
"${source2}" \u2192 "${destination2}"
|
|
5962
6001
|
`);
|
|
5963
6002
|
const sourceJson = fse2.readJSONSync(source2);
|
|
5964
6003
|
const destinationJson = fse2.readJSONSync(destination2);
|
|
5965
6004
|
const mergedJson = merge(destinationJson, sourceJson);
|
|
5966
|
-
fse2.writeJSONSync(destination2, mergedJson, { spaces:
|
|
6005
|
+
fse2.writeJSONSync(destination2, mergedJson, { spaces: " " });
|
|
6006
|
+
await formatFileInPlace(destination2);
|
|
5967
6007
|
return false;
|
|
5968
6008
|
}
|
|
5969
6009
|
if (destinationExists) {
|
|
5970
6010
|
logStream.write(`Overwriting:
|
|
5971
6011
|
"${source2}" \u2192 "${destination2}"
|
|
5972
6012
|
`);
|
|
6013
|
+
await formatFileInPlace(destination2);
|
|
5973
6014
|
return true;
|
|
5974
6015
|
}
|
|
5975
6016
|
logStream.write(`Copying:
|
|
5976
6017
|
"${source2}" \u2192 "${destination2}"
|
|
5977
6018
|
`);
|
|
6019
|
+
await formatFileInPlace(destination2);
|
|
5978
6020
|
return true;
|
|
5979
6021
|
}
|
|
5980
6022
|
return true;
|
|
@@ -6014,11 +6056,12 @@ async function buildCommands(commandDefinition2) {
|
|
|
6014
6056
|
// Command: init.locationOptionFlag ? 'init [--location]' : 'init',
|
|
6015
6057
|
describe: init.description ?? `Initialize by copying starter config files to your project root${init.locationOptionFlag ? " or to your package.json file." : "."}`,
|
|
6016
6058
|
async handler(argv) {
|
|
6059
|
+
const location = init.locationOptionFlag ? argv.location : void 0;
|
|
6017
6060
|
const copyAndMergeInitFilesCommand = {
|
|
6018
|
-
async execute(logStream2) {
|
|
6061
|
+
async execute(logStream2, _, optionFlags) {
|
|
6019
6062
|
return copyAndMergeInitFiles(
|
|
6020
6063
|
logStream2,
|
|
6021
|
-
|
|
6064
|
+
optionFlags.at(1),
|
|
6022
6065
|
init.configFile,
|
|
6023
6066
|
init.configPackageJson
|
|
6024
6067
|
);
|
|
@@ -6028,7 +6071,7 @@ async function buildCommands(commandDefinition2) {
|
|
|
6028
6071
|
const exitCode = await executeCommands(
|
|
6029
6072
|
logStream,
|
|
6030
6073
|
[],
|
|
6031
|
-
[],
|
|
6074
|
+
location === void 0 ? [] : ["--location", location],
|
|
6032
6075
|
[copyAndMergeInitFilesCommand, ...init.commands ?? []]
|
|
6033
6076
|
);
|
|
6034
6077
|
process.exit(exitCode);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/mdat-config",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "MDAT configuration for @kitschpatrol/shared-config.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shared-config",
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"execa": "^9.5.2",
|
|
48
48
|
"find-workspaces": "^0.3.1",
|
|
49
49
|
"fs-extra": "^11.3.0",
|
|
50
|
-
"mdat": "^0.10.0"
|
|
50
|
+
"mdat": "^0.10.0",
|
|
51
|
+
"prettier": "^3.4.2"
|
|
51
52
|
},
|
|
52
53
|
"engines": {
|
|
53
54
|
"node": ">=22.0.0",
|