From 932aa0125187995f843571163f5ac34ef694fae4 Mon Sep 17 00:00:00 2001 From: Danilo Hoffmann Date: Thu, 3 Sep 2020 12:47:20 +0200 Subject: [PATCH] fix(schematics): enable customized-copy schematic for subfolders (#374) --- e2e/test-schematics.sh | 11 +++++++++++ schematics/src/helpers/customized-copy/factory.ts | 6 ++++-- schematics/src/helpers/customized-copy/schema.json | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/e2e/test-schematics.sh b/e2e/test-schematics.sh index 554183cb67..523d470dd6 100644 --- a/e2e/test-schematics.sh +++ b/e2e/test-schematics.sh @@ -89,11 +89,22 @@ grep "AudioComponent" src/app/shared/shared.module.ts npm run lint node schematics/customization/add custom +# format without source folder prefix from project root npx ng g customized-copy shell/footer/footer stat src/app/shell/footer/custom-footer/custom-footer.component.ts grep 'custom-footer' src/app/app.component.html +# format with source folder prefix from project root +npx ng g customized-copy src/app/shared/components/basket/basket-promotion +stat src/app/shared/components/basket/custom-basket-promotion/custom-basket-promotion.component.html +grep 'custom-basket-promotion' src/app/shared/components/basket/basket-cost-summary/basket-cost-summary.component.html + +# from subfolder +(cd src/app/pages/checkout-review && npx ng g customized-copy checkout-review) +stat src/app/pages/checkout-review/custom-checkout-review/custom-checkout-review.component.html +grep 'custom-checkout-review' src/app/pages/checkout-review/checkout-review-page.component.html + sed -i -e "s%icmBaseURL.*%icmBaseURL: 'http://localhost:4200',%g" src/environments/environment.prod.ts if grep mockServerAPI src/environments/environment.prod.ts diff --git a/schematics/src/helpers/customized-copy/factory.ts b/schematics/src/helpers/customized-copy/factory.ts index 998a1df946..994d2ba531 100644 --- a/schematics/src/helpers/customized-copy/factory.ts +++ b/schematics/src/helpers/customized-copy/factory.ts @@ -24,9 +24,11 @@ export function customize(options: Options): Rule { const workspace = await getWorkspace(host); const project = workspace.projects.get(options.project); - const from = options.from.replace(/\/$/, ''); const sourceRoot = project.sourceRoot; - const dir = host.getDir(`${sourceRoot}/app/${from}`); + const from = `${ + options.path ? options.path + '/' : !options.from?.startsWith(sourceRoot + '/app/') ? sourceRoot + '/app/' : '' + }${options.from.replace(/\/$/, '')}`; + const dir = host.getDir(from); const fromName = basename(dir.path); diff --git a/schematics/src/helpers/customized-copy/schema.json b/schematics/src/helpers/customized-copy/schema.json index 42b488ec6e..84d886a3dc 100644 --- a/schematics/src/helpers/customized-copy/schema.json +++ b/schematics/src/helpers/customized-copy/schema.json @@ -11,6 +11,11 @@ }, "visible": false }, + "path": { + "type": "string", + "format": "path", + "visible": false + }, "from": { "type": "string", "description": "The folder of the component source.",