Skip to content

Commit

Permalink
feat(mutates): refactoring, part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
IKatsuba committed Jun 11, 2024
1 parent 72f9a3c commit 06fdcbf
Show file tree
Hide file tree
Showing 55 changed files with 205 additions and 1,890 deletions.
3 changes: 2 additions & 1 deletion packages/angular/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"nx-release-publish": {
"options": {
"packageRoot": "dist/{projectRoot}"
"packageRoot": "dist/{projectRoot}",
"tag": "next"
}
},
"test": {
Expand Down
3 changes: 3 additions & 0 deletions packages/angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ export * from './lib/bootstrap';
export * from './lib/component';
export * from './lib/directive';
export * from './lib/helpers';
export * from './lib/injectable';
export * from './lib/metadata';
export * from './lib/module';
export * from './lib/pipe';
export * from './lib/testing';
export * from './lib/create-angular-project';
export * from './lib/ng-tree-file-system';

This file was deleted.

This file was deleted.

23 changes: 13 additions & 10 deletions packages/angular/src/lib/bootstrap/get-bootstrap-application-fn.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import type { CallExpression } from 'ts-morph';
import { Node, SyntaxKind } from 'ts-morph';

import { getImports } from '@mutates/core';
import { getImportRefs, getImports, getNamedImports } from '@mutates/core';

export function getBootstrapApplicationFn(mainFilePath: string): CallExpression | undefined {
const [bootstrapApplicationImport] = getImports(mainFilePath, {
moduleSpecifier: '@angular/platform-browser',
});
const [namedImport] = getNamedImports(
getImports(mainFilePath, {
moduleSpecifier: '@angular/platform-browser',
}),
{
name: 'bootstrapApplication',
},
);

const namedImport = bootstrapApplicationImport
?.getNamedImports()
.find((imp) => imp.getName() === 'bootstrapApplication');
if (!namedImport) {
return;
}

return namedImport
?.getNameNode()
.findReferencesAsNodes()
return getImportRefs(namedImport)
.find((ref) => Node.isCallExpression(ref.getParent()))
?.getParentIfKind(SyntaxKind.CallExpression);
}
22 changes: 0 additions & 22 deletions packages/angular/src/lib/bootstrap/get-bootstrap-fn.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createSourceFile } from '@mutates/core';

import { createAngularProject } from '../create-angular-project';
import { createTestingTree } from '../testing';
import { getBootstrapFn } from './get-bootstrap-fn';
import { getBootstrapModuleFn } from './get-bootstrap-module-fn';

describe('getBootstrapFn', () => {
let host: UnitTestTree;
Expand All @@ -32,7 +32,7 @@ platformBrowserDynamic()
.catch(err => console.log(err));
`,
);
const bootstrapFn = getBootstrapFn('src/main.ts')!;
const bootstrapFn = getBootstrapModuleFn('src/main.ts')!;

expect(bootstrapFn.getText()).toBe(`platformBrowserDynamic()
.bootstrapModule(AppModule)`);
Expand All @@ -41,7 +41,7 @@ platformBrowserDynamic()

it('should return undefined if bootstrap function is not found', () => {
createSourceFile('src/main.ts', '');
const bootstrapFn = getBootstrapFn('src/main.ts');
const bootstrapFn = getBootstrapModuleFn('src/main.ts');

expect(bootstrapFn).toBeUndefined();
});
Expand Down
21 changes: 21 additions & 0 deletions packages/angular/src/lib/bootstrap/get-bootstrap-module-fn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { CallExpression } from 'ts-morph';
import { Node, SyntaxKind } from 'ts-morph';

import { getImportRefs, getImports, getNamedImports } from '@mutates/core';

export function getBootstrapModuleFn(mainFilePath: string): CallExpression | undefined {
const namedImport = getNamedImports(
getImports(mainFilePath, {
moduleSpecifier: '@angular/platform-browser-dynamic',
}),
{
name: 'platformBrowserDynamic',
},
);

return getImportRefs(namedImport)
.find((ref) => Node.isCallExpression(ref.getParent()))
?.getParentIfKind(SyntaxKind.CallExpression)
?.getParentIfKind(SyntaxKind.PropertyAccessExpression)
?.getParentIfKind(SyntaxKind.CallExpression);
}
3 changes: 1 addition & 2 deletions packages/angular/src/lib/bootstrap/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './add-provider-to-bootstrap-application-fn';
export * from './get-bootstrap-application-fn';
export * from './get-bootstrap-fn';
export * from './get-bootstrap-module-fn';
121 changes: 0 additions & 121 deletions packages/angular/src/lib/component/add-import-to-component.spec.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/angular/src/lib/component/add-import-to-component.ts

This file was deleted.

Loading

0 comments on commit 06fdcbf

Please sign in to comment.