Skip to content

Commit

Permalink
feat: release examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 27, 2018
1 parent 46293ca commit 2f901ca
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 121 deletions.
52 changes: 26 additions & 26 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
54 changes: 51 additions & 3 deletions .circleci/release_example
Original file line number Diff line number Diff line change
@@ -1,17 +1,65 @@
#!/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
}
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/lib
/tmp
/templates
/examples
28 changes: 28 additions & 0 deletions src/app_command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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})
}
}
26 changes: 3 additions & 23 deletions src/commands/base.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
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'
}
26 changes: 3 additions & 23 deletions src/commands/multi.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
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'
}
26 changes: 3 additions & 23 deletions src/commands/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
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'
}
26 changes: 3 additions & 23 deletions src/commands/single.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
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'
}

0 comments on commit 2f901ca

Please sign in to comment.