Skip to content

Commit c9a8cb1

Browse files
committed
feat: use hygen to easily generate new packages
1 parent 478f5f0 commit c9a8cb1

File tree

8 files changed

+113
-0
lines changed

8 files changed

+113
-0
lines changed

Diff for: .hygen.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const pkg = require('./package.json');
2+
3+
const flatten = arr => [].concat.apply([], arr);
4+
5+
const onlyKeys = (keys, obj) => flatten(keys)
6+
.reduce((r, k) => { r[k] = obj[k]; return r; }, {});
7+
8+
const omitKeys = (keys, obj) => {
9+
const filteredKeys = Object.keys(obj)
10+
.filter(k => keys.includes(k));
11+
return onlyKeys(filteredKeys, obj);
12+
};
13+
14+
module.exports = {
15+
localsDefaults: {
16+
baseName: '@' + pkg.name,
17+
license: pkg.license,
18+
publishAccess: 'public',
19+
repository: pkg.repository,
20+
devDependencies: pkg.devDependencies,
21+
},
22+
helpers: {
23+
obj: {
24+
onlyKeys,
25+
omitKeys,
26+
},
27+
},
28+
};

Diff for: _templates/package/new/jest.config.js.t

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
to: packages/<%= name %>/jest.config.js
3+
---
4+
module.exports = require('../../jest.project')({ dirname: __dirname });

Diff for: _templates/package/new/package.json.t

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
to: packages/<%= name %>/package.json
3+
---
4+
<%- JSON.stringify({
5+
"name": baseName ? baseName + '/' + name : name,
6+
"license": license,
7+
"version": "0.0.0",
8+
"main": "dist/index",
9+
"repository": {
10+
...repository,
11+
directory: 'packages/' + name
12+
},
13+
"publishConfig": {
14+
"access": publishAccess
15+
},
16+
"scripts": {
17+
"clean:dist": "rimraf dist",
18+
"compile": "tsc -b tsconfig.build.json",
19+
"build": "yarn clean:dist && yarn compile",
20+
"test": "jest --coverage",
21+
"test:watch": "jest --coverage --watch",
22+
"test:prod": "yarn test -- --no-cache",
23+
"report-coverage": "cat ./coverage/lcov.info | coveralls",
24+
25+
"prepublishOnly": "yarn build"
26+
},
27+
"devDependencies": h.obj.onlyKeys([
28+
'@types/jest',
29+
'@types/node',
30+
'coveralls',
31+
'jest',
32+
'rimraf',
33+
'ts-jest',
34+
'ts-node',
35+
'typescript'
36+
], devDependencies),
37+
}, 0, 2) %>

Diff for: _templates/package/new/src/index.ejs.t

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
to: 'packages/<%= name %>/src/index.ts'
3+
---
4+
export class DummyClass {
5+
6+
}

Diff for: _templates/package/new/test/index.test.ejs.t

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
to: 'packages/<%= name %>/test/index.test.ts'
3+
---
4+
import { DummyClass } from '../src/index';
5+
6+
describe('Dummy test', () => {
7+
it('works if true is truthy', () => {
8+
expect(true).toBeTruthy();
9+
});
10+
11+
it('DummyClass is instantiable', () => {
12+
expect(new DummyClass()).toBeInstanceOf(DummyClass);
13+
});
14+
});

Diff for: _templates/package/new/tsconfig.build.json.t

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
to: packages/<%= name %>/tsconfig.build.json
3+
---
4+
{
5+
"extends": "../../tsconfig.build.json",
6+
7+
"compilerOptions": {
8+
"outDir": "./dist"
9+
},
10+
11+
"include": [
12+
"src/**/*"
13+
]
14+
}

Diff for: _templates/package/new/tsconfig.json.t

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
to: packages/<%= name %>/tsconfig.json
3+
---
4+
{
5+
"extends": "../../tsconfig.json",
6+
7+
"compilerOptions": {
8+
}
9+
}

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
]
4747
},
4848
"devDependencies": {
49+
"@binier/hygen": "^5.2.0",
4950
"@commitlint/cli": "^8.3.5",
5051
"@commitlint/config-conventional": "^8.3.4",
5152
"@types/jest": "^25.2.1",

0 commit comments

Comments
 (0)