Skip to content

Commit

Permalink
fix: fixed command generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 1, 2018
1 parent 7e7f7d3 commit 8c5c179
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/generators/app/index.ts → src/generators/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import yosay = require('yosay')
const sortPjson = require('sort-pjson')
const fixpack = require('fixpack')
const debug = require('debug')('generator-anycli')
const {version} = require('../../../package.json')
const {version} = require('../../package.json')

function stringToArray(s: string) {
const keywords: string[] = []
Expand Down Expand Up @@ -230,7 +230,7 @@ class App extends Generator {
}

writing() {
this.sourceRoot(path.join(__dirname, '../../../templates'))
this.sourceRoot(path.join(__dirname, '../../templates'))

switch (this.type) {
case 'multi':
Expand Down
9 changes: 5 additions & 4 deletions src/generators/command/index.ts → src/generators/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import * as path from 'path'
import * as Generator from 'yeoman-generator'
import yosay = require('yosay')

import {Options} from '../../commands/command'
import {Options} from '../commands/command'

const {version} = require('../../../package.json')
const {version} = require('../../package.json')

class CommandGenerator extends Generator {
pjson!: any
Expand All @@ -24,16 +24,17 @@ class CommandGenerator extends Generator {

async prompting() {
this.pjson = this.fs.readJSON('package.json')
this.pjson.anycli = this.pjson.anycli || {}
if (!this.pjson) throw new Error('not in a project directory')
this.log(yosay(`Adding a command to ${this.pjson.name} Version: ${version}`))
}

writing() {
this.sourceRoot(path.join(__dirname, '../../../templates'))
this.sourceRoot(path.join(__dirname, '../../templates'))
let bin = this.pjson.anycli.bin || this.pjson.anycli.dirname || this.pjson.name
if (bin.includes('/')) bin = bin.split('/').pop()
const cmd = `${bin} ${this.options.name}`
const opts = {...this.options, cmd, _}
const opts = {...this.options, bin, cmd, _}
this.fs.copyTpl(this.templatePath(`command.${this._ext}.ejs`), this.destinationPath(`src/commands/${this._path}.${this._ext}`), opts)
// this.fs.copyTpl(this.templatePath(`plugin/src/hooks/init.${this._ext}`), this.destinationPath(`src/hooks/init.${this._ext}`), this)
if (this._mocha) {
Expand Down

0 comments on commit 8c5c179

Please sign in to comment.