permachine 0.5.2 → 0.7.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.
Files changed (2) hide show
  1. package/dist/cli.js +176 -178
  2. 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 path2 from "node:path";
5803
+ import path3 from "node:path";
5804
5804
 
5805
5805
  // src/core/file-filters.ts
5806
5806
  import os2 from "node:os";
@@ -5944,181 +5944,8 @@ function isLegacyFilename(filename, machineName) {
5944
5944
  return (middlePattern.test(filename) || endPattern.test(filename)) && !hasFilters(filename);
5945
5945
  }
5946
5946
 
5947
- // src/core/file-scanner.ts
5948
- async function scanForMergeOperations(machineName, cwd = process.cwd()) {
5949
- const operations = [];
5950
- const processedOutputs = new Set;
5951
- const baseFilesWithMachineFiles = new Set;
5952
- const patterns = [
5953
- "**/*{*}*",
5954
- `**/*.${machineName}.*`,
5955
- `**/.*.${machineName}`,
5956
- `**/.*.${machineName}.*`
5957
- ];
5958
- const foundFiles = [];
5959
- for (const pattern of patterns) {
5960
- try {
5961
- const files = await glob(pattern, {
5962
- cwd,
5963
- ignore: ["node_modules/**", ".git/**", "dist/**", "**/*.base.*", "**/.*base*"],
5964
- dot: true,
5965
- nodir: true
5966
- });
5967
- foundFiles.push(...files);
5968
- } catch (error) {}
5969
- }
5970
- const uniqueFiles = [...new Set(foundFiles)];
5971
- const context = createCustomContext({ machine: machineName });
5972
- for (const file of uniqueFiles) {
5973
- const basename = path2.basename(file);
5974
- if (isBaseFile(basename)) {
5975
- continue;
5976
- }
5977
- let shouldProcess = false;
5978
- if (hasFilters(basename)) {
5979
- const result = matchFilters(basename, context);
5980
- shouldProcess = result.matches;
5981
- const operation = createMergeOperation(file, machineName, cwd);
5982
- if (operation && operation.basePath) {
5983
- baseFilesWithMachineFiles.add(operation.basePath);
5984
- }
5985
- } else if (isLegacyFilename(basename, machineName)) {
5986
- shouldProcess = true;
5987
- const operation = createMergeOperation(file, machineName, cwd);
5988
- if (operation && operation.basePath) {
5989
- baseFilesWithMachineFiles.add(operation.basePath);
5990
- }
5991
- }
5992
- if (shouldProcess) {
5993
- const operation = createMergeOperation(file, machineName, cwd);
5994
- if (operation) {
5995
- operations.push(operation);
5996
- processedOutputs.add(operation.outputPath);
5997
- }
5998
- }
5999
- }
6000
- const basePatterns = [
6001
- "**/*.base.json",
6002
- "**/.*.base",
6003
- "**/.*.base.*"
6004
- ];
6005
- for (const pattern of basePatterns) {
6006
- try {
6007
- const baseFiles = await glob(pattern, {
6008
- cwd,
6009
- ignore: ["node_modules/**", ".git/**", "dist/**"],
6010
- dot: true,
6011
- nodir: true
6012
- });
6013
- for (const baseFile of baseFiles) {
6014
- const fullPath = path2.join(cwd, baseFile);
6015
- if (baseFilesWithMachineFiles.has(fullPath)) {
6016
- continue;
6017
- }
6018
- const operation = createBaseOnlyMergeOperation(baseFile, cwd);
6019
- if (operation && !processedOutputs.has(operation.outputPath)) {
6020
- operations.push(operation);
6021
- processedOutputs.add(operation.outputPath);
6022
- }
6023
- }
6024
- } catch (error) {}
6025
- }
6026
- return operations;
6027
- }
6028
- function createBaseOnlyMergeOperation(baseFile, cwd) {
6029
- const dir = path2.dirname(baseFile);
6030
- const fullBasename = path2.basename(baseFile);
6031
- let type;
6032
- let ext2;
6033
- if (fullBasename.endsWith(".json") || fullBasename.includes(".base.json") || fullBasename.includes(".{base}.json")) {
6034
- type = "json";
6035
- ext2 = ".json";
6036
- } else if (fullBasename.startsWith(".env")) {
6037
- type = "env";
6038
- ext2 = "";
6039
- } else {
6040
- type = "unknown";
6041
- ext2 = path2.extname(baseFile);
6042
- }
6043
- if (type === "unknown") {
6044
- return null;
6045
- }
6046
- let outputName;
6047
- if (type === "env") {
6048
- outputName = fullBasename.replace(".base", "").replace(".{base}", "");
6049
- } else {
6050
- outputName = fullBasename.replace(".base", "").replace(".{base}", "");
6051
- }
6052
- const basePath = path2.join(cwd, baseFile);
6053
- const outputPath = path2.join(cwd, dir, outputName);
6054
- return {
6055
- basePath,
6056
- machinePath: "",
6057
- outputPath,
6058
- type
6059
- };
6060
- }
6061
- function createMergeOperation(machineFile, machineName, cwd) {
6062
- const dir = path2.dirname(machineFile);
6063
- const fullBasename = path2.basename(machineFile);
6064
- let type;
6065
- let ext2;
6066
- if (fullBasename.endsWith(".json")) {
6067
- type = "json";
6068
- ext2 = ".json";
6069
- } else if (fullBasename.startsWith(".env")) {
6070
- type = "env";
6071
- ext2 = "";
6072
- } else {
6073
- type = "unknown";
6074
- ext2 = path2.extname(machineFile);
6075
- }
6076
- if (type === "unknown") {
6077
- return null;
6078
- }
6079
- let baseName;
6080
- let outputName;
6081
- if (hasFilters(fullBasename)) {
6082
- outputName = getBaseFilename(fullBasename);
6083
- if (type === "env") {
6084
- const nameWithoutExt = outputName;
6085
- baseName = nameWithoutExt + ".base";
6086
- } else {
6087
- const nameWithoutExt = outputName.replace(ext2, "");
6088
- baseName = nameWithoutExt + ".base" + ext2;
6089
- }
6090
- } else {
6091
- const basename = type === "env" ? fullBasename : path2.basename(machineFile, ext2);
6092
- const machinePattern = `.${machineName}`;
6093
- if (basename.endsWith(machinePattern)) {
6094
- const withoutMachine = basename.substring(0, basename.length - machinePattern.length);
6095
- baseName = withoutMachine + ".base";
6096
- outputName = withoutMachine;
6097
- if (type !== "env") {
6098
- baseName = baseName + ext2;
6099
- outputName = outputName + ext2;
6100
- }
6101
- } else {
6102
- return null;
6103
- }
6104
- }
6105
- const basePath = path2.join(cwd, dir, baseName);
6106
- const machinePath = path2.join(cwd, machineFile);
6107
- const outputPath = path2.join(cwd, dir, outputName);
6108
- return {
6109
- basePath,
6110
- machinePath,
6111
- outputPath,
6112
- type
6113
- };
6114
- }
6115
-
6116
- // src/core/merger.ts
6117
- import fs from "node:fs/promises";
6118
- import path4 from "node:path";
6119
-
6120
5947
  // src/adapters/adapter-factory.ts
