Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
fix: command path on windows (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Apr 8, 2018
1 parent 1381021 commit 612f401
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/generators/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/generators/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion templates/src/command.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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, '\\\\') %>`)
}
}

Expand Down
2 changes: 1 addition & 1 deletion templates/src/command.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
Expand Down

0 comments on commit 612f401

Please sign in to comment.