From 959d3d820907dc0899edce6fddedd3f832701974 Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 11 Aug 2021 06:29:48 +0200 Subject: [PATCH] feat(core): handling sub directory with feature generation (#276) https://github.com/nstudio/xplat/issues/275#issuecomment-878208786 --- packages/xplat/src/utils/xplat.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/xplat/src/utils/xplat.ts b/packages/xplat/src/utils/xplat.ts index 97af98fd..2cfffabc 100644 --- a/packages/xplat/src/utils/xplat.ts +++ b/packages/xplat/src/utils/xplat.ts @@ -1035,6 +1035,10 @@ export namespace XplatFeatureHelpers { * Skip formatting */ skipFormat?: boolean; + /** + * The directory of the new feature + */ + directory?: string; /** * testing helper */ @@ -1128,12 +1132,22 @@ export namespace XplatFeatureHelpers { extra: string = '', framework?: FrameworkTypes ) { + //Handle "/" in name + options.directory = options.directory || ''; + const folderParts = options.name.split('/'); + if (folderParts.length > 1) { + options.name = folderParts[folderParts.length - 1]; + folderParts.pop(); + options.directory = folderParts.join('/') + '/'; + } let moveTo: string; if (target) { moveTo = getMoveTo(options, target, projectName, framework); } else { target = 'lib'; - moveTo = `libs/xplat/features/src/lib/${options.name.toLowerCase()}`; + moveTo = `libs/xplat/features/src/lib/${ + options.directory + }${options.name.toLowerCase()}`; } if (!extra) { // make sure no `null` or `undefined` values get in the string path @@ -1193,6 +1207,7 @@ export namespace XplatFeatureHelpers { platform, framework ); + return { ...(options as any), ...getDefaultTemplateOptions(), @@ -1215,12 +1230,12 @@ export namespace XplatFeatureHelpers { ); // console.log('getMoveTo xplatFolderName:', xplatFolderName); const featureName = options.name.toLowerCase(); - let moveTo = `libs/xplat/${xplatFolderName}/features/src/lib/${featureName}`; + let moveTo = `libs/xplat/${xplatFolderName}/features/src/lib/${options.directory}${featureName}`; if (projectName) { let appDir = ['web', 'web-angular'].includes(xplatFolderName) ? '/app' : ''; - moveTo = `apps/${projectName}/src${appDir}/features/${featureName}`; + moveTo = `apps/${projectName}/src${appDir}/features/${options.directory}${featureName}`; // console.log('moveTo:', moveTo); } return moveTo;