Skip to content

Commit

Permalink
make include array
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hritcu committed Sep 23, 2022
1 parent 4526c24 commit f149302
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/cmd/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ export async function runPipeline(config: Config, docs: CollectedGraphQLDocument

async function collectDocuments(config: Config): Promise<CollectedGraphQLDocument[]> {
// the first step we have to do is grab a list of every file in the source tree
let sourceFiles = await promisify(glob)(config.include)
let sourceFiles = await promisify(glob)(`${config.include.join(',')}`)
if (config.exclude) {
sourceFiles = sourceFiles.filter(
(filepath) => !config.exclude?.find((pattern) => minimatch(filepath, pattern))
)
sourceFiles = sourceFiles.filter((filepath) => {
return !config.exclude?.some((pattern) => minimatch(filepath, pattern))
})
}

// the list of documents we found
Expand Down
23 changes: 14 additions & 9 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Config {
apiUrl?: string
schemaPath?: string
persistedQueryPath?: string
include: string
include: string[]
exclude?: string[]
scalars?: ConfigFile['scalars']
framework: 'kit' | 'svelte' = 'kit'
Expand Down Expand Up @@ -133,8 +133,12 @@ ${
this.schemaPath = schemaPath
this.apiUrl = apiUrl
this.filepath = filepath
this.include = include
this.exclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]) : []
this.include = include ? (Array.isArray(include) ? include : [include]) : []

console.log('this.include', this.include)
this.exclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]) : undefined
console.log('this.exclude', this.exclude)

this.framework = framework
this.module = module
this.projectRoot = path.dirname(
Expand Down Expand Up @@ -444,13 +448,14 @@ ${
// deal with any relative imports from compiled assets
filepath = this.resolveRelative(filepath)

// if the filepath doesn't match the include we're done
if (!minimatch(filepath, path.join(this.projectRoot, this.include))) {
return false
// if the filepath does match the include, but does match exclude, ignore it
if (this.include.some((pattern) => minimatch(filepath, pattern))) {
// if there is an exclude, make sure the path doesn't match
if (!this.exclude?.some((pattern) => minimatch(filepath, pattern))) {
return false
}
}

// if there is an exclude, make sure the path doesn't match
return !this.exclude ? true : !this.exclude.find((pattern) => minimatch(filepath, pattern))
return true
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type ConfigFile = {
* for inline queries to work
* @default `src/** /*.{svelte,graphql,gql,ts,js}`
*/
include?: string
include?: string | string[]

/**
* A pattern used to remove matches from files that satisfy the include value
Expand Down
14 changes: 6 additions & 8 deletions src/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ export default function ({
return true
}

// if the filepath does not match the include, ignore it
if (!minimatch(filepath, path.join(process.cwd(), config.include))) {
return false
// if the filepath does match the include, but does match exclude, ignore it
if (config.include.some((pattern) => minimatch(filepath, pattern))) {
if (!config.exclude?.some((pattern) => minimatch(filepath, pattern))) {
return false
}
}

// make sure that the file doesn't match the exclude
return (
!config.exclude ||
!config.exclude?.find((pattern) => minimatch(filepath, pattern))
)
return true
},
async run() {
// load the config file
Expand Down

0 comments on commit f149302

Please sign in to comment.