Skip to content

Commit

Permalink
fix(schematics): enable customized-copy schematic for subfolders (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi authored Sep 3, 2020
1 parent f61cc93 commit 932aa01
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
11 changes: 11 additions & 0 deletions e2e/test-schematics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions schematics/src/helpers/customized-copy/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions schematics/src/helpers/customized-copy/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
},
"visible": false
},
"path": {
"type": "string",
"format": "path",
"visible": false
},
"from": {
"type": "string",
"description": "The folder of the component source.",
Expand Down

0 comments on commit 932aa01

Please sign in to comment.