Skip to content

Commit

Permalink
refactoring layout and component schematics to support nested folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperxq committed Mar 22, 2024
1 parent 6206b06 commit eaf7f0b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
MergeStrategy,
Tree,
} from '@angular-devkit/schematics';
import { parseName } from '../../utils';

// name, addSlot
export function componentFactory({ name, addSlot }: { name: string; addSlot: boolean }): Rule {
return (tree: Tree) => {
const { path, name: componentName } = parseName('./', name);

let basePath = './src';

if (!tree.getDir('/').subdirs.find((f) => f === 'src')) {
Expand All @@ -26,12 +28,12 @@ export function componentFactory({ name, addSlot }: { name: string; addSlot: boo
const template = apply(url('./files'), [
filter((path) => urlTemplates.some((urlTemplate) => path.includes(urlTemplate))),
applyTemplates({
name,
name: componentName,
addSlot,
...strings,
}),
renameTemplateFiles(),
move(basePath),
move(`${basePath}${path ?? ''}`),
]);
return mergeWith(template, MergeStrategy.Overwrite);
};
Expand Down
6 changes: 4 additions & 2 deletions packages/astro/src/builder-generate/layout/layout.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
MergeStrategy,
Tree,
} from '@angular-devkit/schematics';
import { parseName } from '../../utils';

// name, addSlot
export function layoutFactory({ name }: { name: string }): Rule {
return (tree: Tree) => {
const { path, name: layoutName } = parseName('./', name);
let basePath = './src';

if (!tree.getDir('/').subdirs.find((f) => f === 'src')) {
Expand All @@ -26,11 +28,11 @@ export function layoutFactory({ name }: { name: string }): Rule {
const template = apply(url('./files'), [
filter((path) => urlTemplates.some((urlTemplate) => path.includes(urlTemplate))),
applyTemplates({
name,
name: layoutName,
...strings,
}),
renameTemplateFiles(),
move(basePath),
move(`${basePath}${path ?? ''}`),
]);
return mergeWith(template, MergeStrategy.Overwrite);
};
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/builder-generate/page/page.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ function addPageFile(

const pageTypes = {
astro: '__name@classify__.astro.template',
md: '__pageName@classify__.md.template',
mdx: '__pageName@classify__.mdx.template',
md: '__name@classify__.md.template',
mdx: '__name@classify__.mdx.template',
};

const urlTemplates = [pageTypes[fileType]];
Expand All @@ -115,7 +115,7 @@ function addPageFile(
...strings,
}),
renameTemplateFiles(),
move(`${basePath}${pagePath}`),
move(`${basePath}${pagePath ?? ''}`),
]);
return mergeWith(template, MergeStrategy.Overwrite);
}

0 comments on commit eaf7f0b

Please sign in to comment.