Skip to content

Commit

Permalink
feat(optimizeforlazyloading): add compile sources flag
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Rename preCompile sources to compileSources
  • Loading branch information
nivekcode committed Mar 20, 2020
1 parent 0b00a43 commit b177737
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 16 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ gets reduced, but also, where they end up. Means, an icon that is only used in a
end up there.
![Output scenario two](https://raw.githubusercontent.com/kreuzerk/svg-to-ts/master/assets/generated-files-scr2.png)

**We wrote a step to step guide that explains this approach further and helps you create an icon library with this approach.**
[Find out more in this blogpost](https://medium.com/angular-in-depth/how-to-create-an-icon-library-in-angular-4f8863d95a)
**A step by step guide is coming soon**

Available configurations:

Expand All @@ -197,7 +196,7 @@ Available configurations:
| optimizeForLazyLoading | boolean | false | when set to true, multiple files will be generated |
| additionalModelOutputPath | string | null | if a path is specified we will generate an additional file containing interface and type to this path - can be useful to improve type safety |
| iconsFolderName | string | "build" | name of the folder we will build the TypeScript files to |
| preCompileSources | boolean | false | If set to false, we generate a TypeScript file for each SVG. If set to true we will allready compile those TypeScript files and generate JavaScript files and declaration files |
| compileSources | boolean | false | If set to false, we generate a TypeScript file for each SVG. If set to true we will allready compile those TypeScript files and generate JavaScript files and declaration files |

# FAQ

Expand Down
2 changes: 1 addition & 1 deletion src/bin/svg-to-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ commander
.option(
'--preCompileSources <boolean>',
'Tells if the sources should be precompiled with the TypeScript compiler. If true, you will only end up with d.ts and js files (only necessary when optimizeForLazyLoading option is enabled)',
DEFAULT_OPTIONS.preCompileSources
DEFAULT_OPTIONS.compileSources
)
.parse(process.argv);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/compiler/typescript-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ts from 'typescript';

export const compileSources = (filePaths: string[]): void => {
export const compile = (filePaths: string[]): void => {
const compilerOptions = {
noEmitOnError: false,
noImplicitAny: true,
Expand Down
8 changes: 4 additions & 4 deletions src/lib/converters/multiple-files.converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { deleteFiles, deleteFolder, extractSvgContent, writeFile } from '../help
import { info, separatorEnd, separatorStart, success } from '../helpers/log-helper';
import { svgOptimizer } from '../helpers/svg-optimization';
import { MultiFileConvertionOptions } from '../options/convertion-options';
import { compileSources } from '../compiler/typescript-compiler';
import { compile } from '../compiler/typescript-compiler';

const typesDelimitor = ' | ';

Expand All @@ -28,7 +28,7 @@ export const convertToMultipleFiles = async (convertionOptions: MultiFileConvert
modelFileName,
additionalModelOutputPath,
iconsFolderName,
preCompileSources
compileSources
} = convertionOptions;
let indexFileContent = '';
let types = generateTypeDefinition(typeName);
Expand Down Expand Up @@ -79,12 +79,12 @@ export const convertToMultipleFiles = async (convertionOptions: MultiFileConvert
}
}

if (preCompileSources) {
if (compileSources) {
const generatedTypeScriptFilePaths = await getFilePathsFromRegex([
`${outputDirectory}/${iconsFolderName}/*.ts`,
`${outputDirectory}/index.ts`
]);
compileSources(generatedTypeScriptFilePaths);
compile(generatedTypeScriptFilePaths);
info(`compile Typescript - generate JS and d.ts`);
deleteFiles(generatedTypeScriptFilePaths);
info(`delete Typescript files`);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/options/args-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const collectArgumentOptions = (): SingleFileConvertionOptions | MultiFil
iconsFolderName,
optimizeForLazyLoading,
additionalModelOutputPath,
preCompileSources
compileSources
} = commander;

// Because of commander adding default value to params
Expand All @@ -36,6 +36,6 @@ export const collectArgumentOptions = (): SingleFileConvertionOptions | MultiFil
iconsFolderName,
optimizeForLazyLoading,
additionalModelOutputPath,
preCompileSources
compileSources
};
};
6 changes: 3 additions & 3 deletions src/lib/options/config-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ const mergeWithDefaults = (
info(`No iconsFolderName provided, "${DEFAULT_OPTIONS.iconsFolderName}" will be used`);
}

if (!(configOptions as MultiFileConvertionOptions).preCompileSources) {
(configOptions as MultiFileConvertionOptions).preCompileSources = DEFAULT_OPTIONS.preCompileSources;
info(`No preCompileSources flag provided, "${DEFAULT_OPTIONS.preCompileSources}" will be used`);
if (!(configOptions as MultiFileConvertionOptions).compileSources) {
(configOptions as MultiFileConvertionOptions).compileSources = DEFAULT_OPTIONS.compileSources;
info(`No preCompileSources flag provided, "${DEFAULT_OPTIONS.compileSources}" will be used`);
}
return configOptions as MultiFileConvertionOptions;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/options/convertion-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface MultiFileConvertionOptions extends ConvertionOptions {
modelFileName: string;
additionalModelOutputPath: string | null;
iconsFolderName: string;
preCompileSources: boolean;
compileSources: boolean;
}

export const getOptions = (): MultiFileConvertionOptions | SingleFileConvertionOptions => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/options/default-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export const DEFAULT_OPTIONS = {
additionalModelOutputPath: null,
modelFileName: 'my-icons.model',
iconsFolderName: 'build',
preCompileSources: false
compileSources: false
};

0 comments on commit b177737

Please sign in to comment.