Skip to content

Commit

Permalink
Add github actions & more
Browse files Browse the repository at this point in the history
remove coverage
remove travis
include eslint
  • Loading branch information
pablopunk committed Jan 24, 2021
1 parent 79edd1c commit 5d77269
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 113 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
env:
browser: true
es2021: true
node: true
extends: 'eslint:recommended'
parserOptions:
ecmaVersion: 12
sourceType: module
rules: {}
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: test

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14.x
- run: npm install
- run: npm test
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# 💁🏻 miny

<p align="center">
<a href="https://travis-ci.org/pablopunk/miny"><img src="https://img.shields.io/travis/pablopunk/miny.svg" /> </a>
<a href="https://codecov.io/gh/pablopunk/miny"><img src="https://img.shields.io/codecov/c/github/pablopunk/miny.svg" /> </a>
<a href="https://standardjs.com/"><img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" /> </a>
<a href="https://github.com/pablopunk/miny"><img src="https://img.shields.io/badge/made_with-miny-1eced8.svg" /> </a>
<a href="https://www.npmjs.com/package/miny"><img src="https://img.shields.io/npm/dt/miny.svg" /></a>
Expand Down Expand Up @@ -48,31 +46,29 @@ warning The yes flag has been set. This will automatically answer yes to all que

## Features

### Tests. *optional*
### Tests. _optional_

