Skip to content

Commit

Permalink
fix: fixing single and adding windows cmd scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 28, 2018
1 parent 768d2d9 commit 3659d86
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
3 changes: 3 additions & 0 deletions bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
31 changes: 17 additions & 14 deletions src/generators/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -421,13 +414,23 @@ 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)
}
}

export = App
3 changes: 3 additions & 0 deletions templates/bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
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 {
async run() {
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 %>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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'})
}

async run() {
async run () {
const name = this.flags.name || 'world'
cli.log(`hello ${name}!`)
}
Expand Down
4 changes: 2 additions & 2 deletions templates/single/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!')
})

0 comments on commit 3659d86

Please sign in to comment.