Browse Source

refactor: make schematics import sort fn reusable

pull/5137/head
Arman Ozak 6 years ago
parent
commit
f467dc75c8
  1. 11
      npm/ng-packs/packages/schematics/src/utils/import.ts
  2. 1
      npm/ng-packs/packages/schematics/src/utils/index.ts
  3. 11
      npm/ng-packs/packages/schematics/src/utils/service.ts

11
npm/ng-packs/packages/schematics/src/utils/import.ts

@ -0,0 +1,11 @@
import { Import } from '../models';
export function sortImports(imports: Import[]) {
imports.sort((a, b) =>
removeRelative(a) > removeRelative(b) ? 1 : a.keyword > b.keyword ? 1 : -1,
);
}
export function removeRelative(importDef: Import) {
return importDef.path.replace(/\.\.\//g, '');
}

1
npm/ng-packs/packages/schematics/src/utils/index.ts

@ -1,6 +1,7 @@
export * from './angular';
export * from './ast';
export * from './common';
export * from './import';
export * from './model';
export * from './namespace';
export * from './path';

11
npm/ng-packs/packages/schematics/src/utils/service.ts

@ -1,4 +1,5 @@
import { Action, Body, Controller, Import, Method, Property, Service, Signature } from '../models';
import { sortImports } from './import';
import { parseNamespace } from './namespace';
import { parseGenerics } from './tree';
import { createTypeAdapter, createTypesToImportsReducer } from './type';
@ -24,16 +25,6 @@ export function createControllerToServiceMapper(solution: string, apiName: strin
};
}
function sortImports(imports: Import[]) {
imports.sort((a, b) =>
removeRelative(a) > removeRelative(b) ? 1 : a.keyword > b.keyword ? 1 : -1,
);
}
function removeRelative(importDef: Import) {
return importDef.path.replace(/\.\.\//g, '');
}
function sortMethods(methods: Method[]) {
methods.sort((a, b) => (a.signature.name > b.signature.name ? 1 : -1));
}

Loading…
Cancel
Save