Skip to content

Commit eb2931a

Browse files
authored
fix: TypeScript 4.1, stylesheet ext handling, proper project parse (#315)
* chore: bump TS v4.1 * fix: properly parsing project object * fix: read style sheet extension from project object * docs: update README instruction default scss extension
1 parent 3ff5fa7 commit eb2931a

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ You need to add an `angular.json` configuration file to your NativeScript projec
6868
"root": "",
6969
"sourceRoot": ".",
7070
"projectType": "application",
71-
"prefix": "app"
71+
"prefix": "app",
72+
"schematics": {
73+
"@schematics/angular:component": {
74+
"style": "scss"
75+
}
76+
}
7277
}
7378
},
7479
"defaultProject": "project-name"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"jasmine": "^3.5.0",
4242
"jasmine-spec-reporter": "^5.0.2",
4343
"tslint": "~6.1.0",
44-
"typescript": "~4.0.0"
44+
"typescript": "~4.1.0"
4545
},
4646
"repository": {
4747
"type": "git",

src/angular-project-parser.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import * as ts from 'typescript';
22
import { basename } from 'path';
3-
import { Tree, SchematicsException } from '@angular-devkit/schematics';
4-
import {
5-
findBootstrapModuleCall,
6-
findBootstrapModulePath,
7-
} from '@schematics/angular/utility/ng-ast-utils';
3+
import { SchematicsException, Tree } from '@angular-devkit/schematics';
4+
import { findBootstrapModuleCall, findBootstrapModulePath } from '@schematics/angular/utility/ng-ast-utils';
85
import { getWorkspace } from '@schematics/angular/utility/workspace';
96

107
import { safeGet } from './utils';
11-
import { findNode, findImportPath, getSourceFile } from './ts-utils';
8+
import { findImportPath, findNode, getSourceFile } from './ts-utils';
129

1310
export interface AngularProjectSettings {
1411
/** default: '' */
@@ -128,7 +125,7 @@ async function getCoreProjectSettings(tree: Tree, projectName: string): Promise<
128125
);
129126
}
130127

131-
const buildTarget = targets.build;
128+
const buildTarget = targets.get('build');
132129
if (!buildTarget) {
133130
throw new SchematicsException(
134131
`Failed to find build target for project ${projectName}!`,
@@ -139,7 +136,7 @@ async function getCoreProjectSettings(tree: Tree, projectName: string): Promise<
139136
const sourceRoot = project.sourceRoot || 'src';
140137
const mainPath = safeGet(buildTarget, 'options', 'main');
141138
const mainName = mainPath && basename(mainPath).replace(/\.ts$/, '');
142-
const prefix = project.prefix;
139+
const prefix = project.prefix as string;
143140
const tsConfig = safeGet(buildTarget, 'options', 'tsConfig');
144141

145142
return {
@@ -154,21 +151,20 @@ async function getCoreProjectSettings(tree: Tree, projectName: string): Promise<
154151

155152
export async function getTsConfigFromProject(tree: Tree, projectName: string) {
156153
const { targets } = await parseAngularConfig(tree, projectName);
157-
const tsConfig = safeGet(targets, 'build', 'options', 'tsConfig');
158154

159-
return tsConfig;
155+
return safeGet(targets, 'build', 'options', 'tsConfig');
160156
}
161157

162158
async function parseAngularConfig(tree, projectName: string) {
163159
const project = await getProjectObject(tree, projectName);
164-
const targets = project.architect;
160+
const targets = project.targets;
165161

166162
return { targets, project };
167163
}
168164

169165
export async function getProjectObject(tree: Tree, projectName: string) {
170166
const workspace = await getWorkspace(tree);
171-
const project = workspace.projects[projectName];
167+
const project = workspace.projects.get(projectName);
172168
if (!project) {
173169
throw new SchematicsException(`Couldn't find project "${projectName}" in the workspace!`);
174170
}

src/generate/component/index.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,29 @@ let extensions: Extensions;
4545
export default function(options: ComponentOptions): Rule {
4646
let platformUse: PlatformUse;
4747
let componentInfo: ComponentInfo;
48+
4849
return chain([
49-
(tree: Tree) => {
50-
platformUse = getPlatformUse(tree, options);
50+
async (tree: Tree) => {
51+
const projectObject = await getProjectObject(tree, options.project);
5152

52-
if (platformUse.nsOnly && options.spec !== true) {
53-
options.spec = false;
54-
}
53+
return () => {
54+
platformUse = getPlatformUse(tree, options);
5555

56-
const projectObject: any = getProjectObject(tree, options.project);
57-
const style = (projectObject && projectObject.schematics && projectObject.schematics['@schematics/angular:component']
58-
&& projectObject.schematics['@schematics/angular:component'].style);
59-
if (style) {
60-
options.style = style;
61-
}
56+
if (platformUse.nsOnly && options.spec !== true) {
57+
options.spec = false;
58+
}
6259

63-
validateGenerateOptions(platformUse, options);
64-
validateGenerateComponentOptions(platformUse, options);
60+
const style = (projectObject && projectObject.extensions.schematics && projectObject.extensions.schematics['@schematics/angular:component']
61+
&& projectObject.extensions.schematics['@schematics/angular:component'].style);
62+
if (style) {
63+
options.style = style;
64+
}
6565

66-
return tree;
66+
validateGenerateOptions(platformUse, options);
67+
validateGenerateComponentOptions(platformUse, options);
68+
69+
return tree;
70+
}
6771
},
6872

6973
() => externalSchematic(

0 commit comments

Comments
 (0)