Skip to content

Commit 0bacc61

Browse files
feat(angular): v9 support (#276)
1 parent 09e3ce6 commit 0bacc61

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+201
-575
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This repository contains schematics for generating components in NativeScript An
66

77
### Install Angular CLI
88

9-
You should be using `@angular/cli@6.1.0` or newer.
9+
You should be using `@angular/cli@9.1.0` or newer.
1010

1111
```bash
1212
npm i -g @angular/cli
@@ -141,8 +141,8 @@ This includes the following steps:
141141
In a code sharing project to build:
142142

143143
* a `web` app call: `ng serve`,
144-
* an `iOS` app call: `tns run ios --bundle`,
145-
* an `Android` app call: `tns run android --bundle`
144+
* an `iOS` app call: `tns run ios --bundle --env.aot`,
145+
* an `Android` app call: `tns run android --bundle --env.aot`
146146

147147
## Templates
148148

package.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/schematics",
3-
"version": "1.0.0",
3+
"version": "9.0.0",
44
"description": "Schematics for NativeScript Angular apps.",
55
"scripts": {
66
"build": "tsc -p tsconfig.json",
@@ -17,20 +17,21 @@
1717
},
1818
"schematics": "./src/collection.json",
1919
"dependencies": {
20-
"@angular-devkit/core": "~8.2.0",
21-
"@angular-devkit/schematics": "~8.2.0",
22-
"@nativescript/tslint-rules": "~0.0.3",
23-
"@phenomnomnominal/tsquery": "^3.0.0"
20+
"@angular-devkit/core": "~9.1.0",
21+
"@angular-devkit/schematics": "~9.1.0",
22+
"@nativescript/tslint-rules": "~0.0.5",
23+
"@phenomnomnominal/tsquery": "^4.1.0"
2424
},
2525
"devDependencies": {
26-
"@schematics/angular": "~8.2.0",
27-
"@types/jasmine": "^2.6.0",
28-
"@types/node": "^8.0.31",
26+
"@schematics/angular": "~9.1.0",
27+
"@types/jasmine": "~3.5.0",
28+
"@types/jasminewd2": "~2.0.3",
29+
"@types/node": "^12.11.1",
2930
"conventional-changelog-cli": "^2.0.1",
3031
"jasmine": "^2.8.0",
3132
"jasmine-spec-reporter": "^4.2.1",
32-
"tslint": "^5.18.0",
33-
"typescript": "3.5.3"
33+
"tslint": "~6.1.0",
34+
"typescript": "~3.8.3"
3435
},
3536
"repository": {
3637
"type": "git",
@@ -55,4 +56,4 @@
5556
"Sebastian Witalec <[email protected]>"
5657
],
5758
"license": "Apache-2.0"
58-
}
59+
}

src/add-ns/_ns-files/__sourceDir__/app/__entryModuleName@dasherize__.module__nsext__.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2-
import { NativeScriptModule } from 'nativescript-angular/nativescript.module';
2+
import { NativeScriptModule } from '@nativescript/angular';
33

44
import { AppRoutingModule } from './app-routing.module<%= nsext %>';
55
import { <%= entryComponentClassName %> } from '<%= entryComponentImportPath %>';
66
<% if (sample) { %>
77
import { BarcelonaModule } from './barcelona/barcelona.module';<% } %>
88

9-
// Uncomment and add to NgModule imports if you need to use two-way binding
10-
// import { NativeScriptFormsModule } from 'nativescript-angular/forms';
11-
12-
// Uncomment and add to NgModule imports if you need to use the HTTP wrapper
13-
// import { NativeScriptHttpClientModule } from 'nativescript-angular/http-client';
9+
// Uncomment and add to NgModule imports if you need to use two-way binding and/or HTTP wrapper
10+
// import { NativeScriptFormsModule, NativeScriptHttpClientModule } from '@nativescript/angular';
1411

1512
@NgModule({
1613
declarations: [

src/add-ns/_ns-files/__sourceDir__/app/app-routing.module__nsext__.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NgModule } from '@angular/core';
2-
import { NativeScriptRouterModule } from 'nativescript-angular/router';
2+
import { NativeScriptRouterModule } from '@nativescript/angular';
33
import { Routes } from '@angular/router';
44
<% if (!skipAutoGeneratedComponent) { %>
55
import { AutoGeneratedComponent } from './auto-generated/auto-generated.component';

src/add-ns/_ns-files/__sourceDir__/main__nsext__.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// this import should be first in order to load some required settings (like globals and reflect-metadata)
2-
import { platformNativeScriptDynamic } from 'nativescript-angular/platform';
2+
import { platformNativeScriptDynamic } from '@nativescript/angular/platform';
33

44
import { <%= entryModuleClassName %> } from '<%= entryModuleImportPath %>';
55

src/add-ns/_ns-files/ngcc.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
packages: {
3+
"@nativescript/angular": {
4+
entryPoints: {
5+
".": {
6+
override: {
7+
main: "./index.js",
8+
typings: "./index.d.ts",
9+
},
10+
ignoreMissingDependencies: true,
11+
}
12+
},
13+
ignorableDeepImportMatchers: [
14+
/tns-core-modules\//,
15+
/@nativescript\/core\//,
16+
]
17+
}
18+
}
19+
};

src/add-ns/_ns-files/tsconfig__nsext__.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"module": "es2015",
4+
"module": "ESNext",
55
"moduleResolution": "node",
66
"skipLibCheck": true,
77
"paths": {

src/add-ns/_sample-files/barcelona/barcelona.module__nsext__.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2-
import { NativeScriptCommonModule } from 'nativescript-angular/common';
3-
import { NativeScriptRouterModule } from 'nativescript-angular/router';
2+
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
43

54
import {
65
componentDeclarations,
@@ -11,7 +10,6 @@ import {
1110
@NgModule({
1211
imports: [
1312
NativeScriptCommonModule,
14-
NativeScriptRouterModule,
1513
NativeScriptRouterModule.forRoot(routes)
1614
],
1715
exports: [

src/add-ns/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,12 @@ const addRunScriptsToPackageJson = (tree: Tree, context: SchematicContext) => {
223223
const packageJson = getPackageJson(tree);
224224

225225
const scriptsToAdd = {
226-
android: 'tns run android',
227-
ios: 'tns run ios',
226+
android: 'tns run android --env.aot',
227+
ios: 'tns run ios --env.aot',
228228
mobile: 'tns run',
229229
preview: 'tns preview',
230+
ngcc: 'ngcc --properties es2015 module main --first-only',
231+
postinstall: 'npm run ngcc'
230232
};
231233
packageJson.scripts = {...scriptsToAdd, ...packageJson.scripts};
232234

@@ -362,17 +364,17 @@ const addDependencies = () => (tree: Tree, context: SchematicContext) => {
362364

363365
// @UPGRADE: Update all versions whenever {N} version updates
364366
const depsToAdd = {
365-
'nativescript-angular': '~8.20.0',
367+
'@nativescript/angular': '~9.0.0',
368+
'@nativescript/core': '~6.5.5',
366369
'@nativescript/theme': '~2.2.1',
367370
'reflect-metadata': '~0.1.12',
368-
'tns-core-modules': '~6.3.0',
369371
'tslib': '1.10.0',
370372
};
371373
packageJson.dependencies = {...depsToAdd, ...packageJson.dependencies};
372374

373375
const devDepsToAdd = {
374-
'nativescript-dev-webpack': '~1.4.0',
375-
'@nativescript/schematics': '~1.0.0',
376+
'nativescript-dev-webpack': '~1.5.0',
377+
'@nativescript/schematics': '~2.0.0',
376378
'@nativescript/tslint-rules': '~0.0.5',
377379
};
378380
packageJson.devDependencies = {...devDepsToAdd, ...packageJson.devDependencies};

src/add-ns/index_spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getFileContent } from '@schematics/angular/utility/test';
88

99
describe('Add {N} schematic', () => {
1010
const schematicRunner = new SchematicTestRunner(
11-
'nativescript-schematics',
11+
'@nativescript/schematics',
1212
resolve(__dirname, '../collection.json'),
1313
);
1414
const project = 'foo';
@@ -44,6 +44,7 @@ describe('Add {N} schematic', () => {
4444
it('should add {N} specific files', () => {
4545
const files = appTree.files;
4646

47+
expect(files).toContain('/ngcc.config.js');
4748
expect(files).toContain('/nsconfig.json');
4849
expect(files).toContain('/tsconfig.tns.json');
4950
expect(files).toContain('/src/app.css');
@@ -77,9 +78,9 @@ describe('Add {N} schematic', () => {
7778
const packageJson = JSON.parse(getFileContent(appTree, packageJsonPath));
7879
const { dependencies, devDependencies } = packageJson;
7980
expect(dependencies).toBeDefined();
80-
expect(dependencies['nativescript-angular']).toBeDefined();
81+
expect(dependencies['@nativescript/angular']).toBeDefined();
8182
expect(dependencies['@nativescript/theme']).toBeDefined();
82-
expect(dependencies['tns-core-modules']).toBeDefined();
83+
expect(dependencies['@nativescript/core']).toBeDefined();
8384
expect(dependencies['reflect-metadata']).toBeDefined();
8485

8586
expect(devDependencies['nativescript-dev-webpack']).toBeDefined();
@@ -94,8 +95,10 @@ describe('Add {N} schematic', () => {
9495
const packageJson = JSON.parse(getFileContent(appTree, packageJsonPath));
9596
const { scripts } = packageJson;
9697
expect(scripts).toBeDefined();
97-
expect(scripts.android).toEqual('tns run android');
98-
expect(scripts.ios).toEqual('tns run ios');
98+
expect(scripts.android).toEqual('tns run android --env.aot');
99+
expect(scripts.ios).toEqual('tns run ios --env.aot');
100+
expect(scripts.ngcc).toEqual('ngcc --properties es2015 module main --first-only');
101+
expect(scripts.postinstall).toEqual('npm run ngcc');
99102
});
100103

101104
it('should add NativeScript key to the package json', () => {

src/angular-json/index_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Schema as angularJsonOptions } from './schema';
55

66
describe('Angular JSON Config Schematic', () => {
77
const schematicRunner = new SchematicTestRunner(
8-
'nativescript-schematics',
8+
'@nativescript/schematics',
99
path.join(__dirname, '../collection.json'),
1010
);
1111

src/collection.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@
6868
"schema": "./add-ns/schema.json"
6969
},
7070

71-
"refactor-nsng-modules": {
72-
"factory": "./refactor-nsng-modules",
73-
"description": "Upgrades existing {N} Angular projects.",
74-
"schema": "./refactor-nsng-modules/schema.json"
75-
},
76-
7771
"class": {
7872
"aliases": [ "cl" ],
7973
"extends": "@schematics/angular:class"

src/convert-relative-imports/index_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const fixedImportContent = `
2727

2828
describe('Convert relative imports to mapped imports', () => {
2929
const schematicRunner = new SchematicTestRunner(
30-
'nativescript-schematics',
30+
'@nativescript/schematics',
3131
join(__dirname, '../collection.json'),
3232
);
3333

src/generate-template/master-detail/_files-nsonly/__name__/__master__.module.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
22
import { Routes } from '@angular/router';
3-
import { NativeScriptCommonModule } from 'nativescript-angular/common';
4-
import { NativeScriptRouterModule } from 'nativescript-angular/router';
3+
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
54

65
import { <%= masterClassName %>Component } from './<%= master %>/<%= master %>.component';
76
import { <%= detailClassName %>DetailComponent } from './<%= detail %>-detail/<%= detail %>-detail.component';
@@ -14,7 +13,6 @@ export const routes: Routes = [
1413
@NgModule({
1514
imports: [
1615
NativeScriptCommonModule,
17-
NativeScriptRouterModule,
1816
NativeScriptRouterModule.forRoot(routes)
1917
],
2018
exports: [

src/generate-template/master-detail/_files-shared/__name__/__master__.module__nsext__.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2-
import { NativeScriptCommonModule } from 'nativescript-angular/common';
3-
import { NativeScriptRouterModule } from 'nativescript-angular/router';
2+
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
43

54
import {
65
componentDeclarations,
@@ -10,7 +9,6 @@ import {
109
@NgModule({
1110
imports: [
1211
NativeScriptCommonModule,
13-
NativeScriptRouterModule,
1412
NativeScriptRouterModule.forRoot(routes)
1513
],
1614
exports: [

src/generate-template/master-detail/index_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('Master-detail schematic', () => {
2424
};
2525

2626
const schematicRunner = new SchematicTestRunner(
27-
'nativescript-schematics',
27+
'@nativescript/schematics',
2828
join(__dirname, '../../collection.json'),
2929
);
3030

src/generate/component/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export default function(options: ComponentOptions): Rule {
5555
}
5656

5757
const projectObject = getProjectObject(tree, options.project);
58-
const styleext = (projectObject && projectObject.schematics && projectObject.schematics['@schematics/angular:component']
58+
const style = (projectObject && projectObject.schematics && projectObject.schematics['@schematics/angular:component']
5959
&& projectObject.schematics['@schematics/angular:component'].style);
60-
if (styleext) {
61-
options.styleext = styleext;
60+
if (style) {
61+
options.style = style;
6262
}
6363

6464
validateGenerateOptions(platformUse, options);
@@ -162,7 +162,7 @@ const parseComponentInfo = (tree: Tree, options: ComponentOptions): ComponentInf
162162
const templateName = `/${component.name}.component.html`;
163163
component.templatePath = getGeneratedFilePath(templateName);
164164

165-
const stylesheetName = `/${component.name}.component.${options.styleext}`;
165+
const stylesheetName = `/${component.name}.component.${options.style}`;
166166
component.stylesheetPath = getGeneratedFilePath(stylesheetName);
167167

168168
return component;

src/generate/component/index_spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Component Schematic', () => {
2121

2222
const defaultOptions: ComponentOptions = { name, project };
2323
const schematicRunner = new SchematicTestRunner(
24-
'nativescript-schematics',
24+
'@nativescript/schematics',
2525
join(__dirname, '../../collection.json'),
2626
);
2727

@@ -34,8 +34,8 @@ describe('Component Schematic', () => {
3434
const nsTemplatePath = getTemplatePath(DEFAULT_SHARED_EXTENSIONS.ns);
3535
const webTemplatePath = getTemplatePath(DEFAULT_SHARED_EXTENSIONS.web);
3636

37-
const getStylesheetPath = (extension: string, styleExtension: string = 'css') =>
38-
`src/app/${name}/${name}.component${extension}.${styleExtension}`;
37+
const getStylesheetPath = (extension: string, style: string = 'css') =>
38+
`src/app/${name}/${name}.component${extension}.${style}`;
3939
const noExtensionStylesheetPath = getStylesheetPath('');
4040
const nsStylesheetPath = getStylesheetPath(DEFAULT_SHARED_EXTENSIONS.ns);
4141
const webStylesheetPath = getStylesheetPath(DEFAULT_SHARED_EXTENSIONS.web);
@@ -217,11 +217,11 @@ describe('Component Schematic', () => {
217217
});
218218

219219
it('should respect specified style extension', async () => {
220-
const styleext = 'scss';
221-
const options = { ...defaultOptions, nsExtension: customExtension, styleext, nativescript: true };
220+
const style = 'scss';
221+
const options = { ...defaultOptions, nsExtension: customExtension, style, nativescript: true };
222222
appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise();
223223

224-
const componentStylesheetPath = getStylesheetPath(customExtension, styleext);
224+
const componentStylesheetPath = getStylesheetPath(customExtension, style);
225225
expect(appTree.exists(componentStylesheetPath)).toBeTruthy();
226226
});
227227
});

src/generate/component/schema.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface Schema {
6060
/**
6161
* The file extension to be used for style files.
6262
*/
63-
styleext?: string;
63+
style?: string;
6464
/**
6565
* Specifies if a spec file is generated.
6666
*/

src/generate/component/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
}
8585
]
8686
},
87-
"styleext": {
87+
"style": {
8888
"description": "The file extension to be used for style files.",
8989
"type": "string",
9090
"default": "css"

src/generate/module/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ const ensureNsRouting = (tree: Tree, path: string) => {
228228

229229
const importFrom = `, NativeScriptRouterModule } from '@angular/router';`;
230230
const importTo = ` } from '@angular/router';
231-
import { NativeScriptRouterModule } from 'nativescript-angular/router';`;
231+
import { NativeScriptRouterModule } from '@nativescript/angular';`;
232232

233233
const newText = fileText.replace(/RouterModule/g, 'NativeScriptRouterModule')
234234
.replace(importFrom, importTo);
@@ -270,7 +270,7 @@ const addNSRouterModule = (tree: Tree, routingModulePath: string) => {
270270
const addedImport = addSymbolToNgModuleMetadata(
271271
moduleSource, routingModulePath,
272272
'imports', `${moduleName}.forChild(routes)`,
273-
'nativescript-angular/router'
273+
'@nativescript/angular'
274274
);
275275
const importRecorder = tree.beginUpdate(routingModulePath);
276276
@@ -335,7 +335,7 @@ const addNSCommonModule = (tree: Tree, modulePath: string) => {
335335
const metadataChange = addSymbolToNgModuleMetadata(
336336
moduleSource, modulePath,
337337
'imports', 'NativeScriptCommonModule',
338-
'nativescript-angular/common');
338+
'@nativescript/angular');
339339

340340
metadataChange.forEach((change: InsertChange) =>
341341
recorder.insertRight(change.pos, change.toAdd),

0 commit comments

Comments
 (0)