From ab710827d618827e9a40731445c6f94b338f9200 Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Tue, 18 Aug 2020 19:12:37 +0300 Subject: [PATCH] feat: add relativePathFromServiceToModel utility fn --- npm/ng-packs/packages/schematics/src/utils/index.ts | 1 + npm/ng-packs/packages/schematics/src/utils/path.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 npm/ng-packs/packages/schematics/src/utils/path.ts diff --git a/npm/ng-packs/packages/schematics/src/utils/index.ts b/npm/ng-packs/packages/schematics/src/utils/index.ts index f68cb11ded..cc9b0052fa 100644 --- a/npm/ng-packs/packages/schematics/src/utils/index.ts +++ b/npm/ng-packs/packages/schematics/src/utils/index.ts @@ -2,6 +2,7 @@ export * from './angular'; export * from './ast'; export * from './common'; export * from './namespace'; +export * from './path'; export * from './rule'; export * from './service'; export * from './source'; diff --git a/npm/ng-packs/packages/schematics/src/utils/path.ts b/npm/ng-packs/packages/schematics/src/utils/path.ts new file mode 100644 index 0000000000..a48534c92c --- /dev/null +++ b/npm/ng-packs/packages/schematics/src/utils/path.ts @@ -0,0 +1,11 @@ +import { dir } from './text'; + +export function relativePathFromServiceToModel(serviceNamespace: string, modelNamespace: string) { + const repeats = serviceNamespace ? serviceNamespace.split('.').length : 0; + const path = '..' + '/..'.repeat(repeats) + '/models/' + dir(modelNamespace); + return removeTrailingSlash(path); +} + +function removeTrailingSlash(path: string) { + return path.replace(/\/+$/, ''); +}