Skip to content

Commit e2fa67b

Browse files
authored
Merge pull request #110 from Araxeus/new-config-flag
2 parents 27832dc + ec73fee commit e2fa67b

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Commands:
300300
help [command] display help for command
301301
302302
Options:
303-
-d, --folder [folder] Folder containing the config file
303+
-c, --config [file/folder path] Config file path / Folder containing the config file
304304
-v, --version output the current version
305305
-h, --help display help for command
306306
```

cli.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ program
180180
.name('vendor')
181181
.hook('preAction', async () => {
182182
setRunOptions({
183-
configFolder: program.getOptionValue('folder') as
183+
configLocation: program.getOptionValue('config') as
184184
| string
185185
| undefined,
186186
});
@@ -193,7 +193,10 @@ program
193193
.addCommand(installCmd)
194194
.addCommand(uninstallCmd)
195195
.addCommand(loginCmd)
196-
.option('-d, --folder [folder]', 'Folder containing the config file')
196+
.option(
197+
'-c, --config [file/folder path]',
198+
'Config file path / Folder containing the config file',
199+
)
197200
.version(
198201
(await getPackageJson()).version || 'unknown',
199202
'-v, --version',

lib/config.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const defaultConfig = {
2020

2121
const runOptions = {
2222
prMode: false,
23-
configFolder: '',
23+
configLocation: '',
2424
};
2525
export function getRunOptions(): typeof runOptions {
2626
return runOptions;
@@ -29,18 +29,18 @@ export function setRunOptions(flags: Partial<typeof runOptions>) {
2929
Object.assign(runOptions, flags);
3030
}
3131

32-
// function to get the configuration
33-
3432
async function findFirstFile(folderPath: string, files: string[]) {
33+
const getFile = async (file: string) => ({
34+
data: await readFile(file, 'utf-8'),
35+
path: file,
36+
});
37+
const isAlreadyFilepath = files.find(f => folderPath.endsWith(f));
38+
if (isAlreadyFilepath && existsSync(folderPath)) {
39+
return getFile(folderPath);
40+
}
3541
for (const file of files) {
3642
const filePath = path.join(folderPath, file);
37-
38-
if (existsSync(filePath)) {
39-
return {
40-
data: await readFile(filePath, 'utf-8'),
41-
path: filePath,
42-
};
43-
}
43+
if (existsSync(filePath)) return getFile(filePath);
4444
}
4545

4646
return null;
@@ -92,7 +92,7 @@ export async function getConfig(): Promise<VendorsOptions> {
9292
if (res) return res;
9393

9494
const folderPath = await realpath(
95-
runOptions.configFolder ||
95+
runOptions.configLocation ||
9696
process.env.INIT_CWD ||
9797
process.env.PWD ||
9898
process.cwd(),

0 commit comments

Comments
 (0)