_miny_ provides [ava](https://github.com/avajs/ava) or [myass](https://github.com/pablopunk/myass) to test your code. By default you get a `test.js` with a test example. Running `npm test` [code coverage tools](#code-coverage).
_miny_ provides [ava](https://github.com/avajs/ava) or [myass](https://github.com/pablopunk/myass) to test your code. By default you get a `test.js` with a test example. Running `npm test` will execute all your tests.

### CI

If you activate [travis-ci](https://travis-ci.org/) for your project, it will automatically run tests for you in every push. The build status is shown by default on your `README.md` file.

### Code coverage. *optional*

With `npm test` or `npm run test-coverage` it will run all tests and you'll get a report of what lines of code are covered by the tests, thanks to [nyc](https://github.com/istanbuljs/nyc) and [codecov](https://codecov.io/). This is very useful to catch some bugs and by default it shows the coverage percentage in your `README.md` after every push (just right after _travis_ runs all tests).
It includes [github actions](https://github.com/features/actions) that will automatically run tests on every push and pull request.

### Code style

Forget about linters. They suck. Use whatever tool you want for writing your code as long as it is valid code. _miny_ comes with `prettier`, which will format the code for you on each commit. Each time you make a commit, `prettier` makes your code beautiful.
_miny_ comes with `prettier` built-in to automatically format your code on every commit, so you can forget about code inconsistencies across your codebase.

It's also useful to use an actual linter for catching some bugs or not used code, so it also includes `eslint` to lint all your code and help you fixing potential bugs.

You can customize the rules it follows by modifying the section `prettier` in `package.json`. By default, it will use _2 spaces as tabs_, remove unnecessary semicolons and convert double quoutes to _single quoutes_. You can add/remove [all of these rules](https://prettier.io/docs/en/options.html).
You can customize the rules it follows by modifying the section `prettier` in `package.json`. By default, it will use _2 spaces as tabs_, remove unnecessary semicolons and convert double quoutes to _single quoutes_. You can add/remove [all of these rules](https://prettier.io/docs/en/options.html). You can also edit the `eslint` rules in `.eslintrc.yml`. Take a look at [eslint docs](https://eslint.org/docs/user-guide/configuring).

### Offline

Also, **_miny_ works offline**!

## Examples

- miny itself was created with miny. Yes.
- _miny_ itself was created with miny. Yes.
- [nuup](https://github.com/pablopunk/nuup)
- [npm-name-exists](https://github.com/pablopunk/npm-name-exists)
- [prepend-url](https://github.com/pablopunk/prepend-url)
Expand Down
16 changes: 3 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "[email protected]"
},
"contributors": [
"Pablo Varela <yo@pablo.pink>"
"Pablo Varela <pablo@pablopunk.com>"
],
"dependencies": {
"camelcase": "^4.1.0",
Expand All @@ -21,9 +21,8 @@
},
"devDependencies": {
"ava": "^0.25.0",
"codecov": "^3.1.0",
"eslint": "^7.18.0",
"husky": "^2.2.0",
"nyc": "^13.1.0",
"prettier": "^1.17.0",
"pretty-quick": "^1.10.0"
},
Expand Down Expand Up @@ -55,20 +54,11 @@
"singleQuote": true,
"tabWidth": 2
},
"nyc": {
"reporter": [
"lcov",
"html",
"text"
]
},
"repository": {
"type": "git",
"url": "https://github.com/pablopunk/miny"
},
"scripts": {
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"test": "npm run test-coverage",
"test-coverage": "nyc ava"
"test": "ava"
}
}
15 changes: 4 additions & 11 deletions sao.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const path = require('path')
const gravatarUrl = require('gravatar-url')
const isValidNpmName = require('is-valid-npm-name')

const testFiles = ['.travis.yml', 'test.js']
const testFiles = ['.github/worflows/test.yml', 'test.js']

module.exports = {
enforceNewFolder: true,
move: {
gitignore: '.gitignore',
npmrc: '.npmrc',
editorconfig: '.editorconfig',
'travis.yml': '.travis.yml'
'workflow.yml': '.github/workflows/test.yml'
},
prompts: {
name: {
Expand Down Expand Up @@ -66,18 +66,11 @@ module.exports = {
'myass (fast and lightweight)',
'none'
]
},
coverage: {
type: 'list',
message: 'Do you want code coverage for the tests?',
choices: ['yes', 'no'],
when: ({ test }) => test !== 'none'
}
},
data({ test, coverage }) {
data({ test }) {
return {
test: test.split(' ')[0],
coverage: coverage === 'yes'
test: test.split(' ')[0]
}
},
gitInit: true,
Expand Down
2 changes: 0 additions & 2 deletions template/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# <%- name %>

<p align="center">
<a href="https://travis-ci.org/<%- githubRepo.replace('https://github.com/', '') %>"><img src="https://img.shields.io/travis/<%- githubRepo.replace('https://github.com/', '') %>.svg" /> </a>
<a href="https://codecov.io/gh/<%- githubRepo.replace('https://github.com/', '') %>"><img src="https://img.shields.io/codecov/c/github/<%- githubRepo.replace('https://github.com/', '') %>.svg" /> </a>
<a href="https://standardjs.com"><img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" /> </a>
<a href="https://github.com/pablopunk/miny"><img src="https://img.shields.io/badge/made_with-miny-1eced8.svg" /> </a>
<a href="https://www.npmjs.com/package/<%- name %>"><img src="https://img.shields.io/npm/dt/<%- name %>.svg" /></a>
Expand Down
2 changes: 0 additions & 2 deletions template/gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
.DS_Store
node_modules
coverage*
.nyc_output
15 changes: 1 addition & 14 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
<% if (test !== 'none') { %>
"<%- test -%>": "*",
<% } %>
<% if (coverage) { %>
"codecov": "*",
"nyc": "*",
<% } %>
"prettier": "*",
"pretty-quick": "*",
"husky": "*"
Expand All @@ -25,11 +21,6 @@
"keywords": [ <%- `${keywords.trim().split(/[, ]+/).map(k => `"${k.trim()}"`).join(', ')}` %> ],
"license": "MIT",
"main": "index.js",
<% if (coverage) { %>
"nyc": {
"reporter": ["lcov", "html", "text"]
},
<% } %>
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
Expand All @@ -45,11 +36,7 @@
"url": "<%- githubRepo %>"
},
"scripts": {
<% if (coverage) { %>
"test-coverage": "nyc <%- test -%>",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"test": "npm run test-coverage"
<% } else if (test !== 'none') { %>
<% if (test !== 'none') { %>
"test": "<%- test -%>"
<% } %>
}
Expand Down
5 changes: 0 additions & 5 deletions template/travis.yml

This file was deleted.

14 changes: 14 additions & 0 deletions template/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: test

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14.x
- run: npm install
- run: npm test
75 changes: 21 additions & 54 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,30 @@ const mock = {

test('Invalid npm name', async t => {
const err = await t.throws(
sao.mockPrompt(
template,
Object.assign({}, mock, { name: 'ñ' })))
t.regex(err.message, /package name had non-URL-safe characters/)
})

test('No code coverage if no tests', async t => {
const stream = await sao.mockPrompt(
template,
mock
sao.mockPrompt(template, Object.assign({}, mock, { name: 'ñ' }))
)

const { answers } = stream.meta
t.is(answers.coverage, undefined)
})

test('Can have tests without code coverage', async t => {
const stream = await sao.mockPrompt(
template,
{
...mock,
test: 'ava',
coverage: 'no'
}
)

const { answers } = stream.meta
t.not(answers.test, 'none')
t.is(answers.coverage, 'no')
t.regex(err.message, /package name had non-URL-safe characters/)
})

test('Defaults', async t => {
const stream = await sao.mockPrompt(
template,
{
name: 'my-project',
email: '[email protected]',
author: 'Pablo Varela',
githubUsername: 'foo',
test: 'none',
coverage: 'yes'
}
)
const stream = await sao.mockPrompt(template, {
name: 'my-project',
email: '[email protected]',
author: 'Pablo Varela',
githubUsername: 'foo',
test: 'none'
})
const { answers } = stream.meta
t.deepEqual(
answers,
{
...mock,
name: 'my-project',
description: 'My new npm module',
githubUsername: 'foo',
website: 'http://foo.com',
githubRepo: 'https://github.com/foo/my-project',
authorImg: 'https://gravatar.com/avatar/fa50aeff0ddd6e63273a068b04353d9d?size=100',
keywords: 'miny my-project',
test: 'none',
coverage: 'yes'
}
)
t.deepEqual(answers, {
...mock,
name: 'my-project',
description: 'My new npm module',
githubUsername: 'foo',
website: 'http://foo.com',
githubRepo: 'https://github.com/foo/my-project',
authorImg:
'https://gravatar.com/avatar/fa50aeff0ddd6e63273a068b04353d9d?size=100',
keywords: 'miny my-project',
test: 'none'
})
})

0 comments on commit 5d77269

Please sign in to comment.