diff --git a/README.md b/README.md index c3d1d53..87c9e0f 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ Available options: | --version | type | default | output the version number | | --------------- | ----------------------- | ---------------------------------------- | ---------------------------------------------------------------------------- | | fileName | stirng | my-icons | file name of the generated file | -| delimiter | CAMEL, KEBAP, SNAKE | SNAKE | delimiter which is used to generate the types and name properties | +| delimiter | CAMEL, KEBAP, SNAKE | CAMEL | delimiter which is used to generate the types and name properties | | svgoConfig | string or config object | check help command - to large to display | a path to your svgoConfiguration JSON file or an inline configuration object | | srcFiles | string | "/\*.svg" | input files matching the given filename pattern | | outputDirectory | string | "./dist" | name of the output directory | diff --git a/package.json b/package.json index d756944..c66f492 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "start-object:snake": "ts-node ./src/bin/svg-to-ts.ts --convertionType object -s './inputfilesBis/*.svg' -d SNAKE", "start-object:camel": "ts-node ./src/bin/svg-to-ts.ts --convertionType object -s './inputfilesBis/*.svg' -d CAMEL", "start-object:multiple-source": "ts-node ./src/bin/svg-to-ts.ts --convertionType object -s './inputfiles/*.svg' -s './inputfilesBis/*.svg'", - "start-object:custom": "ts-node ./src/bin/svg-to-ts.ts --convertionType object -s './inputfiles/*.svg' -o ./dist --objectName awesomeIcons -f icons -d CAMEL", + "start-object:custom": "ts-node ./src/bin/svg-to-ts.ts --convertionType object -s './inputfiles/*.svg' -o ./dist --objectName awesomeIcons -f icons", + "start-object:default-export": "ts-node ./src/bin/svg-to-ts.ts --convertionType object -s './inputfiles/*.svg' -o ./dist --objectName default", "start-constants": "ts-node ./src/bin/svg-to-ts.ts --convertionType constants -s './inputfiles/*.svg'", "start-constants:svgconfig": "ts-node ./src/bin/svg-to-ts.ts --convertionType constants -s './inputfiles/*.svg' --svgoConfig ./svgo-test.config.json", "start-constants:regex": "ts-node ./src/bin/svg-to-ts.ts --convertionType constants -s './inputfilesRegex/**/*.svg'", diff --git a/src/lib/converters/object.converter.ts b/src/lib/converters/object.converter.ts index 72b35a1..491ac18 100644 --- a/src/lib/converters/object.converter.ts +++ b/src/lib/converters/object.converter.ts @@ -10,7 +10,11 @@ export const convertToSingleObject = async (convertionOptions: ObjectConvertionO const svgObject = {}; const svgDefinitions = await filesProcessor(convertionOptions); svgDefinitions.forEach((svgDefinition: SvgDefinition) => (svgObject[svgDefinition.typeName] = svgDefinition.data)); - await writeFile(outputDirectory, fileName, `export const ${objectName} = ${JSON.stringify(svgObject)}`); + const fileContent = + objectName === 'default' + ? `export default ${JSON.stringify(svgObject)}` + : `export const ${objectName} = ${JSON.stringify(svgObject)}`; + await writeFile(outputDirectory, fileName, fileContent); success(`Icons file successfully generated under ${underlineSuccess(outputDirectory)}`); } catch (exception) { error(`Something went wrong: ${exception}`); diff --git a/src/lib/options/args-collector.ts b/src/lib/options/args-collector.ts index a1a08f5..5f7433b 100644 --- a/src/lib/options/args-collector.ts +++ b/src/lib/options/args-collector.ts @@ -5,10 +5,10 @@ import { Delimiter } from '../generators/code-snippet-generators'; import { getSvgoConfig } from '../helpers/svg-optimization'; import { - FileConvertionOptions, ConstantsConvertionOptions, - ObjectConvertionOptions, - ConvertionType + ConvertionType, + FileConvertionOptions, + ObjectConvertionOptions } from './convertion-options'; import { DEFAULT_OPTIONS } from './default-options'; import { error } from '../helpers/log-helper'; @@ -25,8 +25,7 @@ export const setupCommander = () => { .option('-f --fileName ', 'name of the generated file', DEFAULT_OPTIONS.fileName) .option( '-d --delimiter ', - `delimiter which is used to generate the types and name properties (${Object.values(Delimiter).join(',')})`, - DEFAULT_OPTIONS.delimiter + `delimiter which is used to generate the types and name properties (${Object.values(Delimiter).join(',')})` ) .option('-p --prefix ', 'prefix for the generated svg constants', DEFAULT_OPTIONS.prefix) .option('-i --interfaceName ', 'name for the generated interface', DEFAULT_OPTIONS.interfaceName) @@ -106,6 +105,8 @@ export const collectArgumentOptions = async (): Promise< generateTypeObject = toBoolean(generateTypeObject, DEFAULT_OPTIONS.generateTypeObject); compileSources = toBoolean(compileSources, DEFAULT_OPTIONS.compileSources); + delimiter = convertionType === ConvertionType.OBJECT ? Delimiter.CAMEL : Delimiter.SNAKE; + // Because of commander adding default value to params // See: https://stackoverflow.com/questions/30238654/commander-js-collect-multiple-options-always-include-default let srcFiles = commander.srcFiles; diff --git a/src/lib/options/config-collector.ts b/src/lib/options/config-collector.ts index 2529390..28b9ba9 100644 --- a/src/lib/options/config-collector.ts +++ b/src/lib/options/config-collector.ts @@ -11,6 +11,7 @@ import { DEFAULT_OPTIONS } from './default-options'; import * as packgeJSON from '../../../package.json'; import { error, info } from '../helpers/log-helper'; import { getSvgoConfig } from '../helpers/svg-optimization'; +import { Delimiter } from '../generators/code-snippet-generators'; export const collectConfigurationOptions = async (): Promise< ConstantsConvertionOptions | FileConvertionOptions | ObjectConvertionOptions | null @@ -50,8 +51,8 @@ const mergeWithDefaults = async ( } if (!configOptions.delimiter) { - configOptions.delimiter = DEFAULT_OPTIONS.delimiter; - info(`No delimiter provided, "${DEFAULT_OPTIONS.delimiter}" will be used`); + configOptions.delimiter = options.convertionType === ConvertionType.OBJECT ? Delimiter.CAMEL : Delimiter.SNAKE; + info(`No delimiter provided, "${configOptions.delimiter}" will be used`); } if (options.convertionType === ConvertionType.OBJECT) { diff --git a/src/lib/options/default-options.ts b/src/lib/options/default-options.ts index dce545c..afe96b1 100644 --- a/src/lib/options/default-options.ts +++ b/src/lib/options/default-options.ts @@ -1,8 +1,5 @@ -import { Delimiter } from '../generators/code-snippet-generators'; - export const DEFAULT_OPTIONS = { fileName: 'my-icons', - delimiter: Delimiter.SNAKE, interfaceName: 'MyIcon', objectName: 'icons', outputDirectory: './dist',