Skip to content

Commit

Permalink
fix: simplified bin scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 28, 2018
1 parent 8d42d1e commit 8b36b61
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 74 deletions.
12 changes: 1 addition & 11 deletions bin/run
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
#!/usr/bin/env node

/* eslint-disable no-unpublished-require */

const undefault = m => m.__esModule === true ? m.default : m

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

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

undefault(require(`../${dev ? 'src' : 'lib'}`))()
require('..').run()
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"bin": "bin/run",
"bugs": "https://github.com/dxcli/create-dxcli/issues",
"dependencies": {
"@dxcli/command": "^0.2.3",
"@dxcli/config": "^0.1.32",
"@dxcli/command": "^0.2.4",
"@dxcli/config": "^0.1.33",
"@dxcli/engine": "^0.1.17",
"@dxcli/version": "^0.1.12",
"cli-ux": "^3.3.8",
Expand Down
10 changes: 7 additions & 3 deletions src/generators/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class App extends Generator {

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('plugin/bin/run'), 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) {
Expand All @@ -416,7 +416,11 @@ class App extends Generator {

private _writeSingle() {
if (!this.fromScratch) return
this.fs.copyTpl(this.templatePath(`single/bin/run.${this._ext}`), this.destinationPath('bin/run'), this)
if (this.ts) {
this.fs.copyTpl(this.templatePath('single/bin/run.ts'), this.destinationPath('bin/run'), this)
} else {
this.fs.copyTpl(this.templatePath('bin/run'), 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) {
Expand All @@ -427,7 +431,7 @@ class App extends Generator {
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'), 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)
}
Expand Down
3 changes: 3 additions & 0 deletions templates/bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('..').run()
4 changes: 0 additions & 4 deletions templates/multi/bin/run.js

This file was deleted.

13 changes: 0 additions & 13 deletions templates/multi/bin/run.ts

This file was deleted.

3 changes: 1 addition & 2 deletions templates/multi/src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
const {run} = require('@dxcli/engine')
module.exports = run
module.exports = require('@dxcli/engine')
4 changes: 1 addition & 3 deletions templates/multi/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import run from '@dxcli/engine'
export {run}
export default run
export {run} from '@dxcli/engine'
3 changes: 3 additions & 0 deletions templates/plugin/bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('@dxcli/engine').run()
4 changes: 0 additions & 4 deletions templates/plugin/bin/run.js

This file was deleted.

10 changes: 0 additions & 10 deletions templates/plugin/bin/run.ts

This file was deleted.

4 changes: 0 additions & 4 deletions templates/single/bin/run.js

This file was deleted.

13 changes: 1 addition & 12 deletions templates/single/bin/run.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
#!/usr/bin/env node

/* eslint-disable no-unpublished-require */

const undefault = m => m.__esModule === true ? m.default : m

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

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

const cmd = undefault(require(`../${dev ? 'src' : 'lib'}`))
cmd.run()
require('..').default.run()
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@
lodash "^4.17.4"
tslib "^1.9.0"

"@dxcli/command@^0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@dxcli/command/-/command-0.2.3.tgz#244ffea9939bd3a4b6cd9defe5f8657a5041cb93"
"@dxcli/command@^0.2.4":
version "0.2.4"
resolved "https://registry.yarnpkg.com/@dxcli/command/-/command-0.2.4.tgz#697dd134d60b409e2a42b86260835e78967d10de"
dependencies:
"@dxcli/parser" "^0.0.5"
debug "^3.1.0"
lodash "^4.17.4"
tslib "^1.9.0"

"@dxcli/config@^0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@dxcli/config/-/config-0.1.32.tgz#b07b33cc9f91031ff795983bacf8a84f60294ecb"
"@dxcli/config@^0.1.33":
version "0.1.33"
resolved "https://registry.yarnpkg.com/@dxcli/config/-/config-0.1.33.tgz#b29c059c2f5b8b764f00ccf42b2ea7aaa4f962e4"
dependencies:
cli-ux "^3.3.8"
debug "^3.1.0"
Expand Down

0 comments on commit 8b36b61

Please sign in to comment.