Skip to content

Commit 62b6055

Browse files
committed
feature(@putout/plugin-github) add
1 parent ac3d6ca commit 62b6055

21 files changed

+407
-43
lines changed

.github/workflows/nodejs.yml

+30-37
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
11
name: Node CI
2-
3-
on: [push, pull_request]
4-
2+
on:
3+
- push
4+
- pull_request
55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
9-
108
strategy:
119
matrix:
12-
node-version: [14.x, 15.x]
13-
10+
node-version:
11+
- 14.x
12+
- 16.x
1413
steps:
15-
- uses: actions/checkout@v1
16-
- name: Use Node.js ${{ matrix.node-version }}
17-
uses: actions/setup-node@v1
18-
with:
19-
node-version: ${{ matrix.node-version }}
20-
21-
- name: Install Redrun
22-
run:
23-
npm i redrun -g
24-
25-
- name: Install
26-
run:
27-
npm install
28-
29-
- name: Bootstrap
30-
run:
31-
redrun bootstrap
32-
33-
- name: Lint
34-
run:
35-
redrun lint
36-
37-
- name: Coverage
38-
run:
39-
redrun coverage report
40-
41-
- name: Coveralls
42-
uses: coverallsapp/github-action@master
43-
with:
44-
github-token: ${{ secrets.GITHUB_TOKEN }}
14+
- uses: actions/checkout@v1
15+
- name: Use Node.js ${{ matrix.node-version }}
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
20+
- name: Install Redrun
21+
run: npm i redrun -g
22+
23+
- name: Install
24+
run: npm install
25+
26+
- name: Bootstrap
27+
run: redrun bootstrap
28+
29+
- name: Lint
30+
run: redrun lint
31+
32+
- name: Coverage
33+
run: redrun coverage report
4534

