Skip to content

Commit 10ea31e

Browse files
committed
🛠️ fix(tools): improve input file handling and workflow triggers
Added smart fallback logic for config file resolution and updated GitHub workflow triggers to support pull requests and manual runs. Now users can use shorthand notation for environment configs (e.g., "local" → "salakala.local.json"). Also includes version bump to 1.0.3.
1 parent 4027b40 commit 10ea31e

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ on:
1919
required: true
2020
BW_PASSWORD:
2121
required: true
22-
push:
22+
pull_request:
2323
branches: [ main ]
24+
workflow_dispatch:
2425

2526
jobs:
2627
test:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"bin": {
44
"salakala": "./dist/cli.js"
55
},
6-
"version": "1.0.1",
6+
"version": "1.0.3",
77
"description": "Generate environment variables from various secret providers via URIs in JSON files, checked into your repository",
88
"type": "module",
99
"scripts": {

src/cli.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,36 @@ import { SecretsManager } from './lib/SecretsManager.js';
55
import { program } from '@commander-js/extra-typings';
66
import { escapeEnvValue } from './lib/envEscape.js';
77

8+
/**
9+
* Resolves the input file path with smart fallback logic.
10+
* If the exact file exists, uses it.
11+
* If not found and input doesn't contain extension, tries salakala.{input}.json.
12+
*
13+
* @param {string} input - The input file path or name
14+
* @returns {string} The resolved file path
15+
* @throws {Error} If no valid file is found
16+
*/
17+
function resolveInputFile(input: string): string {
18+
// If the exact file exists, use it
19+
if (existsSync(input)) {
20+
return input;
21+
}
22+
23+
// If the input doesn't contain a dot (no extension), try the salakala.{input}.json pattern
24+
if (!input.includes('.')) {
25+
const salakalatPattern = `salakala.${input}.json`;
26+
if (existsSync(salakalatPattern)) {
27+
return salakalatPattern;
28+
}
29+
30+
// Both attempts failed
31+
throw new Error(`Configuration file not found. Tried:\n - ${input}\n - ${salakalatPattern}`);
32+
}
33+
34+
// Input has extension but file doesn't exist
35+
throw new Error(`Configuration file '${input}' not found`);
36+
}
37+
838
const PACKAGE_VERSION = '1.0.1';
939

1040
program
@@ -13,7 +43,7 @@ program
1343
.version(PACKAGE_VERSION);
1444

1545
program
16-
.option('-i, --input <file>', 'input salakala json file path', 'salakala.json')
46+
.option('-i, --input <file>', 'input config file path or environment name (e.g., "local" → "salakala.local.json")', 'salakala.json')
1747
.option('-e, --env <environment>', 'environment to use from input file', 'development')
1848
.option('-o, --output <file>', 'output file path', '.env')
1949
.option('-w, --overwrite', 'overwrite the output file instead of merging with existing values')
@@ -30,7 +60,8 @@ program
3060
}
3161

3262
const manager = new SecretsManager();
33-
const secrets = await manager.loadSecrets(options.input, options.env);
63+
const resolvedInputFile = resolveInputFile(options.input);
64+
const secrets = await manager.loadSecrets(resolvedInputFile, options.env);
3465

3566
if(options.set) {
3667
Object.entries(secrets).forEach(([key, value]) => {

0 commit comments

Comments
 (0)