Skip to content

Commit 20c4eb9

Browse files
committed
chore: extract tools config in their own file, build script, tune warnings
1 parent 68d7d86 commit 20c4eb9

17 files changed

+1714
-1214
lines changed

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Tells Github UI to allow comments in json files
2+
*.json linguist-language=JSON-with-Comments
3+
4+
# Tells Github to not take js config root files into acccount for language statistics
5+
/*.js linguist-detectable=false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Build output
22
dist
3+
temp
34

45
# Environment variables file
56
.env

.huskyrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @see https://github.com/typicode/husky/blob/master/DOCS.md
3+
* @see https://git-scm.com/docs/githooks
4+
*
5+
* @type {{hooks: {[key in GitHook]?: string}}}
6+
*
7+
* @typedef {'pre-commit' | 'prepare-commit-msg' | 'commit-msg' | 'post-commit' | 'pre-rebase' | 'post-checkout' | 'post-merge' | 'pre-push' | 'applypatch-msg' | 'pre-applypatch' | 'post-applypatch' | 'post-rewrite' | 'post-index-change'} GitHook
8+
*/
9+
const config = {
10+
hooks: {
11+
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
12+
},
13+
}
14+
15+
module.exports = config

README.MD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Reflet 💫
22

3+
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)
4+
35
Reflet is a set of modules using the power of **[decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)** to **complement** already useful nodejs libraries.
46

57
Reflet helps you **organize** your app in a more **declarative** way.

build.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { join } from 'path'
2+
import { build } from 'tsc-prog'
3+
import { Extractor, ExtractorConfig, IConfigFile, ExtractorLogLevel } from '@microsoft/api-extractor'
4+
5+
const basePath = process.cwd()
6+
const rootDir = 'src'
7+
const outDir = 'dist'
8+
const tmpDir = 'temp'
9+
10+
build({
11+
basePath,
12+
configFilePath: 'tsconfig.json',
13+
compilerOptions: {
14+
rootDir,
15+
outDir,
16+
// Emit declaration files in a temp folder so api-extractor can bundle them in the next step
17+
declaration: true,
18+
declarationDir: tmpDir,
19+
declarationMap: true,
20+
skipLibCheck: true,
21+
},
22+
include: [`${rootDir}/**/*`],
23+
exclude: ['**/__tests__', '**/test.ts', '**/*.test.ts', '**/*.spec.ts', 'node_modules'],
24+
clean: { outDir: true, declarationDir: true },
25+
})
26+
27+
bundleDefinitions('public')
28+
29+
/**
30+
* @see https://api-extractor.com/pages/overview/demo_rollup/
31+
*/
32+
function bundleDefinitions(release: '' | 'beta' | 'public' = '') {
33+
const logLevel = {
34+
none: { logLevel: 'none' as ExtractorLogLevel },
35+
warning: { logLevel: 'warning' as ExtractorLogLevel },
36+
error: { logLevel: 'error' as ExtractorLogLevel },
37+
}
38+
39+
const dtsDistFilePath = '<projectFolder>/dist/index.d.ts'
40+
41+
// https://api-extractor.com/pages/commands/config_file/
42+
const configObject: IConfigFile = {
43+
projectFolder: basePath,
44+
mainEntryPointFilePath: '<projectFolder>/temp/index.d.ts',
45+
compiler: { tsconfigFilePath: '<projectFolder>/tsconfig.json' },
46+
dtsRollup: {
47+
enabled: true,
48+
untrimmedFilePath: release === '' ? dtsDistFilePath : '',
49+
betaTrimmedFilePath: release === 'beta' ? dtsDistFilePath : '',
50+
publicTrimmedFilePath: release === 'public' ? dtsDistFilePath : '',
51+
omitTrimmingComments: false,
52+
},
53+
messages: {
54+
compilerMessageReporting: {
55+
default: logLevel.error,
56+
},
57+
extractorMessageReporting: {
58+
default: logLevel.error,
59+
'ae-forgotten-export': logLevel.warning,
60+
'ae-unresolved-inheritdoc-reference': logLevel.none,
61+
'ae-internal-missing-underscore': logLevel.none,
62+
},
63+
tsdocMessageReporting: {
64+
default: logLevel.warning,
65+
'tsdoc-undefined-tag': logLevel.none,
66+
'tsdoc-unsupported-tag': logLevel.none,
67+
},
68+
},
69+
}
70+
71+
const config = ExtractorConfig.prepare({
72+
configObject,
73+
configObjectFullPath: undefined,
74+
packageJsonFullPath: join(basePath, 'package.json'),
75+
})
76+
77+
const { succeeded, errorCount, warningCount } = Extractor.invoke(config, {
78+
localBuild: true,
79+
showVerboseMessages: true,
80+
})
81+
82+
if (succeeded) {
83+
console.log(`API Extractor succeeded with ${warningCount} warnings`)
84+
} else {
85+
console.error(`API Extractor failed with ${errorCount} errors and ${warningCount} warnings`)
86+
process.exit(1)
87+
}
88+
}

