Skip to content

Commit a6afd4b

Browse files
authored
Merge pull request #1719 from zhangfisher/master
feat: Update cli.ts, option `-c` support absolute path
2 parents 918ad68 + dbf8986 commit a6afd4b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/cli/src/cli.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { generateRoutes } from './module/generate-routes';
88
import { generateSpec } from './module/generate-spec';
99
import { fsExists, fsReadFile } from './utils/fs';
1010
import { AbstractRouteGenerator } from './routeGeneration/routeGenerator';
11-
import { extname } from 'node:path';
11+
import { extname,isAbsolute } from 'node:path';
1212
import type { CompilerOptions } from 'typescript';
1313

1414
const workingDir: string = process.cwd();
@@ -54,14 +54,15 @@ const isJsExtension = (extension: string): boolean => extension === '.js' || ext
5454
const getConfig = async (configPath = 'tsoa.json'): Promise<Config> => {
5555
let config: Config;
5656
const ext = extname(configPath);
57+
const configFullPath = isAbsolute(configPath) ? configPath : `${workingDir}/${configPath}`
5758
try {
5859
if (isYamlExtension(ext)) {
59-
const configRaw = await fsReadFile(`${workingDir}/${configPath}`);
60+
const configRaw = await fsReadFile(configFullPath);
6061
config = YAML.parse(configRaw.toString('utf8'));
6162
} else if (isJsExtension(ext)) {
62-
config = await import(`${workingDir}/${configPath}`);
63+
config = await import(configFullPath);
6364
} else {
64-
const configRaw = await fsReadFile(`${workingDir}/${configPath}`);
65+
const configRaw = await fsReadFile(configFullPath);
6566
config = JSON.parse(configRaw.toString('utf8'));
6667
}
6768
} catch (err) {

0 commit comments

Comments
 (0)