fix: command path on windows
MODIFY
src/generators/app.ts
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)

MODIFY
src/generators/command.ts
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)

MODIFY
templates/src/command.js.ejs
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, '\\\\') %>`)
}
}

MODIFY
templates/src/command.ts.ejs
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}`)
}

fix: command path on windows (#96)