Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow -i or --include argument for custom include files #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ const args = process.argv.slice(2)
const argsProjectIndex = args.findIndex(arg => ['-p', '--project'].includes(arg)) // prettier-ignore
const argsProjectValue = argsProjectIndex !== -1 ? args[argsProjectIndex + 1] : undefined // prettier-ignore

const files = args.filter(file => /\.(ts|tsx)$/.test(file))
const argsIncludeIndex = args.findIndex(arg => ['-i', '--include'].includes(arg)) // prettier-ignore
const argsIncludeValue = argsIncludeIndex !== -1 ? args[argsIncludeIndex + 1] : undefined // prettier-ignore
let argsIncludeValueArray = []

const files = args.filter(file => /\.(ts|tsx)$/.test(file) && argsIncludeValue !== file)
if (files.length === 0) {
process.exit(0)
}

const remainingArgsToForward = args.slice().filter(arg => !files.includes(arg))

let remainingArgsToForward = args.slice().filter(arg => !files.includes(arg))
if (argsProjectIndex !== -1) {
remainingArgsToForward.splice(argsProjectIndex, 2)
remainingArgsToForward = remainingArgsToForward.filter(args => !['-p', '--project', argsProjectValue].includes(args))
}
if (argsIncludeIndex !== -1) {
remainingArgsToForward = remainingArgsToForward.filter(args => !['-i', '--include', argsIncludeValue].includes(args))
argsIncludeValueArray = argsIncludeValue.split(',')
}

// Load existing config
Expand All @@ -36,7 +43,7 @@ const tmpTsconfig = {
skipLibCheck: true,
},
files,
include: [],
include: argsIncludeValueArray
}
fs.writeFileSync(tmpTsconfigPath, JSON.stringify(tmpTsconfig, null, 2))

Expand Down