From d5c86354076a93c8e485154d6a4b60dc43071c13 Mon Sep 17 00:00:00 2001 From: kreuzerk Date: Tue, 16 Jun 2020 12:19:54 +0200 Subject: [PATCH] feat(defaultexport): use default export if no objectname is specified --- README.md | 41 ++++++++++++++++++++++++-- package.json | 2 +- src/lib/converters/object.converter.ts | 7 ++--- src/lib/options/args-collector.ts | 2 +- src/lib/options/config-collector.ts | 9 ------ 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 87c9e0f..829d4e1 100644 --- a/README.md +++ b/README.md @@ -160,9 +160,18 @@ Available options: | 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 | +| objectName | string | default - export | name of the exported const - if nothing is set - default export will be used | -As mentioned above, `svg-to-ts` supports different use-cases. You can either generate you library to a single TypeScript file with multiple constants, to single TypeScript file per Icon -or to allready precompiled JavaScript files. +#### Sample output + +```javascript +export default { + expressionLess: ' (svgObject[svgDefinition.typeName] = svgDefinition.data)); - const fileContent = - objectName === 'default' - ? `export default ${JSON.stringify(svgObject)}` - : `export const ${objectName} = ${JSON.stringify(svgObject)}`; + const fileContent = !objectName + ? `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) { diff --git a/src/lib/options/args-collector.ts b/src/lib/options/args-collector.ts index 2b7a7db..d2f7639 100644 --- a/src/lib/options/args-collector.ts +++ b/src/lib/options/args-collector.ts @@ -18,7 +18,7 @@ export const setupCommander = () => { commander .version(packgeJSON.version) .option('-c --convertionType ', 'convertion type (object, constants, files)') - .option('--objectName ', 'name of the exported object', DEFAULT_OPTIONS.objectName) + .option('--objectName ', 'name of the exported object') .option('-t --typeName ', 'name of the generated enumeration type', DEFAULT_OPTIONS.typeName) .option('--generateType ', 'prevent generating enumeration type', DEFAULT_OPTIONS.generateType) .option('--generateTypeObject ', 'generate type object', DEFAULT_OPTIONS.generateTypeObject) diff --git a/src/lib/options/config-collector.ts b/src/lib/options/config-collector.ts index 28b9ba9..337296f 100644 --- a/src/lib/options/config-collector.ts +++ b/src/lib/options/config-collector.ts @@ -55,15 +55,6 @@ const mergeWithDefaults = async ( info(`No delimiter provided, "${configOptions.delimiter}" will be used`); } - if (options.convertionType === ConvertionType.OBJECT) { - info(`Convertiontype "Object" will be used`); - - if (!(configOptions as ObjectConvertionOptions).objectName) { - configOptions.outputDirectory = DEFAULT_OPTIONS.objectName; - info(`No outputDirectory provided, "${DEFAULT_OPTIONS.objectName}" will be used`); - } - } - if (options.convertionType === ConvertionType.CONSTANTS || options.convertionType === ConvertionType.OBJECT) { if (!(configOptions as ConstantsConvertionOptions).fileName) { (configOptions as ConstantsConvertionOptions).fileName = DEFAULT_OPTIONS.modelFileName;