Skip to content

Commit

Permalink
Merge pull request #15 from kreuzerk/check-extension
Browse files Browse the repository at this point in the history
fix(conversion): check to allow only svg files
  • Loading branch information
nivekcode authored Feb 10, 2020
2 parents 2af8f09 + 9fc3111 commit 9e3fb3d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/lib/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ export const convert = async (convertionOptions: ConvertionOptions): Promise<voi
for (let i = 0; i < files.length; i++) {
if (files[i].isFile()) {
const fileNameWithEnding = files[i].name;
const filenameWithoutEnding = fileNameWithEnding.split('.')[0];
const directoryPath = filesDirectoryPath[fileNameWithEnding];
const rawSvg = await extractSvgContent(fileNameWithEnding, directoryPath);
const optimizedSvg = await svgo.optimize(rawSvg);
const variableName = getVariableName(convertionOptions, filenameWithoutEnding);
const typeName = getTypeName(filenameWithoutEnding, convertionOptions.delimiter);
types += `'${typeName}'${typesDelimitor}`;
svgConstants += getSvgConstant(variableName, convertionOptions.interfaceName, typeName, optimizedSvg.data);
const [filenameWithoutEnding, extension] = fileNameWithEnding.split('.');

if (extension === 'svg') {
const directoryPath = filesDirectoryPath[fileNameWithEnding];
const rawSvg = await extractSvgContent(fileNameWithEnding, directoryPath);
const optimizedSvg = await svgo.optimize(rawSvg);
const variableName = getVariableName(convertionOptions, filenameWithoutEnding);
const typeName = getTypeName(filenameWithoutEnding, convertionOptions.delimiter);
types += `'${typeName}'${typesDelimitor}`;
svgConstants += getSvgConstant(variableName, convertionOptions.interfaceName, typeName, optimizedSvg.data);
}
}
}
types = types.substring(0, types.length - typesDelimitor.length) + ';';
Expand Down

0 comments on commit 9e3fb3d

Please sign in to comment.