Skip to content

Commit

Permalink
feat: add absolute path support to other CLI commands (typeorm#6807)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasreimers committed Oct 1, 2020
1 parent f3de0f6 commit d9a76e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/commands/EntityCreateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class EntityCreateCommand implements yargs.CommandModule {
try {
const fileContent = EntityCreateCommand.getTemplate(args.name as any);
const filename = args.name + ".ts";
let directory = args.dir;
let directory = args.dir as string;

// if directory is not set then try to open tsconfig and find default path there
if (!directory) {
Expand All @@ -51,7 +51,7 @@ export class EntityCreateCommand implements yargs.CommandModule {
} catch (err) { }
}

const path = process.cwd() + "/" + (directory ? (directory + "/") : "") + filename;
const path = (directory.startsWith("/") ? "" : process.cwd() + "/") + (directory ? (directory + "/") : "") + filename;
const fileExists = await CommandUtils.fileExists(path);
if (fileExists) {
throw `File ${chalk.blue(path)} already exists`;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/SubscriberCreateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SubscriberCreateCommand implements yargs.CommandModule {
try {
const fileContent = SubscriberCreateCommand.getTemplate(args.name as any);
const filename = args.name + ".ts";
let directory = args.dir;
let directory = args.dir as string;

// if directory is not set then try to open tsconfig and find default path there
if (!directory) {
Expand All @@ -52,7 +52,7 @@ export class SubscriberCreateCommand implements yargs.CommandModule {
} catch (err) { }
}

const path = process.cwd() + "/" + (directory ? (directory + "/") : "") + filename;
const path = (directory.startsWith("/") ? "" : process.cwd() + "/") + (directory ? (directory + "/") : "") + filename;
await CommandUtils.createFile(path, fileContent);
console.log(chalk.green(`Subscriber ${chalk.blue(path)} has been created successfully.`));

Expand Down

0 comments on commit d9a76e9

Please sign in to comment.