Skip to content

Commit

Permalink
Merge pull request #1719 from zhangfisher/master
Browse files Browse the repository at this point in the history
feat: Update cli.ts, option `-c` support absolute path
  • Loading branch information
WoH authored Dec 8, 2024
2 parents 918ad68 + dbf8986 commit a6afd4b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { generateRoutes } from './module/generate-routes';
import { generateSpec } from './module/generate-spec';
import { fsExists, fsReadFile } from './utils/fs';
import { AbstractRouteGenerator } from './routeGeneration/routeGenerator';
import { extname } from 'node:path';
import { extname,isAbsolute } from 'node:path';
import type { CompilerOptions } from 'typescript';

const workingDir: string = process.cwd();
Expand Down Expand Up @@ -54,14 +54,15 @@ const isJsExtension = (extension: string): boolean => extension === '.js' || ext
const getConfig = async (configPath = 'tsoa.json'): Promise<Config> => {
let config: Config;
const ext = extname(configPath);
const configFullPath = isAbsolute(configPath) ? configPath : `${workingDir}/${configPath}`
try {
if (isYamlExtension(ext)) {
const configRaw = await fsReadFile(`${workingDir}/${configPath}`);
const configRaw = await fsReadFile(configFullPath);
config = YAML.parse(configRaw.toString('utf8'));
} else if (isJsExtension(ext)) {
config = await import(`${workingDir}/${configPath}`);
config = await import(configFullPath);
} else {
const configRaw = await fsReadFile(`${workingDir}/${configPath}`);
const configRaw = await fsReadFile(configFullPath);
config = JSON.parse(configRaw.toString('utf8'));
}
} catch (err) {
Expand Down

0 comments on commit a6afd4b

Please sign in to comment.