-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
69 changed files
with
247 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {flags} from '@dxcli/command' | ||
|
||
import Base from '../command_base' | ||
|
||
export interface Options { | ||
name: string | ||
defaults?: boolean | ||
force?: boolean | ||
} | ||
|
||
export default abstract class AppCommand extends Base { | ||
static flags: flags.Input = { | ||
defaults: flags.boolean({description: 'use defaults for every setting'}), | ||
force: flags.boolean({description: 'overwrite existing files'}), | ||
} | ||
static args = [ | ||
{name: 'name', description: 'name of command', required: true} | ||
] | ||
|
||
async run () { | ||
await super.generate('command', { | ||
name: this.args.name, | ||
defaults: this.flags.defaults, | ||
force: this.flags.force | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// tslint:disable no-floating-promises | ||
// tslint:disable no-console | ||
|
||
import * as _ from 'lodash' | ||
import * as path from 'path' | ||
import * as Generator from 'yeoman-generator' | ||
import yosay = require('yosay') | ||
|
||
import {Options} from '../../commands/command' | ||
|
||
const {version} = require('../../../package.json') | ||
|
||
class CommandGenerator extends Generator { | ||
pjson: { | ||
name: string | ||
devDependencies: {[name: string]: string} | ||
} | ||
|
||
get _path () { return this.options.name.split(':').join('/') } | ||
get _ts () { return this.pjson.devDependencies.typescript } | ||
get _ext () { return this._ts ? 'ts' : 'js' } | ||
get _mocha () { return this.pjson.devDependencies.mocha } | ||
|
||
constructor (args: any, public options: Options) { | ||
super(args, options) | ||
} | ||
|
||
async prompting () { | ||
this.pjson = this.fs.readJSON('package.json') | ||
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.fs.copyTpl(this.templatePath(`command.${this._ext}.ejs`), this.destinationPath(`src/commands/${this._path}.${this._ext}`), {...this.options, _}) | ||
// this.fs.copyTpl(this.templatePath(`plugin/src/hooks/init.${this._ext}`), this.destinationPath(`src/hooks/init.${this._ext}`), this) | ||
if (this._mocha) { | ||
// this.fs.copyTpl(this.templatePath(`plugin/test/hooks/init.test.${this._ext}`), this.destinationPath(`test/hooks/init.test.${this._ext}`), this) | ||
this.fs.copyTpl(this.templatePath(`command.test.${this._ext}.ejs`), this.destinationPath(`test/commands/${this._path}.test.${this._ext}`), {...this.options, _}) | ||
} | ||
// this.fs.writeJSON(this.destinationPath('./package.json'), this.pjson) | ||
} | ||
} | ||
|
||
export = CommandGenerator |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const {Command, flags} = require('@dxcli/command') | ||
const {cli} = require('cli-ux') | ||
<%_ const klass = _.upperFirst(_.camelCase(name.split(':').slice(-1).join(':') + ':command')) _%> | ||
|
||
class <%- klass %> extends Command { | ||
async run () { | ||
const name = this.flags.name || 'world' | ||
cli.log(`hello ${name} from <%- name %>!`) | ||
} | ||
} | ||
|
||
<%- klass %>.flags = { | ||
name: flags.string({char: 'n', description: 'name to print'}), | ||
} | ||
|
||
module.exports = <%- klass %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const {expect, test} = require('@dxcli/test') | ||
|
||
const command = '<%- name %>' | ||
|
||
describe(command, () => { | ||
test | ||
.stdout() | ||
.command([command]) | ||
.do(ctx => expect(ctx.stdout).to.equal('hello world from <%- name %>!\n')) | ||
.it() | ||
|
||
test | ||
.stdout() | ||
.command([command, '--name', 'jeff']) | ||
.do(ctx => expect(ctx.stdout).to.equal('hello jeff from <%- name %>!\n')) | ||
.it() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {expect, test} from '@dxcli/test' | ||
|
||
const command = '<%- name %>' | ||
|
||
describe(command, () => { | ||
test | ||
.stdout() | ||
.command([command]) | ||
.do(ctx => expect(ctx.stdout).to.contain('hello world from <%- name %>!')) | ||
.it() | ||
|
||
test | ||
.stdout() | ||
.command([command, '--name', 'jeff']) | ||
.do(ctx => expect(ctx.stdout).to.contain('hello jeff from <%- name %>!')) | ||
.it() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {Command, flags} from '@dxcli/command' | ||
import cli from 'cli-ux' | ||
|
||
export default class <%- _.upperFirst(_.camelCase(name)) %> extends Command { | ||
static flags = { | ||
name: flags.string({char: 'n', description: 'name to print'}) | ||
} | ||
|
||
async run () { | ||
const name = this.flags.name || 'world' | ||
cli.log(`hello ${name} from <%- name %>!`) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
const run = require('../../run') | ||
|
||
describe('base', () => { | ||
run('base', 'everything') | ||
.it() | ||
}) | ||
require('../../run')(module.filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
const run = require('../../run') | ||
|
||
describe('base', () => { | ||
run('base', 'mocha') | ||
.it() | ||
}) | ||
require('../../run')(module.filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
const run = require('../../run') | ||
|
||
describe('base', () => { | ||
run('base', 'plain') | ||
.it() | ||
}) | ||
require('../../run')(module.filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
const run = require('../../run') | ||
|
||
describe('base', () => { | ||
run('base', 'typescript') | ||
.it() | ||
}) | ||
require('../../run')(module.filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('../../run')(module.filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('../../run')(module.filename) |
Oops, something went wrong.