1 | #!/usr/bin/env node
|
2 |
|
3 | const fs = require('fs')
|
4 | const path = require('path')
|
5 |
|
6 | const pkgUp = require('pkg-up')
|
7 |
|
8 | const TSCONFIG_JSON_CONTENT = `{
|
9 | "extends": "@chatie/tsconfig",
|
10 | "compilerOptions": {
|
11 | "outDir": "dist",
|
12 | },
|
13 | "exclude": [
|
14 | "node_modules/",
|
15 | "dist/",
|
16 | "tests/fixtures/",
|
17 | ],
|
18 | "include": [
|
19 | "app/**/*.ts",
|
20 | "bin/*.ts",
|
21 | "bot/**/*.ts",
|
22 | "examples/**/*.ts",
|
23 | "scripts/**/*.ts",
|
24 | "src/**/*.ts",
|
25 | "tests/**/*.spec.ts",
|
26 | ],
|
27 | }
|
28 | `
|
29 |
|
30 | async function main () {
|
31 | const cwd = path.join(__dirname, '..', '..')
|
32 | const pkg = await pkgUp({ cwd })
|
33 | if (!pkg) {
|
34 | return 0
|
35 | }
|
36 | const pkgDir = path.dirname(pkg)
|
37 |
|
38 | const tsconfigFile = path.join(pkgDir, 'tsconfig.json')
|
39 |
|
40 | if (!fs.existsSync(tsconfigFile)) {
|
41 | console.info(`@chatie/tsconfig: auto generated ${tsconfigFile}`)
|
42 | fs.writeFileSync(tsconfigFile, TSCONFIG_JSON_CONTENT)
|
43 | }
|
44 | return 0
|
45 | }
|
46 |
|
47 | main()
|
48 | .then(process.exit)
|
49 | .catch(e => {
|
50 | console.error(e)
|
51 | process.exit(1)
|
52 | })
|