permachine 0.5.1 → 0.5.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.
Files changed (2) hide show
  1. package/dist/cli.js +75 -1
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -5934,6 +5934,10 @@ 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");
@@ -5943,6 +5947,8 @@ function isLegacyFilename(filename, machineName) {
5943
5947
  // src/core/file-scanner.ts
5944
5948
  async function scanForMergeOperations(machineName, cwd = process.cwd()) {
5945
5949
  const operations = [];
5950
+ const processedOutputs = new Set;
5951
+ const baseFilesWithMachineFiles = new Set;
5946
5952
  const patterns = [
5947
5953
  "**/*{*}*",
5948
5954
  `**/*.${machineName}.*`,
@@ -5965,25 +5971,93 @@ async function scanForMergeOperations(machineName, cwd = process.cwd()) {
5965
5971
  const context = createCustomContext({ machine: machineName });
5966
5972
  for (const file of uniqueFiles) {
5967
5973
  const basename = path2.basename(file);
5968
- if (basename.includes(".base.") || basename.includes(".base")) {
5974
+ if (isBaseFile(basename)) {
5969
5975
  continue;
5970
5976
  }
5971
5977
  let shouldProcess = false;
5972
5978
  if (hasFilters(basename)) {
5973
5979
  const result = matchFilters(basename, context);
5974
5980
  shouldProcess = result.matches;
5981
+ const operation = createMergeOperation(file, machineName, cwd);
5982
+ if (operation && operation.basePath) {
5983
+ baseFilesWithMachineFiles.add(operation.basePath);
5984
+ }
5975
5985
  } else if (isLegacyFilename(basename, machineName)) {
5976
5986
  shouldProcess = true;
5987
+ const operation = createMergeOperation(file, machineName, cwd);
5988
+ if (operation && operation.basePath) {
5989
+ baseFilesWithMachineFiles.add(operation.basePath);
5990
+ }
5977
5991
  }
5978
5992
  if (shouldProcess) {
5979
5993
  const operation = createMergeOperation(file, machineName, cwd);
5980
5994
  if (operation) {
5981
5995
  operations.push(operation);
5996
+ processedOutputs.add(operation.outputPath);
5982
5997
  }
5983
5998
  }
5984
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
+ }
5985
6026
  return operations;
5986
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
+ }
5987
6061
  function createMergeOperation(machineFile, machineName, cwd) {
5988
6062
  const dir = path2.dirname(machineFile);
5989
6063
  const fullBasename = path2.basename(machineFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "permachine",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Automatically merge machine-specific config files with base configs using git hooks",
5
5
  "type": "module",
6
6
  "bin": {