Skip to content

Commit

Permalink
feat: support filtering input files (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightjack committed Jan 21, 2022
1 parent 2346bb2 commit caa5401
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ While there are tools like [tsc](https://www.typescriptlang.org/docs/handbook/co
## 🚀 Usage

```bash
npx mkdist [rootDir] [--src=src] [--dist=dist] [--format=cjs|esm] [-d|--declaration] [--ext=mjs|js|ts]
npx mkdist [rootDir] [--src=src] [--dist=dist] [--pattern=glob] [--format=cjs|esm] [-d|--declaration] [--ext=mjs|js|ts]
```

## License
Expand Down
3 changes: 2 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function main () {

if (args.help) {
// eslint-disable-next-line no-console
console.log('Usage: npx mkdist [rootDir] [--src=src] [--dist=dist] [--format=cjs|esm] [-d|--declaration] [--ext=mjs|js|ts]')
console.log('Usage: npx mkdist [rootDir] [--src=src] [--dist=dist] [--pattern=glob] [--format=cjs|esm] [-d|--declaration] [--ext=mjs|js|ts]')
process.exit(0)
}

Expand All @@ -15,6 +15,7 @@ async function main () {
srcDir: args.src,
distDir: args.dist,
format: args.format,
pattern: args.pattern,
ext: args.ext,
declaration: Boolean(args.declaration || args.d)
})
Expand Down
3 changes: 2 additions & 1 deletion src/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getDeclarations } from './utils/dts'
export interface MkdistOptions extends LoaderOptions {
rootDir?: string
srcDir?: string
pattern?: string
distDir?: string
cleanDist?: boolean
}
Expand All @@ -25,7 +26,7 @@ export async function mkdist (options: MkdistOptions /* istanbul ignore next */
}

// Scan input files
const filePaths = await globby('**', { absolute: false, cwd: options.srcDir })
const filePaths = await globby(options.pattern || '**', { absolute: false, cwd: options.srcDir })
const files: InputFile[] = filePaths.map((path) => {
const srcPath = resolve(options.srcDir!, path)
return {
Expand Down
11 changes: 11 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ describe('mkdist', () => {
].map(f => resolve(rootDir, f)).sort())
})

it('mkdist (custom glob pattern)', async () => {
const rootDir = resolve(__dirname, 'fixture')
const { writtenFiles } = await mkdist({ rootDir, pattern: 'components/**' })
expect(writtenFiles.sort()).toEqual([
'dist/components/blank.vue',
'dist/components/js.vue',
'dist/components/script-setup-ts.vue',
'dist/components/ts.vue'
].map(f => resolve(rootDir, f)).sort())
})

it('mkdist (emit types)', async () => {
const rootDir = resolve(__dirname, 'fixture')
const { writtenFiles } = await mkdist({ rootDir, declaration: true })
Expand Down

0 comments on commit caa5401

Please sign in to comment.