fix: fixing single and adding windows cmd scripts
ADD
bin/run.cmd
+@echo off
+
+node "%~dp0\run" %*

MODIFY
src/generators/app/index.ts
src/generators/app/index.ts
@@ -393,25 +393,18 @@ class App extends Generator {
.join('\n') + '\n'
}
- private _writeSingle () {
+ private _writeBase () {
if (!this.fromScratch) return
- this.fs.copyTpl(this.templatePath(`single/bin/run.${this._ext}`), this.destinationPath('bin/run'), this)
- this.fs.copyTpl(this.templatePath(`single/src/index.${this._ext}`), this.destinationPath(`src/index.${this._ext}`), this)
+ this.fs.copyTpl(this.templatePath(`base/src/index.${this._ext}`), this.destinationPath(`src/index.${this._ext}`), this)
if (this.mocha) {
- this.fs.copyTpl(this.templatePath(`single/test/index.test.${this._ext}`), this.destinationPath(`test/index.test.${this._ext}`), this)
- }
+ this.fs.copyTpl(this.templatePath(`base/test/index.test.${this._ext}`), this.destinationPath(`test/index.test.${this._ext}`), this)
}
-
- private _writeMulti () {
- if (!this.fromScratch) return
- this._writePlugin()
- this.fs.copyTpl(this.templatePath(`multi/bin/run.${this._ext}`), this.destinationPath('bin/run'), this)
- this.fs.copyTpl(this.templatePath(`multi/src/index.${this._ext}`), this.destinationPath(`src/index.${this._ext}`), this)
}
private _writePlugin () {
if (!this.fromScratch) return
this.fs.copyTpl(this.templatePath(`plugin/bin/run.${this._ext}`), this.destinationPath('bin/run'), this)
+ this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), this)
this.fs.copyTpl(this.templatePath(`command.${this._ext}.ejs`), this.destinationPath(`src/commands/hello.${this._ext}`), {name: 'hello', _})
if (this.ts) {
this.fs.copyTpl(this.templatePath('plugin/src/index.ts'), this.destinationPath('src/index.ts'), this)
@@ -421,12 +414,22 @@ class App extends Generator {
}
}
- private _writeBase () {
+ private _writeSingle () {
if (!this.fromScratch) return
- this.fs.copyTpl(this.templatePath(`base/src/index.${this._ext}`), this.destinationPath(`src/index.${this._ext}`), this)
+ this.fs.copyTpl(this.templatePath(`single/bin/run.${this._ext}`), this.destinationPath('bin/run'), this)
+ this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), this)
+ this.fs.copyTpl(this.templatePath(`single/src/index.${this._ext}.ejs`), this.destinationPath(`src/index.${this._ext}`), {name: this.pjson.name, _})
if (this.mocha) {
- this.fs.copyTpl(this.templatePath(`base/test/index.test.${this._ext}`), this.destinationPath(`test/index.test.${this._ext}`), this)
+ this.fs.copyTpl(this.templatePath(`single/test/index.test.${this._ext}`), this.destinationPath(`test/index.test.${this._ext}`), this)
+ }
}
+
+ private _writeMulti () {
+ if (!this.fromScratch) return
+ this._writePlugin()
+ this.fs.copyTpl(this.templatePath(`multi/bin/run.${this._ext}`), this.destinationPath('bin/run'), this)
+ this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), this)
+ this.fs.copyTpl(this.templatePath(`multi/src/index.${this._ext}`), this.destinationPath(`src/index.${this._ext}`), this)
}
}

ADD
templates/bin/run.cmd
+@echo off
+
+node "%~dp0\run" %*

RENAME
templates/single/src/index.js
templates/single/src/index.js.ejs
const {Command, flags} = require('@dxcli/command')
const {cli} = require('cli-ux')
+<%_ const klass = _.upperFirst(_.camelCase(name.split(':').slice(-1).join(':') + ':command')) _%>
-class CLI extends Command {
+class <%- klass %> extends Command {
async run () {
const name = this.flags.name || 'world'
cli.log(`hello ${name}!`)
}
}
-CLI.flags = {
+<%- klass %>.flags = {
name: flags.string({char: 'n', description: 'name to print'}),
}
-module.exports = CLI
+module.exports = <%- klass %>

RENAME
templates/single/src/index.ts
templates/single/src/index.ts.ejs
-import Command, {flags} from '@dxcli/command'
+import {Command, flags} from '@dxcli/command'
import cli from 'cli-ux'
-export default class CLI extends Command {
+export default class <%- _.upperFirst(_.camelCase(name)) %> extends Command {
static flags = {
name: flags.string({char: 'n', description: 'name to print'})
}

MODIFY
templates/single/test/index.test.js
templates/single/test/index.test.js
@@ -5,12 +5,12 @@ describe('command', () => {
test
.stdout()
.do(() => cmd.run([]))
- .do(output => expect(output.stdout).to.equal('hello world!\n'))
+ .do(ctx => expect(ctx.stdout).to.equal('hello world!\n'))
.it('says hello world!')
test
.stdout()
.do(() => cmd.run(['--name', 'jeff']))
- .do(output => expect(output.stdout).to.equal('hello jeff!\n'))
+ .do(ctx => expect(ctx.stdout).to.equal('hello jeff!\n'))
.it('says hello jeff!')
})

fix: fixing single and adding windows cmd scripts