Skip to content

Commit

Permalink
fix: upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
dword-design committed May 29, 2020
1 parent 5dba1e7 commit bb63c89
Show file tree
Hide file tree
Showing 7 changed files with 2,588 additions and 8,470 deletions.
57 changes: 39 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,76 @@
name: build

on:
push:
branches:
- '**'

- "**"
jobs:
cancel-existing:
runs-on: ubuntu-latest
steps:
- uses: rokroskar/workflow-run-cleanup-action@v0.2.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test:
runs-on: ${{ matrix.os }}
needs: cancel-existing
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
node: [10, 12]
os:
- macos-latest
- windows-latest
- ubuntu-latest
node:
- 10
- 12
exclude:
- os: macos-latest
node: 10
- os: windows-latest
node: 10
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- if: "!github.event.repository.private || (matrix.os == 'ubuntu-latest' &&
matrix.node == 12)"
uses: actions/checkout@v2
- if: "!github.event.repository.private || (matrix.os == 'ubuntu-latest' &&
matrix.node == 12)"
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: yarn --frozen-lockfile
- run: yarn test
- if: "!github.event.repository.private || (matrix.os == 'ubuntu-latest' &&
matrix.node == 12)"
run: |-
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
yarn --frozen-lockfile
- if: "!github.event.repository.private || (matrix.os == 'ubuntu-latest' &&
matrix.node == 12)"
run: yarn test
- name: Push changed files
run: yarn dw-ci push-changed-files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ secrets.GITHUB_REPOSITORY }}
- name: Coveralls
run: yarn dw-ci coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
COVERALLS_GIT_COMMIT: ${{ github.sha }}
COVERALLS_GIT_BRANCH: ${{ github.ref }}

release:
needs: test
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v1
with:
node-version: 12
- run: yarn --frozen-lockfile
- name: Push changed files
run: yarn dw-ci push-changed-files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ secrets.GITHUB_REPOSITORY }}
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
yarn semantic-release
run: yarn semantic-release
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.DS_Store
/.babelrc.json
/.cz.json
/.editorconfig
/.env
/.env.json
/.eslintrc.json
/.nyc_output
/.releaserc.json
/.test.env.json
/.vscode
/coverage
/dist
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<!-- BADGES/ -->
[![NPM version](https://img.shields.io/npm/v/make-cli.svg)](https://npmjs.org/package/make-cli)
![Linux macOS Windows compatible](https://img.shields.io/badge/os-linux%20%7C%C2%A0macos%20%7C%C2%A0windows-blue)

[![Build status](https://img.shields.io/github/workflow/status/dword-design/make-cli/build)](https://github.com/dword-design/make-cli/actions)
[![Coverage status](https://img.shields.io/coveralls/dword-design/make-cli)](https://coveralls.io/github/dword-design/make-cli)
[![Dependency status](https://img.shields.io/david/dword-design/make-cli)](https://david-dm.org/dword-design/make-cli)
Expand All @@ -19,7 +18,7 @@ Build command line tools declaratively with a configuration object and a single
<!-- /DESCRIPTION -->

<!-- INSTALL/ -->
# Install
## Install

```bash
# NPM
Expand Down Expand Up @@ -92,7 +91,7 @@ $ my-cli --version
For more information see the [Commander.js](https://www.npmjs.com/package/commander) website.

<!-- LICENSE/ -->
# License
## License

Unless stated otherwise all works are:

Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@
],
"scripts": {
"commit": "base commit",
"depgraph": "base depgraph",
"dev": "base dev",
"prepare": "base prepare",
"prepublishOnly": "base prepublishOnly",
"release": "base release",
"test": "base test"
},
"dependencies": {
"@dword-design/functions": "^2.2.2",
"commander": "^4.0.0"
},
"devDependencies": {
"@dword-design/base": "^6.0.0",
"@dword-design/functions": "^2.2.2",
"execa": "^4.0.0",
"fs-extra": "^9.0.0",
"with-local-tmp-dir": "^2.0.4"
},
"publishConfig": {
"access": "public"
}
}
53 changes: 37 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
const applyOptions = (program, options = []) => options.forEach(({ name, description, defaultValue }) => program.option(name, description, defaultValue))
import { compact, join } from '@dword-design/functions'

export default ({ version, name, usage, arguments: args, options, action, commands = [], defaultCommandName } = {}) => {
const applyOptions = (program, options = []) =>
options.forEach(({ name, description, defaultValue }) =>
program.option(name, description, defaultValue)
)

export default ({
version,
name,
usage,
arguments: args,
options,
action,
commands = [],
defaultCommandName,
} = {}) => {
const program = require('commander')

if (version !== undefined) {
Expand All @@ -27,22 +40,30 @@ export default ({ version, name, usage, arguments: args, options, action, comman
}

commands.forEach(
({ name, arguments: args, description, options, handler }) => applyOptions(
program
.command(`${name}${args !== '' ? ` ${args}` : ''}`)
.description(description)
.action(handler),
options,
),
({
name: commandName,
arguments: commandArgs,
description,
options: commandOptions,
handler,
}) =>
applyOptions(
program
.command([commandName, commandArgs] |> compact |> join(' '))
.description(description)
.action(handler),
commandOptions
)
)

if (defaultCommandName !== undefined && process.argv.length <= 2) {
return commands.find(({ name }) => name === defaultCommandName).handler()
} else {
if (commands.length > 0) {
program.on('command:*', () => program.help())
}

return program.parse(process.argv)
return commands
.find(command => command.name === defaultCommandName)
.handler()
}
if (commands.length > 0) {
program.on('command:*', () => program.help())
}

return program.parse(process.argv)
}
Loading

0 comments on commit bb63c89

Please sign in to comment.