Skip to content

Commit

Permalink
fix: fixing single
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 1, 2018
1 parent bd567e1 commit 354f46b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
9 changes: 1 addition & 8 deletions src/generators/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,6 @@ class App extends Generator {
'@anycli/help',
'cli-ux',
)
devDependencies.push(
'@anycli/engine',
)
break
case 'plugin':
dependencies.push(
Expand Down Expand Up @@ -458,11 +455,7 @@ class App extends Generator {
let bin = this.pjson.anycli.bin || this.pjson.anycli.dirname || this.pjson.name
if (bin.includes('/')) bin = bin.split('/').pop()
const opts = {...this as any, _, bin, cmd: bin, name: this.pjson.name}
if (this.ts) {
this.fs.copyTpl(this.templatePath('single/bin/run.ts'), this.destinationPath('bin/run'), opts)
} else {
this.fs.copyTpl(this.templatePath('bin/run'), this.destinationPath('bin/run'), opts)
}
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)
this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), this.destinationPath(`src/index.${this._ext}`), opts)
if (this.mocha) {
Expand Down
9 changes: 9 additions & 0 deletions templates/single/bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')
const dev = fs.existsSync(path.join(__dirname, '../tsconfig.json'))

if (dev) require('ts-node/register')

require(`../${dev ? 'src' : 'lib'}`).run()
3 changes: 3 additions & 0 deletions templates/single/bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('..').run()
8 changes: 7 additions & 1 deletion templates/single/bin/run.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/usr/bin/env node

require('@anycli/engine').run()
const fs = require('fs')
const path = require('path')
const dev = fs.existsSync(path.join(__dirname, '../tsconfig.json'))

if (dev) require('ts-node/register')

require(`../${dev ? 'src' : 'lib'}`).run()
8 changes: 8 additions & 0 deletions templates/src/command.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import {Command, flags, parse} from '@anycli/command'
import cli from 'cli-ux'
<%_ const klass = _.upperFirst(_.camelCase(name)) _%>

<%_ if (type === 'single') { _%>
class <%- klass %> extends Command {
<%_ } else { _%>
export default class <%- klass %> extends Command {
<%_ } _%>
static title = 'scaffolded command that says hello'
<%_ if (type !== 'single') { _%>
Expand Down Expand Up @@ -107,3 +111,7 @@ hello myname from <%- name %>!
// this.options.args.file and this.options.argv[0] is a string or undefined
}
}
<%_ if (type === 'single') { _%>
export = <%- klass %>
<%_ } _%>
2 changes: 1 addition & 1 deletion templates/test/command.test.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {expect, test} from '@anycli/test'
<%_ if (type === 'single') { _%>
import cmd from '../src'
import cmd = require('../src')
<%_ } _%>

const command = '<%- name %>'
Expand Down

0 comments on commit 354f46b

Please sign in to comment.