From e1c1e89c97ac60bfabf871958586b93cae8bb51c Mon Sep 17 00:00:00 2001 From: James Warwood Date: Tue, 7 May 2024 10:27:56 +0100 Subject: [PATCH] feat: Add support for preserving original filename casing with --filename-case=keep --- packages/cli/README.md | 2 +- packages/cli/src/__snapshots__/index.test.ts.snap | 10 ++++++++++ packages/cli/src/index.test.ts | 1 + packages/cli/src/index.ts | 2 +- packages/cli/src/util.ts | 2 ++ website/pages/docs/options.mdx | 3 ++- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/cli/README.md b/packages/cli/README.md index c03a3fad..be27d376 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -22,7 +22,7 @@ Options: -d, --out-dir output files into a directory --ignore-existing ignore existing files when used with --out-dir --ext specify a custom file extension (default: "js") - --filename-case specify filename case ("pascal", "kebab", "camel", "snake") (default: "pascal") + --filename-case specify filename case ("pascal", "kebab", "camel", "snake", "keep") (default: "pascal") --icon use "1em" as width and height --native add react-native support with react-native-svg --memo add React.memo into the result component diff --git a/packages/cli/src/__snapshots__/index.test.ts.snap b/packages/cli/src/__snapshots__/index.test.ts.snap index 58f7d7d4..87ff0e27 100644 --- a/packages/cli/src/__snapshots__/index.test.ts.snap +++ b/packages/cli/src/__snapshots__/index.test.ts.snap @@ -129,6 +129,16 @@ exports[`cli should support different filename cases with directory output: --fi ] `; +exports[`cli should support different filename cases with directory output: --filename-case=keep 1`] = ` +[ + "PascalCase.js", + "camelCase.js", + "index.js", + "kebab-case.js", + "multiple---dashes.js", +] +`; + exports[`cli should support different filename cases with directory output: --filename-case=pascal 1`] = ` [ "CamelCase.js", diff --git a/packages/cli/src/index.test.ts b/packages/cli/src/index.test.ts index 7cd5879f..30d29aa1 100644 --- a/packages/cli/src/index.test.ts +++ b/packages/cli/src/index.test.ts @@ -155,6 +155,7 @@ describe('cli', () => { [2, '--filename-case=pascal'], [3, '--filename-case=kebab'], [4, '--filename-case=snake'], + [5, '--filename-case=keep'], ])( 'should support different filename cases with directory output', async (index, args) => { diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index ae685ccf..1cde7275 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -103,7 +103,7 @@ program .option('--ext ', 'specify a custom file extension (default: "js")') .option( '--filename-case ', - 'specify filename case ("pascal", "kebab", "camel", "snake") (default: "pascal")', + 'specify filename case ("pascal", "kebab", "camel", "snake", "keep") (default: "pascal")', ) .option( '--icon [size]', diff --git a/packages/cli/src/util.ts b/packages/cli/src/util.ts index cc54aed0..a9cfcca9 100644 --- a/packages/cli/src/util.ts +++ b/packages/cli/src/util.ts @@ -24,6 +24,8 @@ export function transformFilename( return camelCase(filename, { pascalCase: true }) case 'snake': return snakeCase(filename) + case 'keep': + return filename default: throw new Error(`Unknown --filename-case ${filenameCase}`) } diff --git a/website/pages/docs/options.mdx b/website/pages/docs/options.mdx index 6befea2c..141dc2c2 100644 --- a/website/pages/docs/options.mdx +++ b/website/pages/docs/options.mdx @@ -253,7 +253,8 @@ When used with `--out-dir`, it ignores already existing files. ## Filename case -Specify a custom filename case. Possible values: `pascal` for PascalCase, `kebab` for kebab-case, `camel` for camelCase, or `snake` for snake_case. +Specify a custom filename case. Possible values: `pascal` for PascalCase, `kebab` for kebab-case, `camel` for camelCase, `snake` for snake_case, or `keep` +to preserve original filename casing. | Default | CLI Override | API Override | | -------- | ----------------- | ---------------------- |