permachine 0.5.1 → 0.6.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.js +173 -108
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -5800,7 +5800,7 @@ var glob = Object.assign(glob_, {
|
|
|
5800
5800
|
glob.glob = glob;
|
|
5801
5801
|
|
|
5802
5802
|
// src/core/file-scanner.ts
|
|
5803
|
-
import
|
|
5803
|
+
import path3 from "node:path";
|
|
5804
5804
|
|
|
5805
5805
|
// src/core/file-filters.ts
|
|
5806
5806
|
import os2 from "node:os";
|
|
@@ -5934,117 +5934,18 @@ function matchFilters(filename, context) {
|
|
|
5934
5934
|
function getBaseFilename(filename) {
|
|
5935
5935
|
return parseFilters(filename).baseFilename;
|
|
5936
5936
|
}
|
|
5937
|
+
function isBaseFile(filename) {
|
|
5938
|
+
const basename = filename.includes("/") || filename.includes("\\") ? filename.split(/[/\\]/).pop() || filename : filename;
|
|
5939
|
+
return basename.includes(".base.") || basename.endsWith(".base");
|
|
5940
|
+
}
|
|
5937
5941
|
function isLegacyFilename(filename, machineName) {
|
|
5938
5942
|
const middlePattern = new RegExp(`\\.${machineName}\\.`, "i");
|
|
5939
5943
|
const endPattern = new RegExp(`\\.${machineName}$`, "i");
|
|
5940
5944
|
return (middlePattern.test(filename) || endPattern.test(filename)) && !hasFilters(filename);
|
|
5941
5945
|
}
|
|
5942
5946
|
|
|
5943
|
-
// src/core/file-scanner.ts
|
|
5944
|
-
async function scanForMergeOperations(machineName, cwd = process.cwd()) {
|
|
5945
|
-
const operations = [];
|
|
5946
|
-
const patterns = [
|
|
5947
|
-
"**/*{*}*",
|
|
5948
|
-
`**/*.${machineName}.*`,
|
|
5949
|
-
`**/.*.${machineName}`,
|
|
5950
|
-
`**/.*.${machineName}.*`
|
|
5951
|
-
];
|
|
5952
|
-
const foundFiles = [];
|
|
5953
|
-
for (const pattern of patterns) {
|
|
5954
|
-
try {
|
|
5955
|
-
const files = await glob(pattern, {
|
|
5956
|
-
cwd,
|
|
5957
|
-
ignore: ["node_modules/**", ".git/**", "dist/**", "**/*.base.*", "**/.*base*"],
|
|
5958
|
-
dot: true,
|
|
5959
|
-
nodir: true
|
|
5960
|
-
});
|
|
5961
|
-
foundFiles.push(...files);
|
|
5962
|
-
} catch (error) {}
|
|
5963
|
-
}
|
|
5964
|
-
const uniqueFiles = [...new Set(foundFiles)];
|
|
5965
|
-
const context = createCustomContext({ machine: machineName });
|
|
5966
|
-
for (const file of uniqueFiles) {
|
|
5967
|
-
const basename = path2.basename(file);
|
|
5968
|
-
if (basename.includes(".base.") || basename.includes(".base")) {
|
|
5969
|
-
continue;
|
|
5970
|
-
}
|
|
5971
|
-
let shouldProcess = false;
|
|
5972
|
-
if (hasFilters(basename)) {
|
|
5973
|
-
const result = matchFilters(basename, context);
|
|
5974
|
-
shouldProcess = result.matches;
|
|
5975
|
-
} else if (isLegacyFilename(basename, machineName)) {
|
|
5976
|
-
shouldProcess = true;
|
|
5977
|
-
}
|
|
5978
|
-
if (shouldProcess) {
|
|
5979
|
-
const operation = createMergeOperation(file, machineName, cwd);
|
|
5980
|
-
if (operation) {
|
|
5981
|
-
operations.push(operation);
|
|
5982
|
-
}
|
|
5983
|
-
}
|
|
5984
|
-
}
|
|
5985
|
-
return operations;
|
|
5986
|
-
}
|
|
5987
|
-
function createMergeOperation(machineFile, machineName, cwd) {
|
|
5988
|
-
const dir = path2.dirname(machineFile);
|
|
5989
|
-
const fullBasename = path2.basename(machineFile);
|
|
5990
|
-
let type;
|
|
5991
|
-
let ext2;
|
|
5992
|
-
if (fullBasename.endsWith(".json")) {
|
|
5993
|
-
type = "json";
|
|
5994
|
-
ext2 = ".json";
|
|
5995
|
-
} else if (fullBasename.startsWith(".env")) {
|
|
5996
|
-
type = "env";
|
|
5997
|
-
ext2 = "";
|
|
5998
|
-
} else {
|
|
5999
|
-
type = "unknown";
|
|
6000
|
-
ext2 = path2.extname(machineFile);
|
|
6001
|
-
}
|
|
6002
|
-
if (type === "unknown") {
|
|
6003
|
-
return null;
|
|
6004
|
-
}
|
|
6005
|
-
let baseName;
|
|
6006
|
-
let outputName;
|
|
6007
|
-
if (hasFilters(fullBasename)) {
|
|
6008
|
-
outputName = getBaseFilename(fullBasename);
|
|
6009
|
-
if (type === "env") {
|
|
6010
|
-
const nameWithoutExt = outputName;
|
|
6011
|
-
baseName = nameWithoutExt + ".base";
|
|
6012
|
-
} else {
|
|
6013
|
-
const nameWithoutExt = outputName.replace(ext2, "");
|
|
6014
|
-
baseName = nameWithoutExt + ".base" + ext2;
|
|
6015
|
-
}
|
|
6016
|
-
} else {
|
|
6017
|
-
const basename = type === "env" ? fullBasename : path2.basename(machineFile, ext2);
|
|
6018
|
-
const machinePattern = `.${machineName}`;
|
|
6019
|
-
if (basename.endsWith(machinePattern)) {
|
|
6020
|
-
const withoutMachine = basename.substring(0, basename.length - machinePattern.length);
|
|
6021
|
-
baseName = withoutMachine + ".base";
|
|
6022
|
-
outputName = withoutMachine;
|
|
6023
|
-
if (type !== "env") {
|
|
6024
|
-
baseName = baseName + ext2;
|
|
6025
|
-
outputName = outputName + ext2;
|
|
6026
|
-
}
|
|
6027
|
-
} else {
|
|
6028
|
-
return null;
|
|
6029
|
-
}
|
|
6030
|
-
}
|
|
6031
|
-
const basePath = path2.join(cwd, dir, baseName);
|
|
6032
|
-
const machinePath = path2.join(cwd, machineFile);
|
|
6033
|
-
const outputPath = path2.join(cwd, dir, outputName);
|
|
6034
|
-
return {
|
|
6035
|
-
basePath,
|
|
6036
|
-
machinePath,
|
|
6037
|
-
outputPath,
|
|
6038
|
-
type
|
|
6039
|
-
};
|
|
6040
|
-
}
|
|
6041
|
-
|
|
6042
|
-
// src/core/merger.ts
|
|
6043
|
-
import fs from "node:fs/promises";
|
|
6044
|
-
import path4 from "node:path";
|
|
6045
|
-
|
|
6046
5947
|
// src/adapters/adapter-factory.ts
|
|
6047
|
-
import
|
|
5948
|
+
import path2 from "node:path";
|
|
6048
5949
|
|
|
6049
5950
|
// node_modules/strip-json-comments/index.js
|
|
6050
5951
|
var singleComment = Symbol("singleComment");
|
|
@@ -6141,7 +6042,7 @@ function stripJsonComments(jsonString, { whitespace = true, trailingCommas = fal
|
|
|
6141
6042
|
// src/adapters/json-adapter.ts
|
|
6142
6043
|
class JsonAdapter {
|
|
6143
6044
|
canHandle(extension) {
|
|
6144
|
-
return extension === ".json";
|
|
6045
|
+
return extension === ".json" || extension === ".jsonc";
|
|
6145
6046
|
}
|
|
6146
6047
|
parse(content) {
|
|
6147
6048
|
try {
|
|
@@ -6233,11 +6134,11 @@ var adapters = [
|
|
|
6233
6134
|
new EnvAdapter
|
|
6234
6135
|
];
|
|
6235
6136
|
function getAdapter(filePath) {
|
|
6236
|
-
const basename =
|
|
6137
|
+
const basename = path2.basename(filePath);
|
|
6237
6138
|
if (basename.startsWith(".env")) {
|
|
6238
6139
|
return new EnvAdapter;
|
|
6239
6140
|
}
|
|
6240
|
-
const ext2 =
|
|
6141
|
+
const ext2 = path2.extname(filePath);
|
|
6241
6142
|
for (const adapter of adapters) {
|
|
6242
6143
|
if (adapter.canHandle(ext2)) {
|
|
6243
6144
|
return adapter;
|
|
@@ -6245,6 +6146,170 @@ function getAdapter(filePath) {
|
|
|
6245
6146
|
}
|
|
6246
6147
|
return null;
|
|
6247
6148
|
}
|
|
6149
|
+
function getFileType(filename) {
|
|
6150
|
+
const basename = path2.basename(filename);
|
|
6151
|
+
if (basename.startsWith(".env")) {
|
|
6152
|
+
return "env";
|
|
6153
|
+
}
|
|
6154
|
+
const ext2 = path2.extname(filename);
|
|
6155
|
+
if (ext2 === ".json" || ext2 === ".jsonc") {
|
|
6156
|
+
return "json";
|
|
6157
|
+
}
|
|
6158
|
+
return "unknown";
|
|
6159
|
+
}
|
|
6160
|
+
|
|
6161
|
+
// src/core/file-scanner.ts
|
|
6162
|
+
async function scanForMergeOperations(machineName, cwd = process.cwd()) {
|
|
6163
|
+
const operations = [];
|
|
6164
|
+
const processedOutputs = new Set;
|
|
6165
|
+
const baseFilesWithMachineFiles = new Set;
|
|
6166
|
+
const patterns = [
|
|
6167
|
+
"**/*{*}*",
|
|
6168
|
+
`**/*.${machineName}.*`,
|
|
6169
|
+
`**/.*.${machineName}`,
|
|
6170
|
+
`**/.*.${machineName}.*`
|
|
6171
|
+
];
|
|
6172
|
+
const foundFiles = [];
|
|
6173
|
+
for (const pattern of patterns) {
|
|
6174
|
+
try {
|
|
6175
|
+
const files = await glob(pattern, {
|
|
6176
|
+
cwd,
|
|
6177
|
+
ignore: ["node_modules/**", ".git/**", "dist/**", "**/*.base.*", "**/.*base*"],
|
|
6178
|
+
dot: true,
|
|
6179
|
+
nodir: true
|
|
6180
|
+
});
|
|
6181
|
+
foundFiles.push(...files);
|
|
6182
|
+
} catch (error) {}
|
|
6183
|
+
}
|
|
6184
|
+
const uniqueFiles = [...new Set(foundFiles)];
|
|
6185
|
+
const context = createCustomContext({ machine: machineName });
|
|
6186
|
+
for (const file of uniqueFiles) {
|
|
6187
|
+
const basename = path3.basename(file);
|
|
6188
|
+
if (isBaseFile(basename)) {
|
|
6189
|
+
continue;
|
|
6190
|
+
}
|
|
6191
|
+
let shouldProcess = false;
|
|
6192
|
+
if (hasFilters(basename)) {
|
|
6193
|
+
const result = matchFilters(basename, context);
|
|
6194
|
+
shouldProcess = result.matches;
|
|
6195
|
+
const operation = createMergeOperation(file, machineName, cwd);
|
|
6196
|
+
if (operation && operation.basePath) {
|
|
6197
|
+
baseFilesWithMachineFiles.add(operation.basePath);
|
|
6198
|
+
}
|
|
6199
|
+
} else if (isLegacyFilename(basename, machineName)) {
|
|
6200
|
+
shouldProcess = true;
|
|
6201
|
+
const operation = createMergeOperation(file, machineName, cwd);
|
|
6202
|
+
if (operation && operation.basePath) {
|
|
6203
|
+
baseFilesWithMachineFiles.add(operation.basePath);
|
|
6204
|
+
}
|
|
6205
|
+
}
|
|
6206
|
+
if (shouldProcess) {
|
|
6207
|
+
const operation = createMergeOperation(file, machineName, cwd);
|
|
6208
|
+
if (operation) {
|
|
6209
|
+
operations.push(operation);
|
|
6210
|
+
processedOutputs.add(operation.outputPath);
|
|
6211
|
+
}
|
|
6212
|
+
}
|
|
6213
|
+
}
|
|
6214
|
+
const basePatterns = [
|
|
6215
|
+
"**/*.base.json",
|
|
6216
|
+
"**/*.base.jsonc",
|
|
6217
|
+
"**/.*.base",
|
|
6218
|
+
"**/.*.base.*"
|
|
6219
|
+
];
|
|
6220
|
+
for (const pattern of basePatterns) {
|
|
6221
|
+
try {
|
|
6222
|
+
const baseFiles = await glob(pattern, {
|
|
6223
|
+
cwd,
|
|
6224
|
+
ignore: ["node_modules/**", ".git/**", "dist/**"],
|
|
6225
|
+
dot: true,
|
|
6226
|
+
nodir: true
|
|
6227
|
+
});
|
|
6228
|
+
for (const baseFile of baseFiles) {
|
|
6229
|
+
const fullPath = path3.join(cwd, baseFile);
|
|
6230
|
+
if (baseFilesWithMachineFiles.has(fullPath)) {
|
|
6231
|
+
continue;
|
|
6232
|
+
}
|
|
6233
|
+
const operation = createBaseOnlyMergeOperation(baseFile, cwd);
|
|
6234
|
+
if (operation && !processedOutputs.has(operation.outputPath)) {
|
|
6235
|
+
operations.push(operation);
|
|
6236
|
+
processedOutputs.add(operation.outputPath);
|
|
6237
|
+
}
|
|
6238
|
+
}
|
|
6239
|
+
} catch (error) {}
|
|
6240
|
+
}
|
|
6241
|
+
return operations;
|
|
6242
|
+
}
|
|
6243
|
+
function createBaseOnlyMergeOperation(baseFile, cwd) {
|
|
6244
|
+
const dir = path3.dirname(baseFile);
|
|
6245
|
+
const fullBasename = path3.basename(baseFile);
|
|
6246
|
+
const type = getFileType(fullBasename);
|
|
6247
|
+
if (type === "unknown") {
|
|
6248
|
+
return null;
|
|
6249
|
+
}
|
|
6250
|
+
let outputName;
|
|
6251
|
+
if (type === "env") {
|
|
6252
|
+
outputName = fullBasename.replace(".base", "").replace(".{base}", "");
|
|
6253
|
+
} else {
|
|
6254
|
+
outputName = fullBasename.replace(".base", "").replace(".{base}", "");
|
|
6255
|
+
}
|
|
6256
|
+
const basePath = path3.join(cwd, baseFile);
|
|
6257
|
+
const outputPath = path3.join(cwd, dir, outputName);
|
|
6258
|
+
return {
|
|
6259
|
+
basePath,
|
|
6260
|
+
machinePath: "",
|
|
6261
|
+
outputPath,
|
|
6262
|
+
type
|
|
6263
|
+
};
|
|
6264
|
+
}
|
|
6265
|
+
function createMergeOperation(machineFile, machineName, cwd) {
|
|
6266
|
+
const dir = path3.dirname(machineFile);
|
|
6267
|
+
const fullBasename = path3.basename(machineFile);
|
|
6268
|
+
const type = getFileType(fullBasename);
|
|
6269
|
+
const ext2 = path3.extname(machineFile);
|
|
6270
|
+
if (type === "unknown") {
|
|
6271
|
+
return null;
|
|
6272
|
+
}
|
|
6273
|
+
let baseName;
|
|
6274
|
+
let outputName;
|
|
6275
|
+
if (hasFilters(fullBasename)) {
|
|
6276
|
+
outputName = getBaseFilename(fullBasename);
|
|
6277
|
+
if (type === "env") {
|
|
6278
|
+
const nameWithoutExt = outputName;
|
|
6279
|
+
baseName = nameWithoutExt + ".base";
|
|
6280
|
+
} else {
|
|
6281
|
+
const nameWithoutExt = outputName.replace(ext2, "");
|
|
6282
|
+
baseName = nameWithoutExt + ".base" + ext2;
|
|
6283
|
+
}
|
|
6284
|
+
} else {
|
|
6285
|
+
const basename = type === "env" ? fullBasename : path3.basename(machineFile, ext2);
|
|
6286
|
+
const machinePattern = `.${machineName}`;
|
|
6287
|
+
if (basename.endsWith(machinePattern)) {
|
|
6288
|
+
const withoutMachine = basename.substring(0, basename.length - machinePattern.length);
|
|
6289
|
+
baseName = withoutMachine + ".base";
|
|
6290
|
+
outputName = withoutMachine;
|
|
6291
|
+
if (type !== "env") {
|
|
6292
|
+
baseName = baseName + ext2;
|
|
6293
|
+
outputName = outputName + ext2;
|
|
6294
|
+
}
|
|
6295
|
+
} else {
|
|
6296
|
+
return null;
|
|
6297
|
+
}
|
|
6298
|
+
}
|
|
6299
|
+
const basePath = path3.join(cwd, dir, baseName);
|
|
6300
|
+
const machinePath = path3.join(cwd, machineFile);
|
|
6301
|
+
const outputPath = path3.join(cwd, dir, outputName);
|
|
6302
|
+
return {
|
|
6303
|
+
basePath,
|
|
6304
|
+
machinePath,
|
|
6305
|
+
outputPath,
|
|
6306
|
+
type
|
|
6307
|
+
};
|
|
6308
|
+
}
|
|
6309
|
+
|
|
6310
|
+
// src/core/merger.ts
|
|
6311
|
+
import fs from "node:fs/promises";
|
|
6312
|
+
import path4 from "node:path";
|
|
6248
6313
|
|
|
6249
6314
|
// src/utils/logger.ts
|
|
6250
6315
|
var silent = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "permachine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Automatically merge machine-specific config files with base configs using git hooks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -57,4 +57,4 @@
|
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=18.0.0"
|
|
59
59
|
}
|
|
60
|
-
}
|
|
60
|
+
}
|