From 612f401aa2f4a4915b2dd46b6f57cc6ceff0e213 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Sun, 8 Apr 2018 15:35:42 -0700 Subject: [PATCH] fix: command path on windows (#96) --- src/generators/app.ts | 6 ++++-- src/generators/command.ts | 5 +++-- templates/src/command.js.ejs | 2 +- templates/src/command.ts.ejs | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/generators/app.ts b/src/generators/app.ts index 9f06d29..5e9eb15 100644 --- a/src/generators/app.ts +++ b/src/generators/app.ts @@ -503,8 +503,9 @@ class App extends Generator { const opts = {...this as any, _, bin, cmd} this.fs.copyTpl(this.templatePath('plugin/bin/run'), this.destinationPath('bin/run'), opts) this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), opts) + const commandPath = this.destinationPath(`src/commands/hello.${this._ext}`) if (!fs.existsSync('src/commands')) { - this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), this.destinationPath(`src/commands/hello.${this._ext}`), {...opts, name: 'hello'}) + this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), commandPath, {...opts, name: 'hello', path: commandPath.replace(process.cwd(), '.')}) } if (this.ts && this.type !== 'multi') { this.fs.copyTpl(this.templatePath('plugin/src/index.ts'), this.destinationPath('src/index.ts'), opts) @@ -519,8 +520,9 @@ class App extends Generator { const opts = {...this as any, _, bin, cmd: bin, name: this.pjson.name} this.fs.copyTpl(this.templatePath(`single/bin/run.${this._ext}`), this.destinationPath('bin/run'), opts) this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), opts) + const commandPath = this.destinationPath(`src/index.${this._ext}`) if (!this.fs.exists(`src/index.${this._ext}`)) { - this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), this.destinationPath(`src/index.${this._ext}`), opts) + this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), this.destinationPath(`src/index.${this._ext}`), {...opts, path: commandPath.replace(process.cwd(), '.')}) } if (this.mocha && !this.fs.exists(`test/index.test.${this._ext}`)) { this.fs.copyTpl(this.templatePath(`test/command.test.${this._ext}.ejs`), this.destinationPath(`test/index.test.${this._ext}`), opts) diff --git a/src/generators/command.ts b/src/generators/command.ts index 68b3b68..cdd0bff 100644 --- a/src/generators/command.ts +++ b/src/generators/command.ts @@ -34,8 +34,9 @@ class CommandGenerator extends Generator { let bin = this.pjson.oclif.bin || this.pjson.oclif.dirname || this.pjson.name if (bin.includes('/')) bin = bin.split('/').pop() const cmd = `${bin} ${this.options.name}` - const opts = {...this.options, bin, cmd, _, type: 'command', path: this._path} - this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), this.destinationPath(`src/commands/${this._path}.${this._ext}`), opts) + const commandPath = this.destinationPath(`src/commands/${this._path}.${this._ext}`) + const opts = {...this.options, bin, cmd, _, type: 'command', path: commandPath} + this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), commandPath, opts) // this.fs.copyTpl(this.templatePath(`plugin/src/hooks/init.${this._ext}`), this.destinationPath(`src/hooks/init.${this._ext}`), this) if (this._mocha) { // this.fs.copyTpl(this.templatePath(`plugin/test/hooks/init.test.${this._ext}`), this.destinationPath(`test/hooks/init.test.${this._ext}`), this) diff --git a/templates/src/command.js.ejs b/templates/src/command.js.ejs index aa6cd4b..d7bf9f9 100644 --- a/templates/src/command.js.ejs +++ b/templates/src/command.js.ejs @@ -5,7 +5,7 @@ class <%- klass %> extends Command { async run() { const {flags} = this.parse(<%- klass %>) const name = flags.name || 'world' - this.log(`hello ${name} from ${__filename}!`) + this.log(`hello ${name} from <%- path.replace(/\\/g, '\\\\') %>`) } } diff --git a/templates/src/command.ts.ejs b/templates/src/command.ts.ejs index e0849d8..29c687d 100644 --- a/templates/src/command.ts.ejs +++ b/templates/src/command.ts.ejs @@ -34,7 +34,7 @@ hello world from ./src/<%- name %>.ts! const {args, flags} = this.parse(<%- klass %>) const name = flags.name || 'world' - this.log(`hello ${name} from ./src/commands/<%- path %>.ts!`) + this.log(`hello ${name} from <%- path.replace(/\\/g, '\\\\') %>`) if (args.file && flags.force) { this.log(`you input --force and --file: ${args.file}`) }