Skip to content

Commit

Permalink
fix(modelfile): remove output path
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekcode committed Mar 11, 2020
1 parent ef8b79d commit 9f03426
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"start:ofl:regex": "ts-node ./src/bin/svg-to-ts.ts --optimizeForLazyLoading true -s './inputfilesRegex/**/*.svg'",
"start:ofl:kebap": "ts-node ./src/bin/svg-to-ts.ts --optimizeForLazyLoading true -s './inputfiles/*.svg' -d KEBAB",
"start:ofl:multiple-source": "ts-node ./src/bin/svg-to-ts.ts --optimizeForLazyLoading true -s './inputfiles/*.svg' -s './inputfilesBis/*.svg'",
"start:ofl:customModel": "ts-node ./src/bin/svg-to-ts.ts --optimizeForLazyLoading true -s './inputfilesRegex/**/*.svg' --modelOutputPath ./dist/model --modelFileName test-model -t sampleIcon -i SampleIcon",
"start:ofl:customModel": "ts-node ./src/bin/svg-to-ts.ts --optimizeForLazyLoading true -s './inputfilesRegex/**/*.svg' --modelFileName test-model -t sampleIcon -i SampleIcon",
"start:ofl:custom": "ts-node ./src/bin/svg-to-ts.ts --optimizeForLazyLoading true -s './inputfiles/*.svg' -o ./dist -t sampleIcon -i SampleIcon -p sampleIcon -f icons",
"semantic-release": "semantic-release"
},
Expand Down
5 changes: 0 additions & 5 deletions src/bin/svg-to-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ commander
'optimize the output for lazyloading',
DEFAULT_OPTIONS.optimizeForLazyLoading
)
.option(
'--modelOutputPath <string>',
'Output path for the types file (only necessary when optimizeForLazyLoading option is enabled)',
DEFAULT_OPTIONS.modelOutputPath
)
.option(
'--modelFileName <string>',
'FileName of the model file (only necessary when optimizeForLazyLoading option is enabled)',
Expand Down
18 changes: 12 additions & 6 deletions src/lib/converters/multiple-files.converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import * as path from 'path';
import {
generateExportStatement,
generateInterfaceDefinition,
generateSvgConstantWithImport,
generateTypeDefinition,
generateTypeName,
generateUntypedSvgConstant,
generateVariableName
} from '../generators/code-snippet-generators';
import { getFilePathsFromRegex } from '../helpers/regex-helpers';
Expand All @@ -24,7 +24,6 @@ export const convertToMultipleFiles = async (convertionOptions: MultiFileConvert
delimiter,
outputDirectory,
srcFiles,
modelOutputPath,
modelFileName,
iconsFolderName
} = convertionOptions;
Expand All @@ -47,7 +46,13 @@ export const convertToMultipleFiles = async (convertionOptions: MultiFileConvert
const optimizedSvg = await svgOptimizer.optimize(rawSvg);
const variableName = generateVariableName(prefix, filenameWithoutEnding);
const typeName = generateTypeName(filenameWithoutEnding, delimiter);
const svgConstant = generateUntypedSvgConstant(variableName, typeName, optimizedSvg.data);
const svgConstant = generateSvgConstantWithImport(
variableName,
typeName,
interfaceName,
modelFileName,
optimizedSvg.data
);
const generatedFileName = `${prefix}-${filenameWithoutEnding}.icon`;
indexFileContent += generateExportStatement(generatedFileName, iconsFolderName);
await writeFile(`${outputDirectory}/${iconsFolderName}`, generatedFileName, svgConstant);
Expand All @@ -57,13 +62,14 @@ export const convertToMultipleFiles = async (convertionOptions: MultiFileConvert
}
}
separatorEnd();
indexFileContent += generateExportStatement(modelFileName, iconsFolderName);
await writeFile(outputDirectory, 'index', indexFileContent);
info(`write index.ts`);

if (modelOutputPath && modelFileName) {
if (modelFileName) {
const modelFile = (types += generateInterfaceDefinition(interfaceName, typeName));
await writeFile(modelOutputPath, modelFileName, modelFile);
info(`model-file successfully generated under ${modelOutputPath}/${modelFileName}.model.ts`);
await writeFile(`${outputDirectory}/${iconsFolderName}`, modelFileName, modelFile);
info(`model-file successfully generated under ${outputDirectory}/${iconsFolderName}/${modelFileName}.ts`);
}

success('========================================================');
Expand Down
9 changes: 7 additions & 2 deletions src/lib/generators/code-snippet-generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ export const generateSvgConstant = (
};`;
};

export const generateUntypedSvgConstant = (
export const generateSvgConstantWithImport = (
variableName: string,
filenameWithoutEnding: string,
interfaceName: string,
modelFileName: string,
data: string
): string => {
return `export const ${variableName}: {name: any, data: string} = {
return `
import {${interfaceName}} from './${modelFileName}';
export const ${variableName}: ${interfaceName} = {
name: '${filenameWithoutEnding}',
data: '${data}'
};`;
Expand Down
2 changes: 0 additions & 2 deletions src/lib/options/args-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const collectArgumentOptions = (): SingleFileConvertionOptions | MultiFil
prefix,
typeName,
modelFileName,
modelOutputPath,
iconsFolderName,
optimizeForLazyLoading
} = commander;
Expand All @@ -32,7 +31,6 @@ export const collectArgumentOptions = (): SingleFileConvertionOptions | MultiFil
prefix,
typeName,
modelFileName,
modelOutputPath,
iconsFolderName,
optimizeForLazyLoading
};
Expand Down
5 changes: 0 additions & 5 deletions src/lib/options/config-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ const mergeWithDefaults = (
}

if (configOptions.optimizeForLazyLoading) {
if (!(configOptions as MultiFileConvertionOptions).modelOutputPath) {
(configOptions as MultiFileConvertionOptions).modelOutputPath = DEFAULT_OPTIONS.modelOutputPath;
info(`No modelOutputPath provided, "${DEFAULT_OPTIONS.modelOutputPath}" will be used`);
}

if (!(configOptions as MultiFileConvertionOptions).modelFileName) {
(configOptions as MultiFileConvertionOptions).modelFileName = DEFAULT_OPTIONS.modelFileName;
info(`No modelFileName provided, "${DEFAULT_OPTIONS.modelFileName}" will be used`);
Expand Down
1 change: 0 additions & 1 deletion src/lib/options/convertion-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface SingleFileConvertionOptions extends ConvertionOptions {

export interface MultiFileConvertionOptions extends ConvertionOptions {
modelFileName: string;
modelOutputPath: string;
iconsFolderName: string;
}

Expand Down

0 comments on commit 9f03426

Please sign in to comment.