Skip to content

Commit

Permalink
fix(objectconvertion): respect delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekcode committed Jun 16, 2020
1 parent ce6ed70 commit b0b307a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"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",
"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-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'",
Expand Down
8 changes: 4 additions & 4 deletions src/bin/svg-to-ts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env node
import { convertToSingleFile } from '../lib/converters/single-file.converter';
import { convertToMultipleFiles } from '../lib/converters/multiple-files.converter';
import {
ConvertionType,
getOptions,
Expand All @@ -11,6 +9,8 @@ import {
import { info, printLogo } from '../lib/helpers/log-helper';
import { setupCommander } from '../lib/options/args-collector';
import { convertToSingleObject } from '../lib/converters/object.converter';
import { convertToConstants } from '../lib/converters/constants.converter';
import { convertToFiles } from '../lib/converters/files.converter';

(async () => {
setupCommander();
Expand All @@ -19,12 +19,12 @@ import { convertToSingleObject } from '../lib/converters/object.converter';

if (convertionOptions.convertionType === ConvertionType.FILES) {
info('We are using the convertiontype "files"');
await convertToMultipleFiles(convertionOptions as FileConvertionOptions);
await convertToFiles(convertionOptions as FileConvertionOptions);
}

if (convertionOptions.convertionType === ConvertionType.CONSTANTS) {
info('We are using the convertiontype "constants"');
await convertToSingleFile(convertionOptions as ConstantsConvertionOptions);
await convertToConstants(convertionOptions as ConstantsConvertionOptions);
}

if (convertionOptions.convertionType === ConvertionType.OBJECT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getSvgConstants = svgDefinitions => {
return svgConstants.join('');
};

export const convertToSingleFile = async (convertionOptions: ConstantsConvertionOptions): Promise<void> => {
export const convertToConstants = async (convertionOptions: ConstantsConvertionOptions): Promise<void> => {
const { outputDirectory, fileName } = convertionOptions;
try {
const svgDefinitions = await filesProcessor(convertionOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const writeFiles = async (outputDirectory, iconsFolderName, modelFileName, prefi
return fileContent.join('');
};

export const convertToMultipleFiles = async (convertionOptions: FileConvertionOptions): Promise<void> => {
export const convertToFiles = async (convertionOptions: FileConvertionOptions): Promise<void> => {
const {
prefix,
outputDirectory,
Expand Down
8 changes: 3 additions & 5 deletions src/lib/converters/object.converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import { error, success, underlineSuccess } from '../helpers/log-helper';
import { filesProcessor, SvgDefinition } from './shared.converter';

export const convertToSingleObject = async (convertionOptions: ObjectConvertionOptions): Promise<void> => {
const { outputDirectory, fileName } = convertionOptions;
const { outputDirectory, fileName, objectName } = convertionOptions;
try {
const svgObject = {};
const svgDefinitions = await filesProcessor(convertionOptions);
svgDefinitions.forEach(
(svgDefinition: SvgDefinition) => (svgObject[svgDefinition.filenameWithoutEnding] = svgDefinition.data)
);
await writeFile(outputDirectory, fileName, `export const icons = ${JSON.stringify(svgObject)}`);
svgDefinitions.forEach((svgDefinition: SvgDefinition) => (svgObject[svgDefinition.typeName] = svgDefinition.data));
await writeFile(outputDirectory, fileName, `export const ${objectName} = ${JSON.stringify(svgObject)}`);
success(`Icons file successfully generated under ${underlineSuccess(outputDirectory)}`);
} catch (exception) {
error(`Something went wrong: ${exception}`);
Expand Down

0 comments on commit b0b307a

Please sign in to comment.