commitlint.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @see https://commitlint.js.org/#/reference-configuration
3+
*
4+
* @type {Config}
5+
*
6+
* @typedef Config
7+
* @property {string[]=} extends Resolveable ids to commitlint configurations to extend.
8+
* @property {string=} parserPreset Resolveable id to conventional-changelog parser preset to import and use.
9+
* @property {string=} formatter Resolveable id to package, from node_modules, which formats the output.
10+
* @property {{[key in RuleName]?: Rule | ((...args) => Rule)}=} rules Rules to check against.
11+
* @property {((message: string) => boolean)[]=} ignores Functions that return true if commitlint should ignore the given message.
12+
* @property {boolean=} defaultIgnores Whether commitlint uses the default ignore rules.
13+
*
14+
* @typedef {[0 | 1 | 2, 'always' | 'never', number | string | string[]]} Rule
15+
* @typedef {'body-leading-blank' | 'body-max-length' | 'body-min-length' | 'footer-leading-blank' | 'footer-max-length' | 'footer-max-line-length' | 'footer-min-length' | 'header-case' | 'header-full-stop' | 'header-max-length' | 'header-min-length' | 'references-empty' | 'scope-enum' | 'scope-case' | 'scope-empty' | 'scope-max-length' | 'scope-min-length' | 'subject-case' | 'subject-empty' | 'subject-full-stop' | 'subject-max-length' | 'subject-min-length' | 'type-enum' | 'type-case' | 'type-empty' | 'type-max-length' | 'type-min-length' | 'signed-off-by'} RuleName
16+
*/
17+
const config = {
18+
extends: ['@commitlint/config-conventional', '@commitlint/config-lerna-scopes'],
19+
rules: {
20+
'header-max-length': [2, 'always', 100],
21+
},
22+
}
23+
24+
module.exports = config

express/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Jeremy Bensimon
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.

express/jest.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

express/package.json

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
"version": "1.0.0",
44
"author": "Jeremy Bensimon",
55
"license": "MIT",
6-
"repository": {
7-
"type": "git",
8-
"url": "https://github.com/jeremyben/reflet",
9-
"directory": "express"
10-
},
6+
"repository": "https://github.com/jeremyben/reflet/tree/master/express",
7+
"keywords": [
8+
"express",
9+
"decorators",
10+
"typescript",
11+
"framework",
12+
"router",
13+
"app",
14+
"nest"
15+
],
1116
"main": "dist/index.js",
1217
"types": "dist/index.d.ts",
1318
"files": [
@@ -16,19 +21,19 @@
1621
"publishConfig": {
1722
"access": "public"
1823
},
24+
"engines": {
25+
"node": ">=8.10"
26+
},
27+
"engineStrict": true,
1928
"peerDependencies": {
20-
"reflect-metadata": "^0.1.13",
29+
"@types/express": "^4.16.0",
2130
"express": "^4.16.0",
22-
"express-session": "^1.15.0",
23-
"@types/express": "^4.16.0"
24-
},
25-
"devDependencies": {
26-
"@reflet/monorepo": "0.0.0"
31+
"reflect-metadata": "^0.1.13"
2732
},
2833
"scripts": {
29-
"build": "rimraf dist && tsc -p tsconfig.build.json",
34+
"build": "ts-node -T ../build.ts",
3035
"prepublishOnly": "yarn run build",
31-
"test": "jest",
32-
"test:watch": "jest --watch --verbose false"
36+
"test": "jest --config ../jest.config.js",
37+
"test:watch": "jest --config ../jest.config.js --watch --verbose false"
3338
}
3439
}

express/tsconfig.build.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

express/tsconfig.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
{
2-
"extends": "../tsconfig.base.json",
3-
"compilerOptions": {
4-
"rootDir": "src",
5-
"outDir": "dist"
6-
}
2+
"extends": "../tsconfig.json"
73
}

jest.config.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
const { join } = require('path')
2+
const rootDir = process.cwd()
23