6121
- import path3 from "node:path";
5948
+ import path2 from "node:path";
6122
5949
 
6123
5950
  // node_modules/strip-json-comments/index.js
6124
5951
  var singleComment = Symbol("singleComment");
@@ -6215,7 +6042,7 @@ function stripJsonComments(jsonString, { whitespace = true, trailingCommas = fal
6215
6042
  // src/adapters/json-adapter.ts
6216
6043
  class JsonAdapter {
6217
6044
  canHandle(extension) {
6218
- return extension === ".json";
6045
+ return extension === ".json" || extension === ".jsonc";
6219
6046
  }
6220
6047
  parse(content) {
6221
6048
  try {
@@ -6307,11 +6134,11 @@ var adapters = [
6307
6134
  new EnvAdapter
6308
6135
  ];
6309
6136
  function getAdapter(filePath) {
6310
- const basename = path3.basename(filePath);
6137
+ const basename = path2.basename(filePath);
6311
6138
  if (basename.startsWith(".env")) {
6312
6139
  return new EnvAdapter;
6313
6140
  }
6314
- const ext2 = path3.extname(filePath);
6141
+ const ext2 = path2.extname(filePath);
6315
6142
  for (const adapter of adapters) {
6316
6143
  if (adapter.canHandle(ext2)) {
6317
6144
  return adapter;
@@ -6319,6 +6146,177 @@ function getAdapter(filePath) {
6319
6146
  }
6320
6147
  return null;
6321
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
+ if (outputName.endsWith(".jsonc")) {
6256
+ outputName = outputName.replace(/\.jsonc$/, ".json");
6257
+ }
6258
+ }
6259
+ const basePath = path3.join(cwd, baseFile);
6260
+ const outputPath = path3.join(cwd, dir, outputName);
6261
+ return {
6262
+ basePath,
6263
+ machinePath: "",
6264
+ outputPath,
6265
+ type
6266
+ };
6267
+ }
6268
+ function createMergeOperation(machineFile, machineName, cwd) {
6269
+ const dir = path3.dirname(machineFile);
6270
+ const fullBasename = path3.basename(machineFile);
6271
+ const type = getFileType(fullBasename);
6272
+ const ext2 = path3.extname(machineFile);
6273
+ if (type === "unknown") {
6274
+ return null;
6275
+ }
6276
+ let baseName;
6277
+ let outputName;
6278
+ if (hasFilters(fullBasename)) {
6279
+ outputName = getBaseFilename(fullBasename);
6280
+ if (type === "json" && outputName.endsWith(".jsonc")) {
6281
+ outputName = outputName.replace(/\.jsonc$/, ".json");
6282
+ }
6283
+ if (type === "env") {
6284
+ const nameWithoutExt = outputName;
6285
+ baseName = nameWithoutExt + ".base";
6286
+ } else {
6287
+ const nameWithoutExt = outputName.replace(/\.(json|jsonc)$/, "");
6288
+ baseName = nameWithoutExt + ".base" + ext2;
6289
+ }
6290
+ } else {
6291
+ const basename = type === "env" ? fullBasename : path3.basename(machineFile, ext2);
6292
+ const machinePattern = `.${machineName}`;
6293
+ if (basename.endsWith(machinePattern)) {
6294
+ const withoutMachine = basename.substring(0, basename.length - machinePattern.length);
6295
+ baseName = withoutMachine + ".base";
6296
+ outputName = withoutMachine;
6297
+ if (type !== "env") {
6298
+ baseName = baseName + ext2;
6299
+ const outputExt = ext2 === ".jsonc" ? ".json" : ext2;
6300
+ outputName = outputName + outputExt;
6301
+ }
6302
+ } else {
6303
+ return null;
6304
+ }
6305
+ }
6306
+ const basePath = path3.join(cwd, dir, baseName);
6307
+ const machinePath = path3.join(cwd, machineFile);
6308
+ const outputPath = path3.join(cwd, dir, outputName);
6309
+ return {
6310
+ basePath,
6311
+ machinePath,
6312
+ outputPath,
6313
+ type
6314
+ };
6315
+ }
6316
+
6317
+ // src/core/merger.ts
6318
+ import fs from "node:fs/promises";
6319
+ import path4 from "node:path";
6322
6320
 
6323
6321
  // src/utils/logger.ts
6324
6322
  var silent = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "permachine",
3
- "version": "0.5.2",
3
+ "version": "0.7.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
+ }