@ionic/angular-toolkit
Advanced tools
Comparing version 8.0.0 to 8.1.0
@@ -6,2 +6,14 @@ # Change Log | ||
# [8.1.0](https://github.com/ionic-team/angular-toolkit/compare/@ionic/angular-toolkit@8.0.0...@ionic/angular-toolkit@8.1.0) (2023-03-28) | ||
### Features | ||
* add support for standalone pages ([5523f7a](https://github.com/ionic-team/angular-toolkit/commit/5523f7a8b891b86a0db0ab7781529211cd6a9d83)) | ||
* **page:** add large header ([e018d4a](https://github.com/ionic-team/angular-toolkit/commit/e018d4ae29726d3ab2bf4cf9f372b1ca95df610b)) | ||
# [8.0.0](https://github.com/ionic-team/angular-toolkit/compare/@ionic/angular-toolkit@7.0.0...@ionic/angular-toolkit@8.0.0) (2023-02-15) | ||
@@ -8,0 +20,0 @@ |
{ | ||
"name": "@ionic/angular-toolkit", | ||
"version": "8.0.0", | ||
"version": "8.1.0", | ||
"license": "MIT", | ||
@@ -47,3 +47,3 @@ "description": "Schematics for @ionic/angular apps.", | ||
"schematics": "./collection.json", | ||
"gitHead": "35483be48ae4ef8b1837581a1f413914c72af770" | ||
"gitHead": "bba93029b0bc56ce76f62be7da565c095e52d49c" | ||
} |
@@ -1,4 +0,2 @@ | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { IonicModule } from '@ionic/angular'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { <%= classify(name) %>Page } from './<%= dasherize(name) %>.page'; | ||
@@ -10,8 +8,3 @@ | ||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ <%= classify(name) %>Page ], | ||
imports: [IonicModule.forRoot()] | ||
}).compileComponents(); | ||
beforeEach(async(() => { | ||
fixture = TestBed.createComponent(<%= classify(name) %>Page); | ||
@@ -18,0 +11,0 @@ component = fixture.componentInstance; |
import { Component, OnInit } from '@angular/core';<% if(routePath) { %> | ||
import { ActivatedRoute, Params } from '@angular/router';<% } %> | ||
import { ActivatedRoute, Params } from '@angular/router';<% } %><% if(standalone) {%> | ||
import { CommonModule } from '@angular/common'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { IonicModule } from '@ionic/angular';<%} %> | ||
@@ -7,3 +10,5 @@ @Component({ | ||
templateUrl: './<%= dasherize(name) %>.page.html', | ||
styleUrls: ['./<%= dasherize(name) %>.page.<%= styleext %>'], | ||
styleUrls: ['./<%= dasherize(name) %>.page.<%= styleext %>'],<% if(standalone) {%> | ||
standalone: true, | ||
imports: [IonicModule, CommonModule, FormsModule]<%} %> | ||
}) | ||
@@ -10,0 +15,0 @@ export class <%= classify(name) %>Page implements OnInit {<% if(routePath) { %> |
@@ -5,110 +5,7 @@ "use strict"; | ||
const schematics_1 = require("@angular-devkit/schematics"); | ||
const find_module_1 = require("@schematics/angular/utility/find-module"); | ||
const parse_name_1 = require("@schematics/angular/utility/parse-name"); | ||
const validation_1 = require("@schematics/angular/utility/validation"); | ||
const workspace_1 = require("@schematics/angular/utility/workspace"); | ||
const ts = require("typescript"); | ||
const util_1 = require("../util"); | ||
const ast_util_1 = require("../util/ast-util"); | ||
const change_1 = require("../util/change"); | ||
function findRoutingModuleFromOptions(host, options) { | ||
// eslint-disable-next-line no-prototype-builtins | ||
if (options.hasOwnProperty('skipImport') && options.skipImport) { | ||
return undefined; | ||
} | ||
if (!options.module) { | ||
const pathToCheck = (options.path || '') + (options.flat ? '' : '/' + core_1.strings.dasherize(options.name)); | ||
return (0, core_1.normalize)(findRoutingModule(host, pathToCheck)); | ||
} | ||
else { | ||
const modulePath = (0, core_1.normalize)('/' + options.path + '/' + options.module); | ||
const moduleBaseName = (0, core_1.normalize)(modulePath).split('/').pop(); | ||
if (host.exists(modulePath)) { | ||
return (0, core_1.normalize)(modulePath); | ||
} | ||
else if (host.exists(modulePath + '.ts')) { | ||
return (0, core_1.normalize)(modulePath + '.ts'); | ||
} | ||
else if (host.exists(modulePath + '.module.ts')) { | ||
return (0, core_1.normalize)(modulePath + '.module.ts'); | ||
} | ||
else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) { | ||
return (0, core_1.normalize)(modulePath + '/' + moduleBaseName + '.module.ts'); | ||
} | ||
else { | ||
throw new Error('Specified module does not exist'); | ||
} | ||
} | ||
} | ||
function findRoutingModule(host, generateDir) { | ||
let dir = host.getDir('/' + generateDir); | ||
const routingModuleRe = /-routing\.module\.ts/; | ||
while (dir) { | ||
const matches = dir.subfiles.filter((p) => routingModuleRe.test(p)); | ||
if (matches.length === 1) { | ||
return (0, core_1.join)(dir.path, matches[0]); | ||
} | ||
else if (matches.length > 1) { | ||
throw new Error('More than one module matches. Use skip-import option to skip importing ' + | ||
'the component into the closest module.'); | ||
} | ||
dir = dir.parent; | ||
} | ||
throw new Error('Could not find an NgModule. Use the skip-import ' + 'option to skip importing in NgModule.'); | ||
} | ||
function addRouteToNgModule(options) { | ||
const { module } = options; | ||
if (!module) { | ||
throw new schematics_1.SchematicsException('module option is required.'); | ||
} | ||
return (host) => { | ||
const text = host.read(module); | ||
if (!text) { | ||
throw new schematics_1.SchematicsException(`File ${module} does not exist.`); | ||
} | ||
const sourceText = text.toString('utf8'); | ||
const source = ts.createSourceFile(module, sourceText, ts.ScriptTarget.Latest, true); | ||
const pagePath = `/${options.path}/` + | ||
(options.flat ? '' : `${core_1.strings.dasherize(options.name)}/`) + | ||
`${core_1.strings.dasherize(options.name)}.module`; | ||
const relativePath = (0, find_module_1.buildRelativePath)(module, pagePath); | ||
const routePath = core_1.strings.dasherize(options.routePath ? options.routePath : options.name); | ||
const ngModuleName = `${core_1.strings.classify(options.name)}PageModule`; | ||
const changes = addRouteToRoutesArray(source, module, routePath, relativePath, ngModuleName); | ||
const recorder = host.beginUpdate(module); | ||
for (const change of changes) { | ||
if (change instanceof change_1.InsertChange) { | ||
recorder.insertLeft(change.pos, change.toAdd); | ||
} | ||
} | ||
host.commitUpdate(recorder); | ||
return host; | ||
}; | ||
} | ||
function addRouteToRoutesArray(source, ngModulePath, routePath, routeLoadChildren, ngModuleName) { | ||
const keywords = (0, ast_util_1.findNodes)(source, ts.SyntaxKind.VariableStatement); | ||
for (const keyword of keywords) { | ||
if (ts.isVariableStatement(keyword)) { | ||
const [declaration] = keyword.declarationList.declarations; | ||
if (ts.isVariableDeclaration(declaration) && declaration.initializer && declaration.name.getText() === 'routes') { | ||
const node = declaration.initializer.getChildAt(1); | ||
const lastRouteNode = node.getLastToken(); | ||
if (!lastRouteNode) { | ||
return []; | ||
} | ||
const changes = []; | ||
let trailingCommaFound = false; | ||
if (lastRouteNode.kind === ts.SyntaxKind.CommaToken) { | ||
trailingCommaFound = true; | ||
} | ||
else { | ||
changes.push(new change_1.InsertChange(ngModulePath, lastRouteNode.getEnd(), ',')); | ||
} | ||
changes.push(new change_1.InsertChange(ngModulePath, lastRouteNode.getEnd() + 1, ` {\n path: '${routePath}',\n loadChildren: () => import('${routeLoadChildren}').then( m => m.${ngModuleName})\n }${trailingCommaFound ? ',' : ''}\n`)); | ||
return changes; | ||
} | ||
} | ||
} | ||
return []; | ||
} | ||
const route_utils_1 = require("./route-utils"); | ||
function default_1(options) { | ||
@@ -125,3 +22,5 @@ return async (host) => { | ||
} | ||
options.module = findRoutingModuleFromOptions(host, options); | ||
if (!options.standalone) { | ||
options.module = (0, route_utils_1.findRoutingModuleFromOptions)(host, options); | ||
} | ||
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name); | ||
@@ -134,2 +33,3 @@ options.name = parsedPath.name; | ||
options.spec ? (0, schematics_1.noop)() : (0, schematics_1.filter)((p) => !p.endsWith('.spec.ts')), | ||
options.standalone ? (0, schematics_1.filter)((p) => !p.endsWith('module.ts')) : (0, schematics_1.noop)(), | ||
(0, schematics_1.template)({ | ||
@@ -142,5 +42,7 @@ ...core_1.strings, | ||
]); | ||
return (0, schematics_1.chain)([(0, schematics_1.branchAndMerge)((0, schematics_1.chain)([addRouteToNgModule(options), (0, schematics_1.mergeWith)(templateSource)]))]); | ||
return (0, schematics_1.chain)([ | ||
(0, schematics_1.branchAndMerge)((0, schematics_1.chain)([options.standalone ? (0, route_utils_1.addRoute)(options) : (0, route_utils_1.addRouteToNgModule)(options), (0, schematics_1.mergeWith)(templateSource)])), | ||
]); | ||
}; | ||
} | ||
exports.default = default_1; |
@@ -12,2 +12,3 @@ export interface Schema { | ||
routePath?: string; | ||
standalone?: boolean; | ||
} |
@@ -74,2 +74,7 @@ { | ||
"default": "" | ||
}, | ||
"standalone": { | ||
"type": "boolean", | ||
"description": "Specifies if the page should be standalone", | ||
"default": false | ||
} | ||
@@ -76,0 +81,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59622
27
1281