Skip to content

Commit

Permalink
fix(ionic): feature/component generators
Browse files Browse the repository at this point in the history
closes #152
  • Loading branch information
NathanWalker committed Oct 7, 2019
1 parent 2690aa0 commit 816ae3b
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 35 deletions.
14 changes: 5 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
<a name="8.0.9"></a>
## [8.0.9](https://github.com/nstudio/xplat/compare/8.0.7...8.0.9) (2019-10-07)

## [8.0.9](https://github.com/nstudio/xplat/compare/8.0.7...8.0.9) (2019-10-07)

### Bug Fixes

* **generators:** angular feature/component + update {N} deps ([98309eb](https://github.com/nstudio/xplat/commit/98309eb))
* **generators:** app platform ([9a99c6e](https://github.com/nstudio/xplat/commit/9a99c6e))


- **generators:** angular feature/component + update {N} deps ([98309eb](https://github.com/nstudio/xplat/commit/98309eb))
- **generators:** app platform ([9a99c6e](https://github.com/nstudio/xplat/commit/9a99c6e))

<a name="8.0.8"></a>
## [8.0.8](https://github.com/nstudio/xplat/compare/8.0.7...8.0.8) (2019-10-07)

## [8.0.8](https://github.com/nstudio/xplat/compare/8.0.7...8.0.8) (2019-10-07)

### Bug Fixes

* **generators:** angular feature/component + update {N} deps ([98309eb](https://github.com/nstudio/xplat/commit/98309eb))


- **generators:** angular feature/component + update {N} deps ([98309eb](https://github.com/nstudio/xplat/commit/98309eb))

<a name="8.0.7"></a>

Expand Down
6 changes: 6 additions & 0 deletions packages/ionic-angular/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
"aliases": ["c"],
"hidden": true
},
"feature": {
"factory": "./src/schematics/feature",
"schema": "./src/schematics/feature/schema.json",
"description": "Create an Ionic Angular feature module configured for xplat projects and shared code.",
"hidden": true
},
"xplat": {
"factory": "./src/schematics/xplat",
"schema": "./src/schematics/xplat/schema.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { <%= utils.classify(name) %>Component } from './<%= name %>/<%= name %>.component';

export const <%= subFolder ? utils.sanitize(subFolder).toUpperCase() : utils.sanitize(name).toUpperCase() %>_COMPONENTS = [
<%= utils.classify(name) %>Component
];

export * from './<%= name %>/<%= name %>.component';
113 changes: 88 additions & 25 deletions packages/ionic-angular/src/schematics/feature/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,96 @@
import { adjustSandbox, adjustRouting } from '@nstudio/angular';
import { chain, Tree, SchematicContext } from '@angular-devkit/schematics';
import { XplatFeatureHelpers, prerun } from '@nstudio/xplat';
import {
XplatFeatureHelpers,
PlatformTypes,
XplatHelpers,
prerun
} from '@nstudio/xplat';

export default function(options: XplatFeatureHelpers.Schema) {
const xplatChains = [];
xplatChains.push((tree: Tree, context: SchematicContext) =>
XplatFeatureHelpers.addFiles(options, 'ionic', null, null, 'angular')(
tree,
context
)
);
// update index
xplatChains.push((tree: Tree, context: SchematicContext) =>
XplatFeatureHelpers.adjustBarrelIndex(
options,
`xplat/ionic/features/index.ts`
)(tree, context)
);
// add starting component unless onlyModule
if (!options.onlyModule) {
xplatChains.push((tree: Tree, context: SchematicContext) =>
XplatFeatureHelpers.addFiles(
options,
const featureSettings = XplatFeatureHelpers.prepare(options);
const chains = [];

if (options.onlyProject) {
for (const projectName of featureSettings.projectNames) {
const projectParts = projectName.split('-');
const platPrefix = projectParts[0];
const platSuffix = projectParts.pop();
if (platPrefix === 'ionic' || platSuffix === 'ionic') {
// check for 2 different naming conventions on routing modules
const routingModulePathOptions = [];
const appDirectory = `apps/${projectName}/src/app/`;
routingModulePathOptions.push(`${appDirectory}app.routing.ts`);
routingModulePathOptions.push(`${appDirectory}app-routing.module.ts`);

chains.push((tree: Tree, context: SchematicContext) => {
return XplatFeatureHelpers.addFiles(options, platPrefix, projectName)(
tree,
context
);
});
if (options.routing) {
chains.push((tree: Tree, context: SchematicContext) => {
return adjustRouting(options, routingModulePathOptions, platPrefix)(
tree,
context
);
});
if (options.adjustSandbox) {
chains.push((tree: Tree, context: SchematicContext) => {
return adjustSandbox(
options,
<PlatformTypes>platPrefix,
appDirectory
)(tree, context);
});
}
}
if (!options.onlyModule) {
chains.push((tree: Tree, context: SchematicContext) => {
return XplatFeatureHelpers.addFiles(
options,
platPrefix,
projectName,
'_component'
)(tree, context);
});
}
}
}
} else {
// projectChains.push(noop());

chains.push((tree: Tree, context: SchematicContext) =>
XplatFeatureHelpers.addFiles(options, 'ionic', null, null, 'angular')(
tree,
context
)
);
// update index
chains.push((tree: Tree, context: SchematicContext) => {
const xplatFolderName = XplatHelpers.getXplatFoldername(
'ionic',
null,
'_component',
'angular'
)(tree, context)
);
);
return XplatFeatureHelpers.adjustBarrelIndex(
options,
`xplat/${xplatFolderName}/features/index.ts`
)(tree, context);
});
// add starting component unless onlyModule
if (!options.onlyModule) {
chains.push((tree: Tree, context: SchematicContext) =>
XplatFeatureHelpers.addFiles(
options,
'ionic',
null,
'_component',
'angular'
)(tree, context)
);
}
}

return chain([prerun(), ...xplatChains]);
return chain([prerun(), ...chains]);
}
5 changes: 4 additions & 1 deletion packages/xplat/src/utils/xplat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ export namespace XplatHelpers {
if (supportedFrameworks.includes(framework)) {
if (platforms.length) {
for (const platform of platforms) {
if (framework === 'angular' && (!isApp || (isApp && platform === 'web'))) {
if (
framework === 'angular' &&
(!isApp || (isApp && platform === 'web'))
) {
// Angular generators start with @nstudio/angular and branch from there
// Exception: if app generator and with web platform, also use this configuration
const packageName = `@nstudio/angular`;
Expand Down

0 comments on commit 816ae3b

Please sign in to comment.