Skip to content

Commit

Permalink
feat: 🎸 enrich options with default options
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekcode committed Oct 28, 2020
1 parent 0519928 commit 94bd99f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 40 deletions.
92 changes: 67 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"dependencies": {
"@angular-devkit/core": "^10.1.6",
"@angular-devkit/schematics": "^10.1.6",
"typescript": "~4.0.2",
"svg-to-ts": "^5.6.1"
"svg-to-ts": "^5.7.0",
"typescript": "~4.0.2"
},
"devDependencies": {
"@angular-devkit/architect": "^0.1001.7",
Expand Down
22 changes: 9 additions & 13 deletions svg-icons-builder/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
import { JsonObject } from '@angular-devkit/core';
/*
TODO - we should export this from svg-to-ts - otherwise we rely on internals and it would break if
we refactor something in svg-to-ts
*/
import {
CommonConversionOptions,
ConstantsConversionOptions,
ConversionType,
FileConversionOptions,
ObjectConversionOptions,
} from 'svg-to-ts/src/lib/options/conversion-options';
import { convertToFiles } from 'svg-to-ts/src/lib/converters/files.converter';
import { convertToConstants } from 'svg-to-ts/src/lib/converters/constants.converter';
import { convertToSingleObject } from 'svg-to-ts/src/lib/converters/object.converter';
convertToFiles,
convertToConstants,
convertToSingleObject,
mergeWithDefaults,
} from 'svg-to-ts';

interface Options extends CommonConversionOptions, JsonObject {
generateCompleteIconSet: boolean; // TODO: should this be exportCompleteIconSet
}
interface Options extends CommonConversionOptions, JsonObject {}

export default createBuilder<Options>((conversionOptions: Options, context: BuilderContext) => {
export default createBuilder<Options>((options: Options, context: BuilderContext) => {
return new Promise<BuilderOutput>(async (resolve, reject) => {
try {
if (!conversionOptions) {
if (!options.conversionType) {
reject();
}

const conversionOptions = await mergeWithDefaults(options);
if (conversionOptions.conversionType === ConversionType.FILES) {
context.logger.info('We are using the conversion type "files"');
await convertToFiles((conversionOptions as unknown) as FileConversionOptions);
Expand Down

0 comments on commit 94bd99f

Please sign in to comment.