Skip to content

Commit a27dc50

Browse files
committed
feat: program creation, files emitting, diagnostics logging and formatting
0 parents  commit a27dc50

21 files changed

+5560
-0
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Build output
2+
dist
3+
4+
# Environment variables file
5+
.env
6+
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Dependencies directory
15+
node_modules/
16+
17+
# Output of 'npm pack'
18+
*.tgz
19+
20+
# Yarn Integrity file
21+
.yarn-integrity
22+
23+
# Optional npm cache directory
24+
.npm
25+
26+
# OS files
27+
.DS_Store
28+
Thumbs.db
29+
[Dd]esktop.ini
30+
31+
# Vscode
32+
.vscode/*
33+
!.vscode/settings.json
34+
!.vscode/tasks.json
35+
!.vscode/launch.json
36+
!.vscode/extensions.json

.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

.prettierrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"printWidth": 120,
3+
"tabWidth": 2,
4+
"useTabs": true,
5+
"semi": false,
6+
"singleQuote": true,
7+
"trailingComma": "es5",
8+
"bracketSpacing": true,
9+
"arrowParens": "always",
10+
"proseWrap": "preserve",
11+
"endOfLine": "lf"
12+
}

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"esbenp.prettier-vscode",
4+
"ms-vscode.vscode-typescript-tslint-plugin"
5+
]
6+
}

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"npm.packageManager": "yarn",
4+
"prettier.requireConfig": true,
5+
"files.associations": {
6+
"tslint.json": "jsonc"
7+
}
8+
}

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.

README.MD

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# tsc-prog
2+
3+
Build your TypeScript projects programmatically.
4+
5+
## Get started
6+
7+
```bash
8+
npm i -D tsc-prog
9+
yarn add -D tsc-prog
10+
```
11+
12+
_Tsc-prog has no dependency. You just need typescript as a peer dependency._
13+
14+
## Usage
15+
16+
### You simply need to build
17+
18+
Use **`tsc.build`**.
19+
20+
```js
21+
const tsc = require('tsc-prog')
22+
23+
tsc.build({
24+
basePath: __dirname,
25+
configFilePath: 'tsconfig.json',
26+
compilerOptions: {
27+
rootDir: 'src',
28+
outDir: 'dist',
29+
declaration: true,
30+
skipLibCheck: true,
31+
},
32+
include: ['src/**/*.ts'],
33+
exclude: ['**/*.test.ts', '**/*.spec.ts']
34+
})
35+
```
36+
37+
You can have a look at the parameters **[here](./src/interfaces.ts)**.
38+
39+
### You need more access
40+
41+
The `tsc.build` function is made of the two following steps, which you can have access to :
42+
43+
- [Program](https://github.com/microsoft/TypeScript/wiki/Architectural-Overview#data-structures) creation with **`tsc.createProgramFromConfig`**.
44+
- Emitting files from program with **`tsc.emit`**.
45+
46+
```js
47+
const tsc = require('tsc-prog')
48+
49+
// Create the program
50+
const program = tsc.createProgramFromConfig({
51+
basePath: process.cwd(),
52+
configFilePath: 'tsconfig.json'
53+
})
54+
55+
// Do what you want with the program
56+
57+
// Actually compile typescript files
58+
tsc.emit(program, { betterDiagnostics: true })
59+
```

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'],
19+
rules: {
20+
'header-max-length': [2, 'always', 100],
21+
},
22+
}
23+
24+
module.exports = config

jest.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/** @type {jest.InitialOptions} */
2+
const config = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
testPathIgnorePatterns: ['/node_modules/', '/__fixtures__/'],
6+
globals: {
7+
'ts-jest': {
8+
diagnostics: {
9+
warnOnly: true, // https://kulshekhar.github.io/ts-jest/user/config/diagnostics
10+
},
11+
},
12+
},
13+
}
14+
15+
module.exports = config

0 commit comments

Comments
 (0)