3-
// https://kulshekhar.github.io/ts-jest/user/config/
4-
module.exports = {
4+
/** @type {jest.InitialOptions} */
5+
const config = {
6+
rootDir,
57
preset: 'ts-jest',
68
testEnvironment: 'node',
7-
8-
// https://jestjs.io/docs/en/configuration.html#testpathignorepatterns-array-string
9-
testPathIgnorePatterns: ['/node_modules/', '/__tests__/shared/'],
10-
9+
testPathIgnorePatterns: ['/node_modules/', '/__tests__/shared/', '/dist/'],
1110
// https://jestjs.io/docs/en/configuration#setupfiles-array
1211
setupFiles: [join(__dirname, 'testing', 'eachfile-setup.ts')],
13-
1412
globals: {
1513
'ts-jest': {
1614
diagnostics: {
17-
// https://kulshekhar.github.io/ts-jest/user/config/diagnostics
1815
warnOnly: true,
1916
},
2017
},
2118
},
2219
}
20+
21+
module.exports = config

lerna.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "independent",
3+
"npmClient": "yarn",
4+
"useWorkspaces": true,
5+
"command": {
6+
"version": {
7+
"allowBranch": "master",
8+
"conventionalCommits": true,
9+
"push": false,
10+
"message": "chore: release"
11+
}
12+
}
13+
}

package.json

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,45 @@
11
{
22
"name": "@reflet/monorepo",
33
"version": "0.0.0",
4-
"private": true,
54
"author": "Jeremy Bensimon",
6-
"repository": "github:jeremyben/reflet",
75
"license": "MIT",
6+
"private": true,
7+
"repository": "github:jeremyben/reflet",
88
"workspaces": [
9-
".",
109
"express"
1110
],
12-
"lerna": {
13-
"version": "independent",
14-
"npmClient": "yarn",
15-
"useWorkspaces": true,
16-
"command": {
17-
"version": {
18-
"allowBranch": "master"
19-
}
20-
}
21-
},
22-
"husky": {
23-
"hooks": {
24-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
25-
}
26-
},
27-
"commitlint": {
28-
"extends": [
29-
"@commitlint/config-conventional",
30-
"@commitlint/config-lerna-scopes"
31-
]
32-
},
3311
"engines": {
3412
"node": ">=8.10"
3513
},
14+
"engineStrict": true,
3615
"scripts": {
16+
"bootstrap": "yarn install --force",
3717
"test": "lerna run test --stream",
38-
"build": "lerna run build --stream"
18+
"build": "lerna run build --stream",
19+
"release": "lerna version",
20+
"npm": "lerna publish from-package"
3921
},
4022
"devDependencies": {
41-
"@commitlint/cli": "^8.0.0",
42-
"@commitlint/config-conventional": "^8.0.0",
43-
"@commitlint/config-lerna-scopes": "^8.0.0",
44-
"@types/express": "^4.17.0",
45-
"@types/jest": "^24.0.15",
23+
"@commitlint/cli": "^8.1.0",
24+
"@commitlint/config-conventional": "^8.1.0",
25+
"@commitlint/config-lerna-scopes": "^8.1.0",
26+
"@microsoft/api-extractor": "^7.3.8",
27+
"@types/express": "^4.17.1",
28+
"@types/jest": "^24.0.18",
4629
"@types/node": "^10",
47-
"@types/supertest": "^2.0.7",
30+
"@types/supertest": "^2.0.8",
4831
"express": "^4.17.1",
49-
"husky": "^2.7.0",
50-
"jest": "^24.8.0",
51-
"lerna": "^3.15.0",
32+
"husky": "^3.0.4",
33+
"jest": "^24.9.0",
34+
"lerna": "^3.16.4",
5235
"reflect-metadata": "^0.1.13",
53-
"rimraf": "^2.6.3",
5436
"supertest": "^4.0.2",
5537
"ts-jest": "^24.0.2",
56-
"ts-node-dev": "^1.0.0-pre.40",
57-
"tslint": "^5.18.0",
38+
"ts-node": "^8.3.0",
39+
"tsc-prog": "^2.0.2",
40+
"tslint": "^5.19.0",
5841
"tslint-config-prettier": "^1.18.0",
59-
"typescript": "^3.5.2",
60-
"typescript-tslint-plugin": "^0.5.2"
42+
"typescript": "^3.5.3",
43+
"typescript-tslint-plugin": "^0.5.4"
6144
}
6245
}

0 commit comments

Comments
 (0)