feat: release examples
MODIFY
.circleci/config.yml
.circleci/config.yml
@@ -141,33 +141,33 @@ workflows:
version: 2
create-dxcli:
jobs:
- # - lint
- # - node-latest-base
- # - node-latest-single
- # - node-latest-plugin
- # - node-latest-multi
- # - node-8-base
- # - node-8-single
- # - node-8-plugin
- # - node-8-multi
- # - release:
- # context: org-global
- # filters:
- # branches: {only: master}
- # requires:
- # - lint
- # - node-latest-base
- # - node-latest-single
- # - node-latest-plugin
- # - node-latest-multi
- # - node-8-base
- # - node-8-single
- # - node-8-plugin
- # - node-8-multi
+ - lint
+ - node-latest-base
+ - node-latest-single
+ - node-latest-plugin
+ - node-latest-multi
+ - node-8-base
+ - node-8-single
+ - node-8-plugin
+ - node-8-multi
+ - release:
+ context: org-global
+ filters:
+ branches: {only: master}
+ requires:
+ - lint
+ - node-latest-base
+ - node-latest-single
+ - node-latest-plugin
+ - node-latest-multi
+ - node-8-base
+ - node-8-single
+ - node-8-plugin
+ - node-8-multi
- example-multi-cli-typescript: &example_workflow
context: org-global
requires:
- release
- # - example-multi-cli-javascript: *example_workflow
- # - example-single-cli-typescript: *example_workflow
- # - example-single-cli-javascript: *example_workflow
+ - example-multi-cli-javascript: *example_workflow
+ - example-single-cli-typescript: *example_workflow
+ - example-single-cli-javascript: *example_workflow

MODIFY
.circleci/release_example
.circleci/release_example
#!/usr/bin/env node
const sh = require('shelljs')
+const fs = require('fs-extra')
sh.set('-ev')
+const {version} = fs.readJSONSync('package.json')
const example = process.env.CIRCLE_JOB
const [, type,, format] = example.split('-')
-console.dir({type, format})
-
const options = format === 'typescript' ?
'--options=typescript,mocha,semantic-release' :
'--options=mocha,semantic-release'
sh.cd(`examples/${example}`)
-sh.exec(`yarn create dxcli ${type} --defaults ${options}`)
+sh.exec('git fetch')
+sh.exec('git checkout master')
+sh.exec('git pull --rebase origin master')
+
+sh.rm('-rf', [
+'.circleci',
+'.editorconfig',
+'.eslintignore',
+'.eslintrc',
+'.gitattributes',
+'.gitignore',
+'appveyor.yml',
+'bin',
+'package-scripts.js',
+'README.md',
+'src',
+'test',
+'tsconfig.json',
+'tslint.json',
+'yarn.lock'
+].join(' '))
+
+const pjson = fs.readJSONSync('package.json')
+fs.outputJSONSync('package.json', {
+ name: `@dxcli/${example}`,
+ repository: `dxcli/${example}`,
+ author: pjson.author,
+ version: pjson.version,
+})
+
+sh.exec(`yarn create dxcli ${type} --force --defaults ${options}`)
+sh.exec('git add .')
+sh.exec(`git commit -m "fix: create-dxcli ${version}"`)
+sh.exec('git push')
+sh.cd('../..')
+sh.exec(`git add examples/${example}`)
+sh.exec(`git commit -m "chore: ${example} updated [ci-skip]`)
+
+let retries = 4
+function push() {
+ try {
+ sh.exec('git pull --rebase origin master')
+ sh.exec('git push')
+ } catch (err) {
+ retries--
+ if (retries > 0) return push()
+ throw err
+ }
+}

MODIFY
.eslintignore
.eslintignore
/lib
/tmp
/templates
+/examples

