Skip to content

Commit 55fa354

Browse files
authored
feat(angular): v10 support (#286)
1 parent b5678dd commit 55fa354

37 files changed

+211
-219
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.spec.js
88
*.js.map
99
tsconfig.json
10+
*.tgz
1011

1112
/jasmine-config
1213

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 --env.aot`,
145-
* an `Android` app call: `tns run android --env.aot`
144+
* an `iOS` app call: `tns run ios`,
145+
* an `Android` app call: `tns run android`
146146

147147
## Templates
148148

package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "@nativescript/schematics",
3-
"version": "9.0.0",
3+
"version": "10.0.1",
44
"description": "Schematics for NativeScript Angular apps.",
55
"scripts": {
6+
"clean": "npx rimraf node_modules package-lock.json && npm i",
67
"build": "tsc -p tsconfig.json",
78
"watch": "tsc -w -p tsconfig.json",
89
"test": "npm run build && npm run jasmine",
@@ -23,21 +24,23 @@
2324
},
2425
"schematics": "./src/collection.json",
2526
"dependencies": {
26-
"@angular-devkit/core": "~9.1.0",
27-
"@angular-devkit/schematics": "~9.1.0",
27+
"@angular-devkit/core": "~10.0.0",
28+
"@angular-devkit/schematics": "~10.0.0",
2829
"@nativescript/tslint-rules": "~0.0.5",
29-
"@phenomnomnominal/tsquery": "^4.1.0"
30+
"@phenomnomnominal/tsquery": "^4.1.0",
31+
"strip-json-comments": "~3.1.1"
3032
},
3133
"devDependencies": {
32-
"@schematics/angular": "~9.1.0",
34+
"@angular/cli": "~10.0.0",
35+
"@schematics/angular": "~10.0.0",
3336
"@types/jasmine": "~3.5.0",
3437
"@types/jasminewd2": "~2.0.3",
3538
"@types/node": "^12.11.1",
3639
"conventional-changelog-cli": "^2.0.1",
37-
"jasmine": "^2.8.0",
38-
"jasmine-spec-reporter": "^4.2.1",
40+
"jasmine": "^3.5.0",
41+
"jasmine-spec-reporter": "^5.0.2",
3942
"tslint": "~6.1.0",
40-
"typescript": "~3.8.3"
43+
"typescript": "~3.9.0"
4144
},
4245
"repository": {
4346
"type": "git",
@@ -60,7 +63,8 @@
6063
"contributors": [
6164
"Stanimira Vlaeva <[email protected]>",
6265
"Sebastian Witalec <[email protected]>",
63-
"Danny Koppenhagen <d-koppenhagen>"
66+
"Danny Koppenhagen <d-koppenhagen>",
67+
"NativeScript Team <[email protected]>"
6468
],
6569
"license": "Apache-2.0"
6670
}
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
<!-- https://docs.nativescript.org/angular/core-concepts/angular-navigation.html#page-router-outlet -->
2-
<page-router-outlet></page-router-outlet>
3-
<% if (skipAutoGeneratedComponent && !sample) { %><Label text="Entry Component works" textWrap="true"></Label>
4-
<% } %>
1+
<GridLayout>
2+
<!-- This will contain any angular routes you setup -->
3+
<page-router-outlet></page-router-outlet>
4+
5+
<% if (skipAutoGeneratedComponent && !sample) { %>
6+
<!-- This is just a fun sample for you to play with :) -->
7+
<StackLayout verticalAlignment="center" (loaded)="loadedSuccess($event)" opacity="0">
8+
<Label text="Sweet!" textWrap="true" class="h2 text-center"></Label>
9+
<Label text="You should try adding some routes." class="h3 text-center"></Label>
10+
</StackLayout>
11+
<StackLayout verticalAlignment="center" (loaded)="loadedContainer($event)">
12+
<Label text="Congrats! It works" textWrap="true" class="h2 text-center"></Label>
13+
<Button text="Keep Tapping for a Surprise!" textWrap="true" class="-primary" (tap)="tapMe()"></Button>
14+
<Label [text]="'You have ' + cnt + ' taps left.'" class="h3 text-center"></Label>
15+
</StackLayout>
16+
<% } %>
17+
18+
</GridLayout>
Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,45 @@
1-
import { Component } from '@angular/core';
1+
import { Component } from '@angular/core';<% if (skipAutoGeneratedComponent && !sample) { %>
2+
import { StackLayout, Enums } from '@nativescript/core';<% } %>
23

34
@Component({
45
selector: '<%= indexAppRootTag %>',
56
templateUrl: '<%= entryComponentImportPath %>.html',
67
})
8+
export class <%= entryComponentClassName %> {
9+
<% if (skipAutoGeneratedComponent && !sample) { %>
10+
title = 'NativeScript';
11+
cnt = 3;
12+
private messageLayout: StackLayout;
13+
private successLayout: StackLayout;
714

8-
export class <%= entryComponentClassName %> { }
15+
tapMe() {
16+
this.cnt--;
17+
if (this.cnt === 0) {
18+
this.messageLayout
19+
.animate({
20+
translate: { x: 0, y: 150 },
21+
opacity: 0,
22+
duration: 400,
23+
curve: Enums.AnimationCurve.easeOut,
24+
})
25+
.then(() => {
26+
this.successLayout.translateY = 150;
27+
this.successLayout.animate({
28+
translate: { x: 0, y: 0 },
29+
opacity: 1,
30+
duration: 300,
31+
curve: Enums.AnimationCurve.easeInOut,
32+
});
33+
});
34+
}
35+
}
36+
37+
loadedContainer(args) {
38+
this.messageLayout = args.object;
39+
}
40+
41+
loadedSuccess(args) {
42+
this.successLayout = args.object;
43+
}
44+
<% } %>
45+
}

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';
33

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

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
"appPath": "<%= sourceDir %>",
44
"nsext": "<%= nsext %>",
55
"webext": "<%= webext %>",
6-
"shared": true,
7-
"useLegacyWorkflow": false
6+
"shared": true
87
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"compilerOptions": {
44
"module": "ESNext",
55
"moduleResolution": "node",
6+
"experimentalDecorators": true,
67
"skipLibCheck": true,
8+
"baseUrl": ".",
79
"paths": {
810
"@src/*": [
911
"<%= sourceDir %>/*.tns.ts",

src/add-ns/index.ts

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

225225
const scriptsToAdd = {
226-
android: 'tns run android --env.aot',
227-
ios: 'tns run ios --env.aot',
226+
android: 'tns run android --no-hmr',
227+
ios: 'tns run ios --no-hmr',
228228
mobile: 'tns run',
229229
preview: 'tns preview',
230230
ngcc: 'ngcc --properties es2015 module main --first-only',
@@ -364,16 +364,16 @@ const addDependencies = () => (tree: Tree, context: SchematicContext) => {
364364

365365
// @UPGRADE: Update all versions whenever {N} version updates
366366
const depsToAdd = {
367-
'@nativescript/angular': '~9.0.0',
368-
'@nativescript/core': '~6.5.5',
367+
'@nativescript/angular': '~10.0.0',
368+
'@nativescript/core': 'rc',
369369
'@nativescript/theme': '~2.2.1',
370370
'reflect-metadata': '~0.1.12',
371371
tslib: '1.10.0',
372372
};
373373
packageJson.dependencies = {...depsToAdd, ...packageJson.dependencies};
374374

375375
const devDepsToAdd = {
376-
'nativescript-dev-webpack': '~1.5.0',
376+
'@nativescript/webpack': '~2.0.0',
377377
'@nativescript/tslint-rules': '~0.0.5',
378378
};
379379
packageJson.devDependencies = {...devDepsToAdd, ...packageJson.devDependencies};

src/add-ns/index_spec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/te
55

66
import { Schema as AddNsOptions } from './schema';
77
import { getFileContent } from '@schematics/angular/utility/test';
8+
import * as stripJsonComments from 'strip-json-comments';
89

910
describe('Add {N} schematic', () => {
1011
const schematicRunner = new SchematicTestRunner(
@@ -36,15 +37,14 @@ describe('Add {N} schematic', () => {
3637
it('should add dependency to NativeScript schematics', () => {
3738
const configFile = '/angular.json';
3839
expect(appTree.files).toContain(configFile);
39-
const configFileContent = JSON.parse(getFileContent(appTree, configFile));
40+
const configFileContent = JSON.parse(stripJsonComments(getFileContent(appTree, configFile)));
4041

41-
expect(configFileContent.cli.defaultCollection).toEqual('@nativescript/schematics');
42+
expect(configFileContent.cli.defaultCollection).toBe('@nativescript/schematics');
4243
});
4344

4445
it('should add {N} specific files', () => {
4546
const files = appTree.files;
4647

47-
expect(files).toContain('/ngcc.config.js');
4848
expect(files).toContain('/nsconfig.json');
4949
expect(files).toContain('/tsconfig.tns.json');
5050
expect(files).toContain('/src/app.css');
@@ -75,27 +75,27 @@ describe('Add {N} schematic', () => {
7575
const packageJsonPath = '/package.json';
7676
expect(appTree.files).toContain(packageJsonPath);
7777

78-
const packageJson = JSON.parse(getFileContent(appTree, packageJsonPath));
78+
const packageJson = JSON.parse(stripJsonComments(getFileContent(appTree, packageJsonPath)));
7979
const { dependencies, devDependencies } = packageJson;
8080
expect(dependencies).toBeDefined();
8181
expect(dependencies['@nativescript/angular']).toBeDefined();
8282
expect(dependencies['@nativescript/theme']).toBeDefined();
8383
expect(dependencies['@nativescript/core']).toBeDefined();
8484
expect(dependencies['reflect-metadata']).toBeDefined();
8585

86-
expect(devDependencies['nativescript-dev-webpack']).toBeDefined();
86+
expect(devDependencies['@nativescript/webpack']).toBeDefined();
8787
expect(devDependencies['@nativescript/tslint-rules']).toBeDefined();
8888
});
8989

9090
it('should add run scripts to the package json', () => {
9191
const packageJsonPath = '/package.json';
9292
expect(appTree.files).toContain(packageJsonPath);
9393

94-
const packageJson = JSON.parse(getFileContent(appTree, packageJsonPath));
94+
const packageJson = JSON.parse(stripJsonComments(getFileContent(appTree, packageJsonPath)));
9595
const { scripts } = packageJson;
9696
expect(scripts).toBeDefined();
97-
expect(scripts.android).toEqual('tns run android --env.aot');
98-
expect(scripts.ios).toEqual('tns run ios --env.aot');
97+
expect(scripts.android).toEqual('tns run android --no-hmr');
98+
expect(scripts.ios).toEqual('tns run ios --no-hmr');
9999
expect(scripts.ngcc).toEqual('ngcc --properties es2015 module main --first-only');
100100
expect(scripts.postinstall).toEqual('npm run ngcc');
101101
});
@@ -104,7 +104,7 @@ describe('Add {N} schematic', () => {
104104
const packageJsonPath = '/package.json';
105105
expect(appTree.files).toContain(packageJsonPath);
106106

107-
const packageJson = JSON.parse(getFileContent(appTree, packageJsonPath));
107+
const packageJson = JSON.parse(stripJsonComments(getFileContent(appTree, packageJsonPath)));
108108
const { nativescript } = packageJson;
109109

110110
expect(nativescript).toBeDefined();
@@ -115,7 +115,7 @@ describe('Add {N} schematic', () => {
115115
const webTsConfigPath = '/tsconfig.app.json';
116116
expect(appTree.files).toContain(webTsConfigPath);
117117

118-
const webTsconfig = JSON.parse(getFileContent(appTree, webTsConfigPath));
118+
const webTsconfig = JSON.parse(stripJsonComments(getFileContent(appTree, webTsConfigPath)));
119119
const files = webTsconfig.files;
120120

121121
expect(files).toBeDefined();
@@ -135,7 +135,7 @@ describe('Add {N} schematic', () => {
135135
const nsTsConfigPath = '/tsconfig.tns.json';
136136
expect(appTree.files).toContain(nsTsConfigPath);
137137

138-
const nsTsConfig = JSON.parse(getFileContent(appTree, nsTsConfigPath));
138+
const nsTsConfig = JSON.parse(stripJsonComments(getFileContent(appTree, nsTsConfigPath)));
139139
const files = nsTsConfig.files;
140140

141141
expect(files).toBeDefined();
@@ -154,7 +154,7 @@ describe('Add {N} schematic', () => {
154154
const specTsConfigPath = '/tsconfig.spec.json';
155155
expect(appTree.files).toContain(specTsConfigPath);
156156

157-
const specTsConfig = JSON.parse(getFileContent(appTree, specTsConfigPath));
157+
const specTsConfig = JSON.parse(stripJsonComments(getFileContent(appTree, specTsConfigPath)));
158158
const files = specTsConfig.files;
159159

160160
expect(files).toBeDefined();
@@ -163,10 +163,10 @@ describe('Add {N} schematic', () => {
163163
});
164164

165165
it('should modify the base tsconfig.json to include path mappings', () => {
166-
const baseTsConfigPath = '/tsconfig.json';
166+
const baseTsConfigPath = '/tsconfig.base.json';
167167
expect(appTree.files).toContain(baseTsConfigPath);
168168

169-
const baseTsConfig = JSON.parse(getFileContent(appTree, baseTsConfigPath));
169+
const baseTsConfig = JSON.parse(stripJsonComments(getFileContent(appTree, baseTsConfigPath)));
170170

171171
const paths = baseTsConfig.compilerOptions.paths;
172172
expect(paths).toBeDefined();
@@ -184,7 +184,7 @@ describe('Add {N} schematic', () => {
184184
const tsLintConfigPath = '/tslint.json';
185185
expect(appTree.files).toContain(tsLintConfigPath);
186186

187-
const tsLintConfig = JSON.parse(getFileContent(appTree, tsLintConfigPath));
187+
const tsLintConfig = JSON.parse(stripJsonComments(getFileContent(appTree, tsLintConfigPath)));
188188
const { extends: tsLintExtends, rules: tsLintRules } = tsLintConfig;
189189

190190
expect(tsLintExtends).toEqual(jasmine.any(Array));
@@ -241,7 +241,7 @@ describe('Add {N} schematic', () => {
241241
'export const routes: Routes = []',
242242
);
243243
expect(appComponentTemplate).toContain(
244-
'<Label text="Entry Component works" textWrap="true"></Label>',
244+
`This is just a fun sample for you to play with`,
245245
);
246246
});
247247
});
@@ -294,7 +294,7 @@ async function setupProject(
294294
'workspace',
295295
{
296296
name: 'workspace',
297-
version: '8.0.0',
297+
version: '10.0.0',
298298
newProjectRoot: '',
299299
},
300300
).toPromise();

src/angular-project-parser.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeSc
22
import { basename } from 'path';
33
import { Tree, SchematicsException } from '@angular-devkit/schematics';
44
import { getWorkspace } from '@schematics/angular/utility/config';
5-
import { getProject } from '@schematics/angular/utility/project';
6-
import { getProjectTargets } from '@schematics/angular/utility/project-targets';
75
import {
86
findBootstrapModuleCall,
97
findBootstrapModulePath,
@@ -161,14 +159,14 @@ export function getTsConfigFromProject(tree: Tree, projectName: string): string
161159

162160
function parseAngularConfig(tree, projectName: string) {
163161
const project = getProjectObject(tree, projectName);
164-
const targets = getProjectTargets(project);
162+
const targets = project.architect;
165163

166164
return { targets, project };
167165
}
168166

169167
export function getProjectObject(tree: Tree, projectName: string) {
170168
const workspace = getWorkspace(tree);
171-
const project = getProject(workspace, projectName);
169+
const project = workspace.projects[projectName];
172170
if (!project) {
173171
throw new SchematicsException(`Couldn't find project "${projectName}" in the workspace!`);
174172
}

0 commit comments

Comments
 (0)