Skip to content

Commit

Permalink
Glob is an option instead of a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulioRandall committed May 19, 2024
1 parent 8708e27 commit b34ea88
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A simple tool for adding parsable metadata as comments within Svelte components.

## Made to be Plundered

This library is made to be plundered for whatever you like as long as you adhere to the permissive MIT license found within.
Do whatever you like as long as you adhere to the permissive MIT license found within.

## Example

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Simple tool for adding parsable metadata as comments within Svelte components.",
"type": "module",
"license": "MIT",
"version": "0.7.0",
"version": "0.8.0",
"engines": {
"node": ">=18"
},
Expand Down
13 changes: 7 additions & 6 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const defaultGlobOptions = {
nodir: true,
}

export default (glob = '**/*.svelte', options = {}) => {
export default (options = {}) => {
try {
options = parseOptions(options)
return parseTree(glob, options)
return parseTree(options)
} catch (e) {
console.error(`[P23] Unable to parse with glob '${glob}'`)
console.error(e)
Expand All @@ -21,19 +21,20 @@ export default (glob = '**/*.svelte', options = {}) => {
const parseOptions = (options) => {
return {
prefix: 'p23',
glob: '**/*.svelte',
globOptions: defaultGlobOptions,
...options,
}
}

const parseTree = (glob, options) => {
return listFiles(glob, options) //
const parseTree = (options) => {
return listFiles(options) //
.map(fileInfo)
.map((f) => appendFileNodes(f, options))
}

const listFiles = (glob, options) => {
return globSync(glob, options.globOptions).sort()
const listFiles = (options) => {
return globSync(options.glob, options.globOptions).sort()
}

const fileInfo = (filePath) => {
Expand Down
31 changes: 16 additions & 15 deletions src/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const generateFileFields = (file) => {
}
}

const parseToUnix = (f) => {
return parse(f).map((m) => {
const parseToUnix = (file) => {
return parse({ glob: file }).map((m) => {
m.relPath = upath.toUnix(m.relPath)
m.absPath = upath.toUnix(m.absPath)
return m
Expand All @@ -26,7 +26,7 @@ describe('parser.js', () => {
describe('parse', () => {
test('Parses no docs', () => {
const file = createSvelteFilePath('NoDocs')
const metadata = parse(file)
const metadata = parse({ glob: file })

expect(metadata).toEqual([
{
Expand All @@ -38,7 +38,7 @@ describe('parser.js', () => {

test('Parses non-nested single line node', () => {
const file = createSvelteFilePath('JsLine_NonNested')
const metadata = parse(file)
const metadata = parse({ glob: file })

expect(metadata).toEqual([
{
Expand All @@ -52,7 +52,7 @@ describe('parser.js', () => {

test('Parses multiple lines in series that represent a single node', () => {
const file = createSvelteFilePath('JsLine_MultiLine')
const metadata = parse(file)
const metadata = parse({ glob: file })

expect(metadata).toEqual([
{
Expand All @@ -67,7 +67,7 @@ describe('parser.js', () => {

test('Parses non-nested single line node (lowercase p23)', () => {
const file = createSvelteFilePath('JsLine_NonNested_Lowercase')
const metadata = parse(file)
const metadata = parse({ glob: file })

expect(metadata).toEqual([
{
Expand All @@ -81,7 +81,7 @@ describe('parser.js', () => {

test('Parses multiple non-nested single line nodes', () => {
const file = createSvelteFilePath('JsLine_NonNested_Multiple')
const metadata = parse(file)
const metadata = parse({ glob: file })

expect(metadata).toEqual([
{
Expand All @@ -97,7 +97,7 @@ describe('parser.js', () => {

test('Parses nested single line node', () => {
const file = createSvelteFilePath('JsLine_Nested')
const metadata = parse(file)
const metadata = parse({ glob: file })

expect(metadata).toEqual([
{
Expand All @@ -113,7 +113,7 @@ describe('parser.js', () => {

test('Parses nested single line node 2', () => {
const file = createSvelteFilePath('JsLine_Nested_2')
const metadata = parse(file)
const metadata = parse({ glob: file })

expect(metadata).toEqual([
{
Expand All @@ -131,7 +131,7 @@ describe('parser.js', () => {

test('Parses comprehensive set of nested and non-nested nodes', () => {
const file = createSvelteFilePath('JsLine_Complex')
const metadata = parse(file)
const metadata = parse({ glob: file })

expect(metadata).toEqual([
{
Expand All @@ -153,7 +153,7 @@ describe('parser.js', () => {

test('Parses directory', () => {
const dir = upath.join(`${testdataDir}/dir`)
const metadata = parse(dir + '/**/*.svelte')
const metadata = parse({ glob: dir + '/**/*.svelte' })

expect(metadata).toEqual([
{
Expand All @@ -177,7 +177,8 @@ describe('parser.js', () => {

test('Parses with option', () => {
const file = createSvelteFilePath('JsLine_Option_Prefix')
const metadata = parse(file, {
const metadata = parse({
glob: file,
prefix: 'my_custom_prefix',
})

Expand All @@ -193,7 +194,7 @@ describe('parser.js', () => {

test('Parses with HTML docs', () => {
const file = createSvelteFilePath('htmlDocs')
const metadata = parse(file)
const metadata = parse({ glob: file })

expect(metadata).toEqual([
{
Expand All @@ -220,7 +221,7 @@ describe('parser.js', () => {

test('Parses block comment on a single line', () => {
const file = createSvelteFilePath('JsBlock_Line')
const metadata = parse(file)
const metadata = parse({ glob: file })

expect(metadata).toEqual([
{
Expand All @@ -234,7 +235,7 @@ describe('parser.js', () => {

test('Parses block comment on multiple lines', () => {
const file = createSvelteFilePath('JsBlock_Lines')
const metadata = parse(file)
const metadata = parse({ glob: file })

expect(metadata).toEqual([
{
Expand Down

0 comments on commit b34ea88

Please sign in to comment.