Skip to content

Commit

Permalink
chore: 🤖 inline svg-to-ts wrapper into index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekcode committed Oct 25, 2020
1 parent ef69a21 commit 75f6599
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 97 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2
}
64 changes: 38 additions & 26 deletions src/svg-icons-builder/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
import { BuilderOutput, createBuilder } from '@angular-devkit/architect';
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
import { JsonObject } from '@angular-devkit/core';
import { fork } from 'child_process';
import { join } from 'path';
import { ConstantsConversionOptions } from 'svg-to-ts/src/lib/options/conversion-options';
/*
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';

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

export default createBuilder<Options>((options, context) => {
context.logger.info(`Options: ${options}`);
return new Promise<BuilderOutput>((resolve, reject) => {
const child = fork(join(__dirname, `/svg-to-ts-wrapper.ts`), [], {
stdio: [0, 1, 2, 'ipc'],
});
child.send(options);
child.on('message', ({ isError, data }) => {
if (isError) {
context.logger.error(data);
child.kill('SIGINT');
reject();
}
context.logger.info(data);
});
child.on('exit', (code) => {
resolve({ success: code === 0 });
});
child.on('error', (err) => {
context.logger.error(err.toString());
export default createBuilder<Options>((conversionOptions: Options, context: BuilderContext) => {
return new Promise<BuilderOutput>(async (resolve, reject) => {
if (!conversionOptions) {
reject();
});
}

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

if (conversionOptions.conversionType === ConversionType.CONSTANTS) {
context.logger.info('We are using the conversion type "constants"');
await convertToConstants((conversionOptions as unknown) as ConstantsConversionOptions);
}

if (conversionOptions.conversionType === ConversionType.OBJECT) {
context.logger.info('We are using the conversion type "object"');
await convertToSingleObject((conversionOptions as unknown) as ObjectConversionOptions);
}

resolve();
context.reportStatus(`Done.`);
process.exit(0);
});
});
71 changes: 0 additions & 71 deletions src/svg-icons-builder/svg-to-ts-wrapper.ts

This file was deleted.

0 comments on commit 75f6599

Please sign in to comment.