Skip to content

Commit

Permalink
fix(tsconfig): making tsconfig work
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Mar 29, 2022
1 parent bea5953 commit 6debb4b
Show file tree
Hide file tree
Showing 5 changed files with 576 additions and 636 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,23 @@ npx install-peerdeps --dev @pocket-tools/tsconfig

2. You will see several dependencies were installed. Now, create (or update) a `tsconfig.json` file with the following content:

If you don't already have one the NPM post install script will create it for you.
```json
{
"extends": "@pocket-tools/tsconfig'
"extends": "@pocket-tools/tsconfig",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"exclude": [
"node_modules/",
"dist/"
],
"include": [
"src/**/*.ts",
"src/config"
]
}
```

Concepts are used from https://github.com/Chatie/tsconfig
50 changes: 50 additions & 0 deletions bin/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env node

import fs from 'fs'
import path from 'path'

import pkgUp from 'pkg-up'

import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))

const TSCONFIG_JSON_CONTENT = `{
"extends": "@pocket-tools/tsconfig",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
},
"exclude": [
"node_modules/",
"dist/"
],
"include": [
"src/**/*.ts",
"src/config"
],
}
`

async function main () {
const cwd = path.join(__dirname, '..', '..')
const pkg = await pkgUp({ cwd })
if (!pkg) {
return 0
}
const pkgDir = path.dirname(pkg)

const tsconfigFile = path.join(pkgDir, 'tsconfig.json')

if (!fs.existsSync(tsconfigFile)) {
console.info(`@pocket-tools/tsconfig: auto generated ${tsconfigFile}`)
fs.writeFileSync(tsconfigFile, TSCONFIG_JSON_CONTENT)
}
return 0
}

main()
.then(process.exit)
.catch(e => {
console.error(e)
process.exit(1)
})
Loading

0 comments on commit 6debb4b

Please sign in to comment.