Skip to content

Commit

Permalink
feat: support custom globby options
Browse files Browse the repository at this point in the history
Default globby options:

```js
{
  dot: true,
  onlyFiles: false,
  gitignore: true,
}
```
  • Loading branch information
fjc0k committed Jul 2, 2019
1 parent 8855b85 commit 9d1b443
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ You can use markers (`@index()` and `@endindex`) to tell where the index should
function index(
patterns: Patterns,
codeGenerator: CodeGenerator,
globbyOptions?: GlobbyOptions,
): string {
// generate index
}
Expand Down Expand Up @@ -115,6 +116,10 @@ function index(

See [all changeCase methods](https://github.com/blakeembrey/change-case#usage).

- **GlobbyOptions**

See [https://github.com/sindresorhus/globby#options](https://github.com/sindresorhus/globby#options).

## Indentation

You can make an index indented by indenting the start marker, e.g.
Expand Down
12 changes: 10 additions & 2 deletions src/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs'
import * as changeCase from 'change-case'
import * as vscode from 'vscode'
import { castArray, noop } from 'vtils'
import globby from 'globby'
import globby, { GlobbyOptions } from 'globby'

type ChangeCase = typeof changeCase

Expand Down Expand Up @@ -41,6 +41,7 @@ interface Marker {
end: number,
patterns: Pattern[],
codeGenerator: CodeGenerator,
globbyOptions: GlobbyOptions,
}

export default class Generator {
Expand All @@ -58,9 +59,12 @@ export default class Generator {
const paths = await globby(
marker.patterns,
{
dot: true,
onlyFiles: false,
gitignore: true,
...(marker.globbyOptions || {}),
cwd: currentDir,
absolute: true,
onlyFiles: false,
},
)
paths.sort(
Expand Down Expand Up @@ -144,13 +148,16 @@ export default class Generator {
const indent = startMatch[1].match(/^\s*/)![0]
let patterns: Pattern[] = []
let codeGenerator: CodeGenerator = noop
let globbyOptions: GlobbyOptions = {}
// eslint-disable-next-line no-inner-declarations
function setParams(
localPatterns: Pattern | Pattern[],
localCodeGenerator: CodeGenerator,
localGlobbyOptions: GlobbyOptions,
) {
patterns = castArray(localPatterns)
codeGenerator = localCodeGenerator
globbyOptions = localGlobbyOptions
}
try {
eval(`${setParams.name}(${startMatch[2]})`)
Expand All @@ -160,6 +167,7 @@ export default class Generator {
end: end,
patterns: patterns,
codeGenerator: codeGenerator,
globbyOptions: globbyOptions,
})
} catch (e) {
vscode.window.showWarningMessage(
Expand Down

0 comments on commit 9d1b443

Please sign in to comment.