This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(command.collect): use custom parser to unify lib & cli options t…
…ype, allow array of transformer, and fix type exports (package.json)
- Loading branch information
1 parent
ac9ec40
commit 4855c76
Showing
16 changed files
with
135 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,37 @@ | ||
import type { | ||
CliCollectOptions, | ||
CollectOptions, | ||
KeyTransformFn | ||
} from '$commands/collect/collect.types'; | ||
import {KeyTransformCli} from '$commands/collect/collect.types'; | ||
import { | ||
camelCasify, | ||
dollarArgify, | ||
} from '$utils/transformer'; | ||
|
||
export const MAPPING_FILENAME = 'routes.json'; | ||
export const UTIL_ROUTE_FILENAME = 'route'; | ||
|
||
export function camelCasify(str: string) { | ||
return str | ||
.trim() | ||
.replace(/\[([a-zA-Z_-]+)\]/g, function(match, p1) { | ||
return match.replace(/\[[a-zA-Z_-]+\]/g, `-${p1}`); | ||
}) | ||
.replace(/[-_\s]+./g, function(match) { | ||
return match.replace(/[-_\s]/g, '').toUpperCase(); | ||
}) | ||
.replace(/^(.)/, function(match) { | ||
return match.toLowerCase(); | ||
}); | ||
} | ||
|
||
export const defaultCollectOptions: CollectOptions = { | ||
inDir: 'src/routes', | ||
extensions: ['.svelte'], | ||
ignorePatterns: [/^_/], | ||
output: true, | ||
outDir: 'src/generated/routing', | ||
typescript: true, | ||
keyTransform: camelCasify, | ||
keyTransform: [dollarArgify, camelCasify], | ||
verbose: false, | ||
depth: Infinity, | ||
dirkey: '__dir', | ||
utils: true, | ||
}; | ||
|
||
export const defaultCliCollectOptions: CliCollectOptions = { | ||
...defaultCollectOptions, | ||
extensions: defaultCollectOptions.extensions.join(','), | ||
ignorePatterns: defaultCollectOptions.ignorePatterns.map((pattern) => (pattern instanceof RegExp) ? pattern.source : pattern).join(','), | ||
depth: 'Infinity', | ||
keyTransform: 'camelCase', | ||
}; | ||
export const defaultKeyTransformCli: KeyTransformCli[] = [ | ||
KeyTransformCli.camelCase, | ||
KeyTransformCli.dollarArg, | ||
]; | ||
|
||
export const keyTransformCliToFunc: Record<CliCollectOptions['keyTransform'], (str) => string> = { | ||
camelCase: camelCasify, | ||
export const keyTransformCliToFunc: Record<KeyTransformCli, KeyTransformFn> = { | ||
none: (str) => str, | ||
camelCase: camelCasify, | ||
dollarArg: dollarArgify, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.