ADD
src/app_command.ts
+import Command, {flags} from '@dxcli/command'
+import {createEnv} from 'yeoman-environment'
+
+export default abstract class AppCommand extends Command {
+ static flags: flags.Input = {
+ defaults: flags.boolean({description: 'use defaults for every setting'}),
+ options: flags.string({description: '(typescript|semantic-release|mocha)'}),
+ force: flags.boolean({description: 'overwrite existing files'}),
+ }
+ static args = [
+ {name: 'path', required: false}
+ ]
+
+ abstract type: string
+
+ async run() {
+ const env = createEnv()
+
+ env.register(
+ require.resolve('./generators/app'),
+ 'dxcli:app'
+ )
+
+ const options = this.flags.options ? this.flags.options.split(',') : []
+
+ await env.run('dxcli:app', {type: this.type, path: this.args.path, options, defaults: this.flags.defaults, force: this.flags.force})
+ }
+}

MODIFY
src/commands/base.ts
src/commands/base.ts
-import Command, {flags} from '@dxcli/command'
-import {createEnv} from 'yeoman-environment'
+import AppCommand from '../app_command'
-export default class extends Command {
- static flags: flags.Input = {
- defaults: flags.boolean({description: 'use defaults for every setting'}),
- options: flags.string({description: '(typescript|semantic-release|mocha)'}),
- }
- static args = [
- {name: 'path', required: false}
- ]
-
- async run() {
- const env = createEnv()
-
- env.register(
- require.resolve('../generators/app'),
- 'dxcli:app'
- )
-
- const options = this.flags.options ? this.flags.options.split(',') : []
-
- await env.run('dxcli:app', {type: 'base', path: this.args.path, options, defaults: this.flags.defaults})
- }
+export default class extends AppCommand {
+ type = 'base'
}

MODIFY
src/commands/multi.ts
src/commands/multi.ts
-import Command, {flags} from '@dxcli/command'
-import {createEnv} from 'yeoman-environment'
+import AppCommand from '../app_command'
-export default class extends Command {
- static flags: flags.Input = {
- defaults: flags.boolean({description: 'use defaults for every setting'}),
- options: flags.string({description: '(typescript|semantic-release|mocha)'}),
- }
- static args = [
- {name: 'path', required: false}
- ]
-
- async run() {
- const env = createEnv()
-
- env.register(
- require.resolve('../generators/app'),
- 'dxcli:app'
- )
-
- const options = this.flags.options ? this.flags.options.split(',') : []
-
- await env.run('dxcli:app', {type: 'multi', path: this.args.path, options, defaults: this.flags.defaults})
- }
+export default class extends AppCommand {
+ type = 'multi'
}

MODIFY
src/commands/plugin.ts
src/commands/plugin.ts
-import Command, {flags} from '@dxcli/command'
-import {createEnv} from 'yeoman-environment'
+import AppCommand from '../app_command'
-export default class extends Command {
- static flags: flags.Input = {
- defaults: flags.boolean({description: 'use defaults for every setting'}),
- options: flags.string({description: '(typescript|semantic-release|mocha)'}),
- }
- static args = [
- {name: 'path', required: false}
- ]
-
- async run() {
- const env = createEnv()
-
- env.register(
- require.resolve('../generators/app'),
- 'dxcli:app'
- )
-
- const options = this.flags.options ? this.flags.options.split(',') : []
-
- await env.run('dxcli:app', {type: 'plugin', path: this.args.path, options, defaults: this.flags.defaults})
- }
+export default class extends AppCommand {
+ type = 'plugin'
}

MODIFY
src/commands/single.ts
src/commands/single.ts
-import Command, {flags} from '@dxcli/command'
-import {createEnv} from 'yeoman-environment'
+import AppCommand from '../app_command'
-export default class extends Command {
- static flags: flags.Input = {
- defaults: flags.boolean({description: 'use defaults for every setting'}),
- options: flags.string({description: '(typescript|semantic-release|mocha)'}),
- }
- static args = [
- {name: 'path', required: false}
- ]
-
- async run() {
- const env = createEnv()
-
- env.register(
- require.resolve('../generators/app'),
- 'dxcli:app'
- )
-
- const options = this.flags.options ? this.flags.options.split(',') : []
-
- await env.run('dxcli:app', {type: 'single', path: this.args.path, options, defaults: this.flags.defaults})
- }
+export default class extends AppCommand {
+ type = 'single'
}

feat: release examples