35+
- name: Coveralls
36+
uses: coverallsapp/github-action@master
37+
with:
38+
github-token: ${{ secrets.GITHUB_TOKEN }}

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,7 @@ Next packages not bundled with `putout` but can be installed separately.
12181218
| [`@putout/plugin-cloudcmd`](/packages/plugin-cloudcmd) | [![npm](https://img.shields.io/npm/v/@putout/plugin-cloudcmd.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-cloudcmd) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-cloudcmd)](https://david-dm.org/coderaiser/putout?path=packages/plugin-cloudcmd) |
12191219
| [`@putout/plugin-postcss`](/packages/plugin-postcss) | [![npm](https://img.shields.io/npm/v/@putout/plugin-postcss.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-postcss) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-postcss)](https://david-dm.org/coderaiser/putout?path=packages/plugin-postcss) |
12201220
| [`@putout/plugin-convert-any-to-primitive`](/packages/plugin-convert-any-to-primitive) | [![npm](https://img.shields.io/npm/v/@putout/plugin-convert-any-to-primitive.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-convert-any-to-primitive) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-convert-any-to-primitive)](https://david-dm.org/coderaiser/putout?path=packages/plugin-convert-any-to-primitive) |
1221+
| [`@putout/plugin-travis`](/packages/plugin-travis) | [![npm](https://img.shields.io/npm/v/@putout/plugin-travis.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-travis) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-travis)](https://david-dm.org/coderaiser/putout?path=packages/plugin-travis) |
12211222

12221223
### Other
12231224

@@ -1241,7 +1242,7 @@ Next packages not bundled with `putout` but can be installed separately.
12411242
| [`@putout/plugin-gitignore`](/packages/plugin-gitignore) | [![npm](https://img.shields.io/npm/v/@putout/plugin-gitignore.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-gitignore) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-gitignore)](https://david-dm.org/coderaiser/putout?path=packages/plugin-gitignore) |
12421243
| [`@putout/plugin-npmignore`](/packages/plugin-npmignore) | [![npm](https://img.shields.io/npm/v/@putout/plugin-npmignore.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-npmignore) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-npmignore)](https://david-dm.org/coderaiser/putout?path=packages/plugin-npmignore) |
12431244
| [`@putout/plugin-browserlist`](/packages/plugin-browserlist) | [![npm](https://img.shields.io/npm/v/@putout/plugin-browserlist.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-browserlist) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-browserlist)](https://david-dm.org/coderaiser/putout?path=packages/plugin-browserlist) |
1244-
| [`@putout/plugin-travis`](/packages/plugin-travis) | [![npm](https://img.shields.io/npm/v/@putout/plugin-travis.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-travis) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-travis)](https://david-dm.org/coderaiser/putout?path=packages/plugin-travis) |
1245+
| [`@putout/plugin-github`](/packages/plugin-github) | [![npm](https://img.shields.io/npm/v/@putout/plugin-github.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-github) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-github)](https://david-dm.org/coderaiser/putout?path=packages/plugin-github) |
12451246
| [`@putout/plugin-regexp`](/packages/plugin-regexp) | [![npm](https://img.shields.io/npm/v/@putout/plugin-regexp.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-regexp) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-regexp)](https://david-dm.org/coderaiser/putout?path=packages/plugin-regexp) |
12461247
| [`@putout/plugin-nodejs`](/packages/plugin-nodejs) | [![npm](https://img.shields.io/npm/v/@putout/plugin-nodejs.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-nodejs) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-nodejs)](https://david-dm.org/coderaiser/putout?path=packages/plugin-nodejs) |
12471248

packages/plugin-github/.eslintrc.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": [
3+
"plugin:node/recommended",
4+
"plugin:putout/recommended"
5+
],
6+
"plugins": [
7+
"node",
8+
"putout"
9+
]
10+
}

packages/plugin-github/.madrun.mjs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {run} from 'madrun';
2+
3+
export default {
4+
'test': () => `tape 'test/*.js' 'lib/**/*.spec.js'`,
5+
'watch:test': async () => `nodemon -w lib -x ${await run('test')}`,
6+
'lint': () => `putout .`,
7+
'fresh:lint': () => run('lint', '--fresh'),
8+
'lint:fresh': () => run('lint', '--fresh'),
9+
'fix:lint': () => run('lint', '--fix'),
10+
'coverage': async () => `c8 ${await run('test')}`,
11+
'report': () => 'c8 report --reporter=lcov',
12+
};
13+

packages/plugin-github/.npmignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.*
2+
*.spec.js
3+
test
4+
fixture
5+
yarn-error.log
6+
7+
coverage

packages/plugin-github/.nycrc.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/*.spec.*",
6+
"**/fixture",
7+
"test",
8+
".*.*"
9+
],
10+
"branches": 100,
11+
"lines": 100,
12+
"functions": 100,
13+
"statements": 100
14+
}

packages/plugin-github/.putout.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"match": {
3+
"lib/index.js": {
4+
"remove-useless-spread/object": "off"
5+
}
6+
}
7+
}

packages/plugin-github/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) coderaiser
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/plugin-github/README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# @putout/plugin-github [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]
2+
3+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-github.svg?style=flat&longCache=true
4+
[NPMURL]: https://npmjs.org/package/@putout/plugin-github"npm"
5+
6+
[DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/plugin-github
7+
[DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-github
8+
9+
`putout` plugin helps with `putout` plugins development.
10+
11+
## Install
12+
13+
```
14+
npm i @putout/plugin-github -D
15+
```
16+
17+
## Rules
18+
19+
```json
20+
{
21+
"rules": {
22+
"github/set-node-versions": "on"
23+
}
24+
}
25+
```
26+
27+
## Set node versions
28+
29+
```diff
30+
jobs:
31+
build:
32+
33+
runs-on: ubuntu-latest
34+
35+
strategy:
36+
matrix:
37+
- node-version: [14.x, 15.x]
38+
+ node-version: [14.x, 16.x]
39+
```
40+
41+
## License
42+
43+
MIT
44+

packages/plugin-github/lib/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
const getRule = (a) => ({
4+
[a]: require(`./${a}`),
5+
});
6+
7+
module.exports.rules = {
8+
...getRule('set-node-versions'),
9+
};
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
__putout_processor_json({
2+
"jobs": {
3+
"build": {
4+
"runs-on": "ubuntu-latest",
5+
"strategy": {
6+
"matrix": {
7+
"node-version": ['14.x', '16.x']
8+
}
9+
}
10+
}
11+
}
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
__putout_processor_json({
2+
"jobs": {
3+
"build": {
4+
"runs-on": "ubuntu-latest",
5+
"strategy": {
6+
"matrix": {
7+
"node-version": [
8+
"14.x",
9+
"15.x"
10+
]
11+
}
12+
}
13+
}
14+
}
15+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
__putout_processor_json({
2+
"name": "Node CI",
3+
"on": [
4+
"push",
5+
"pull_request"
6+
],
7+
"jobs": {
8+
"build": {
9+
"runs-on": "ubuntu-latest",
10+
"steps": [
11+
{
12+
"uses": "actions/checkout@v1"
13+
},
14+
{
15+
"name": "Use Node.js ${{ matrix.node-version }}",
16+
"uses": "actions/setup-node@v1",
17+
"with": {
18+
"node-version": "${{ matrix.node-version }}"
19+
}
20+
},
21+
{
22+
"name": "Install Redrun",
23+
"run": "npm i redrun -g"
24+
},
25+
{
26+
"name": "Install",
27+
"run": "npm install"
28+
},
29+
{
30+
"name": "Bootstrap",
31+
"run": "redrun bootstrap"
32+
},
33+
{
34+
"name": "Lint",
35+
"run": "redrun lint"
36+
},
37+
{
38+
"name": "Coverage",
39+
"run": "redrun coverage report"
40+
},
41+
{
42+
"name": "Coveralls",
43+
"uses": "coverallsapp/github-action@master",
44+
"with": {
45+
"github-token": "${{ secrets.GITHUB_TOKEN }}"
46+
}
47+
}
48+
]
49+
}
50+
}
51+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
3+
const {operator, template} = require('putout');
4+
const {replaceWith} = require('putout').operator;
5+
const deepEqual = require('fast-deep-equal');
6+
7+
const {
8+
traverse,
9+
getTemplateValues,
10+
} = operator;
11+
12+
const nodeVersions = [
13+
'14.x',
14+
'16.x',
15+
];
16+
17+
const nodeVersionsNode = template.ast(`[
18+
"14.x",
19+
"16.x"
20+
]`);
21+
22+
const {parse} = JSON;
23+
24+
module.exports.report = () => 'Latest version of node is missing';
25+
26+
module.exports.fix = (path) => {
27+
replaceWith(path, nodeVersionsNode);
28+
};
29+
30+
module.exports.traverse = ({push}) => ({
31+
'__putout_processor_json(__a)'(path) {
32+
const {__a} = getTemplateValues(path.node, '__putout_processor_json(__a)');
33+
traverse(__a, {
34+
'__object'(path) {
35+
const nodeVersionPath = path.get('properties.0');
36+
const {value} = nodeVersionPath.get('key').node;
37+
38+
if (value === 'node-version') {
39+
const versions = parse(String(path))['node-version'];
40+
41+
if (versions === '${{ matrix.node-version }}')
42+
return;
43+
44+
if (deepEqual(versions, nodeVersions))
45+
return;
46+
47+
push(nodeVersionPath.get('value'));
48+
}
49+
},
50+
});
51+
52+
return path;
53+
},
54+
});
55+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const test = require('@putout/test')(__dirname, {
4+
'github/set-node-version': require('.'),
5+
});
6+
7+
test('plugin-github: set node versions: report', (t) => {
8+
t.report('github', 'Latest version of node is missing');
9+
});
10+
11+
test('plugin-github: set node versions: transform', (t) => {
12+
t.transform('github');
13+
t.end();
14+
});
15+
16+
test('plugin-github: set node versions: no transform: no version', (t) => {
17+
t.noTransform('no-version');
18+
t.end();
19+
});
20+

0 commit comments

Comments
 (0)