From c5a62d7544f6a08d09f0b8a38aae3a9d3d69f532 Mon Sep 17 00:00:00 2001 From: kreuzerk Date: Tue, 20 Aug 2024 09:19:35 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20resolve=20merge=20da?= =?UTF-8?q?mages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/parse.ts | 7 +- .../directive/directive.converter.spec.ts | 2 +- src/converters/pipes/pipes.converter.spec.ts | 2 +- .../service.converter.component.spec.ts | 3 + src/parser/parse-output.model.ts | 4 +- src/parser/parser.ts | 91 ++----------------- 6 files changed, 19 insertions(+), 90 deletions(-) diff --git a/src/commands/parse.ts b/src/commands/parse.ts index 28e79a5..97cfd65 100644 --- a/src/commands/parse.ts +++ b/src/commands/parse.ts @@ -12,7 +12,7 @@ import { NgParselModule } from '../parser/module/module.model.js'; import { NgParselSpec } from '../parser/spec/spec.model.js'; import { NgParselHarness } from '../parser/harness/harness.model.js'; import { NgParselPipe } from '../parser/pipe/pipe.model.js'; -import { NgParselValidtor } from '../parser/validator/validator.model.js'; +import { NgParselValidator } from '../parser/validator/validator.model.js'; import { writeJson } from '../utils/write.util.js'; import { NgParselOutput } from '../parser/parse-output.model.js'; import { loadAndMergeConfig } from '../utils/config.util.js'; @@ -22,9 +22,6 @@ export function parseCommand(cliArgs: { [key: string]: string }) { const config = loadAndMergeConfig(cliArgs); - // TODO: clean this up later - config['src'] = './test-spa'; - const parsedOutput = parse(config); writeParsedOutputToDisk(config, parsedOutput); @@ -63,7 +60,7 @@ function writeOutputFiles( ngParselSpecs: NgParselSpec[], ngParselHarnesses: NgParselHarness[], ngParselPipes: NgParselPipe[], - ngParselValidators: NgParselValidtor[] + ngParselValidators: NgParselValidator[] ): void { if (!existsSync(config.out as string)) { mkdirSync(config.out as string, { recursive: true }); diff --git a/src/converters/directive/directive.converter.spec.ts b/src/converters/directive/directive.converter.spec.ts index 987028a..dd90689 100644 --- a/src/converters/directive/directive.converter.spec.ts +++ b/src/converters/directive/directive.converter.spec.ts @@ -1,4 +1,4 @@ -import { convertToDirectiveStats } from './directive.component.js'; +import { convertToDirectiveStats } from './directive.converter.js'; import { NgParselOutputType } from '../../parser/shared/model/types.model.js'; describe('Directive converter', () => { diff --git a/src/converters/pipes/pipes.converter.spec.ts b/src/converters/pipes/pipes.converter.spec.ts index 7f72623..0234f39 100644 --- a/src/converters/pipes/pipes.converter.spec.ts +++ b/src/converters/pipes/pipes.converter.spec.ts @@ -1,5 +1,5 @@ import { NgParselOutputType } from '../../parser/shared/model/types.model.js'; -import { convertToPipeStats } from './pipes.component.js'; +import { convertToPipeStats } from './pipes.converter.js'; describe('Directive converter', () => { it('should convert to directive stats', () => { diff --git a/src/converters/service/service.converter.component.spec.ts b/src/converters/service/service.converter.component.spec.ts index 5b04bdd..fddc46d 100644 --- a/src/converters/service/service.converter.component.spec.ts +++ b/src/converters/service/service.converter.component.spec.ts @@ -9,18 +9,21 @@ describe('Service stats converter', () => { className: 'first', type: NgParselOutputType.SERVICE, filePath: '', + fieldsPublicExplicit: [], methodsPublicExplicit: [], }, { className: 'second', type: NgParselOutputType.SERVICE, filePath: '', + fieldsPublicExplicit: [], methodsPublicExplicit: [], }, { className: 'third', type: NgParselOutputType.SERVICE, filePath: '', + fieldsPublicExplicit: [], methodsPublicExplicit: [], }, ]; diff --git a/src/parser/parse-output.model.ts b/src/parser/parse-output.model.ts index ed4161e..d53e25e 100644 --- a/src/parser/parse-output.model.ts +++ b/src/parser/parse-output.model.ts @@ -1,6 +1,6 @@ import { NgParselComponent } from './component/component.model.js'; import { NgParselSpec } from './spec/spec.model.js'; -import { NgParselValidtor } from './validator/validator.model.js'; +import { NgParselValidator } from './validator/validator.model.js'; import { NgParselHarness } from './harness/harness.model.js'; import { NgParselPipe } from './pipe/pipe.model.js'; import { NgParselModule } from './module/module.model.js'; @@ -10,7 +10,7 @@ import { NgParselService } from './services/service.model.js'; export interface NgParselOutput { ngParselComponents: NgParselComponent[]; ngParselSpecs: NgParselSpec[]; - ngParselValidators: NgParselValidtor[]; + ngParselValidators: NgParselValidator[]; ngParselHarnesses: NgParselHarness[]; ngParselPipes: NgParselPipe[]; ngParselModules: NgParselModule[]; diff --git a/src/parser/parser.ts b/src/parser/parser.ts index cd87449..0910755 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -83,85 +83,14 @@ export function parse(configuration: NgParselConfig): NgParselOutput { parseSpinner.fail(`Failed to parse files: ${e}`); } - const writeOutputSpinner = generateSpinner('Write output files'); - try { - writeOutputSpinner.start(); - - writeOutputFiles( - configuration, - ngParselComponents, - ngParselServices, - ngParselDirectives, - ngParselModules, - ngParselSpecs, - ngParselHarnesses, - ngParselPipes, - ngParselValidators - ); - - writeOutputSpinner.succeed(`Files successfully written to ${configuration.out}`); - } catch (e) { - writeOutputSpinner.fail(`Failed to write output files: ${e}`); - } -} - -function writeOutputFiles( - config: NgParselConfig, - ngParselComponents: NgParselComponent[], - ngParselServices: NgParselService[], - ngParselDirectives: NgParselDirective[], - ngParselModules: NgParselModule[], - ngParselSpecs: NgParselSpec[], - ngParselHarnesses: NgParselHarness[], - ngParselPipes: NgParselPipe[], - ngParselValidators: NgParselValidator[] -): void { - if (!existsSync(config.out as string)) { - mkdirSync(config.out as string, { recursive: true }); - } - - if (config.singleFile) { - writeJson(`${config.out}/ng-parsel.json`, [ - ...ngParselComponents, - ...ngParselServices, - ...ngParselModules, - ...ngParselDirectives, - ...ngParselSpecs, - ...ngParselHarnesses, - ...ngParselPipes, - ...ngParselValidators, - ]); - } else { - if (ngParselComponents.length > 0) { - writeJson(`${config.out}/ng-parsel-components.json`, ngParselComponents); - } - - if (ngParselServices.length > 0) { - writeJson(`${config.out}/ng-parsel-services.json`, ngParselServices); - } - - if (ngParselModules.length > 0) { - writeJson(`${config.out}/ng-parsel-modules.json`, ngParselModules); - } - - if (ngParselDirectives.length > 0) { - writeJson(`${config.out}/ng-parsel-directives.json`, ngParselDirectives); - } - - if (ngParselPipes.length > 0) { - writeJson(`${config.out}/ng-parsel-pipes.json`, ngParselPipes); - } - - if (ngParselSpecs.length > 0) { - writeJson(`${config.out}/ng-parsel-specs.json`, ngParselSpecs); - } - - if (ngParselHarnesses.length > 0) { - writeJson(`${config.out}/ng-parsel-harnesses.json`, ngParselHarnesses); - } - - if (ngParselValidators.length > 0) { - writeJson(`${config.out}/ng-parsel-validators.json`, ngParselValidators); - } - } + return { + ngParselComponents, + ngParselServices, + ngParselDirectives, + ngParselModules, + ngParselSpecs, + ngParselHarnesses, + ngParselPipes, + ngParselValidators, + }; }