Skip to content

Commit

Permalink
refactor: 💡 resolve merge damages
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekcode committed Aug 20, 2024
1 parent ea2c65d commit c5a62d7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 90 deletions.
7 changes: 2 additions & 5 deletions src/commands/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);

Expand Down Expand Up @@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion src/converters/directive/directive.converter.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/converters/pipes/pipes.converter.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
3 changes: 3 additions & 0 deletions src/converters/service/service.converter.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
},
];
Expand Down
4 changes: 2 additions & 2 deletions src/parser/parse-output.model.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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[];
Expand Down
91 changes: 10 additions & 81 deletions src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

0 comments on commit c5a62d7

Please sign in to comment.