Skip to content

Commit 5417146

Browse files
authored
chore: adding deps for angular applications (#1)
1 parent 5090bef commit 5417146

File tree

6 files changed

+123
-287
lines changed

6 files changed

+123
-287
lines changed

packages/nx/src/schematics/application/application.spec.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Tree } from '@angular-devkit/schematics';
22
import { UnitTestTree } from '@angular-devkit/schematics/testing';
3-
import { createEmptyWorkspace } from '@nrwl/workspace/testing';
4-
import * as stripJsonComments from 'strip-json-comments';
53
import { NxJson, readJsonInTree } from '@nrwl/workspace';
4+
import { createEmptyWorkspace } from '@nrwl/workspace/testing';
65
import { runSchematic } from '../../utils/testing';
6+
import { nsAngularVersion, nsRxjs, nsZonejs } from '../../utils/versions';
77

88
describe('app', () => {
99
let appTree: Tree;
@@ -87,15 +87,38 @@ describe('app', () => {
8787
checkFiles(tree, appPath, '../../../');
8888
});
8989

90-
it('Angular groupByName: should generate files', async () => {
91-
const tree = await runSchematic('app', { name: 'myApp', framework: 'angular', groupByName: true }, appTree);
92-
const appPath = 'apps/my-app-nativescript';
93-
checkAngularFiles(tree, appPath);
90+
it('should add angular dependencies when framework is angular', async () => {
91+
const tree = await runSchematic('app', { name: 'myApp', framework: 'angular' }, appTree);
92+
const packageJson = readJsonInTree(tree, `package.json`);
9493

95-
expect(tree.exists(`${appPath}/src/app.routing.ts`)).toBeTruthy();
96-
expect(tree.exists(`${appPath}/src/features/home/home.module.ts`)).toBeTruthy();
94+
expect(packageJson['dependencies']['@angular/animations']).toEqual(nsAngularVersion);
95+
expect(packageJson['dependencies']['@angular/common']).toEqual(nsAngularVersion);
96+
expect(packageJson['dependencies']['@angular/compiler']).toEqual(nsAngularVersion);
97+
expect(packageJson['dependencies']['@angular/core']).toEqual(nsAngularVersion);
98+
expect(packageJson['dependencies']['@angular/forms']).toEqual(nsAngularVersion);
99+
expect(packageJson['dependencies']['@angular/platform-browser']).toEqual(nsAngularVersion);
100+
expect(packageJson['dependencies']['@angular/platform-browser-dynamic']).toEqual(nsAngularVersion);
101+
expect(packageJson['dependencies']['@angular/router']).toEqual(nsAngularVersion);
102+
expect(packageJson['dependencies']['rxjs']).toEqual(nsRxjs);
103+
expect(packageJson['dependencies']['zone.js']).toEqual(nsZonejs);
104+
expect(packageJson['dependencies']['@nativescript/angular']).toEqual(nsAngularVersion);
105+
});
106+
107+
it('should not add angular dependencies when framework is not angular', async () => {
108+
const tree = await runSchematic('app', { name: 'myApp', framework: '' }, appTree);
109+
const packageJson = readJsonInTree(tree, `package.json`);
97110

98-
checkFiles(tree, appPath, '../../');
111+
expect(packageJson['dependencies']['@angular/animations']).toBeFalsy();
112+
expect(packageJson['dependencies']['@angular/common']).toBeFalsy();
113+
expect(packageJson['dependencies']['@angular/compiler']).toBeFalsy();
114+
expect(packageJson['dependencies']['@angular/core']).toBeFalsy();
115+
expect(packageJson['dependencies']['@angular/forms']).toBeFalsy();
116+
expect(packageJson['dependencies']['@angular/platform-browser']).toBeFalsy();
117+
expect(packageJson['dependencies']['@angular/platform-browser-dynamic']).toBeFalsy();
118+
expect(packageJson['dependencies']['@angular/router']).toBeFalsy();
119+
expect(packageJson['dependencies']['rxjs']).toBeFalsy();
120+
expect(packageJson['dependencies']['zone.js']).toBeFalsy();
121+
expect(packageJson['dependencies']['@nativescript/angular']).toBeFalsy();
99122
});
100123
});
101124

packages/nx/src/schematics/application/application.ts

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,26 @@
1-
import {
2-
apply,
3-
chain,
4-
Tree,
5-
Rule,
6-
url,
7-
move,
8-
template,
9-
mergeWith,
10-
branchAndMerge,
11-
SchematicContext,
12-
SchematicsException,
13-
schematic,
14-
noop,
15-
externalSchematic,
16-
} from '@angular-devkit/schematics';
17-
import {
18-
prerun,
19-
missingArgument,
20-
PluginHelpers,
21-
updatePackageScripts,
22-
getPrefix,
23-
updateWorkspace,
24-
updateNxProjects,
25-
getAppName,
26-
getDefaultTemplateOptions,
27-
getFrontendFramework,
28-
} from '../../utils';
1+
import { apply, branchAndMerge, chain, externalSchematic, mergeWith, move, noop, Rule, SchematicContext, SchematicsException, template, Tree, url } from '@angular-devkit/schematics';
2+
import { getAppName, getDefaultTemplateOptions, getFrontendFramework, getPrefix, missingArgument, PluginHelpers, prerun, updateNxProjects, updatePackageScripts, updateWorkspace } from '../../utils';
293
import { nsWebpackVersion } from '../../utils/versions';
304
import { Schema } from './schema';
315

326
export default function (options: Schema) {
337
if (!options.name) {
34-
throw new SchematicsException(
35-
missingArgument(
36-
'name',
37-
'Provide a name for your NativeScript app.',
38-
'nx g @nativescript/nx:app name'
39-
)
40-
);
8+
throw new SchematicsException(missingArgument('name', 'Provide a name for your NativeScript app.', 'nx g @nativescript/nx:app name'));
419
}
4210

4311
return chain([
4412
prerun(options, true),
4513
PluginHelpers.applyAppNamingConvention(options, 'nativescript'),
46-
(tree: Tree, context: SchematicContext) =>
47-
addAppFiles(options, options.name),
14+
(tree: Tree, context: SchematicContext) => addAppFiles(options, options.name),
4815
// add extra files per options
49-
(tree: Tree, context: SchematicContext) =>
50-
options.routing && ['angular'].includes(options.framework)
51-
? addAppFiles(options, options.name, 'routing')
52-
: noop(),
16+
(tree: Tree, context: SchematicContext) => (options.routing && ['angular'].includes(options.framework) ? addAppFiles(options, options.name, 'routing') : noop()),
5317
// add app resources
5418
(tree: Tree, context: SchematicContext) =>
5519
externalSchematic(
5620
'@nativescript/nx',
5721
'app-resources',
5822
{
59-
path: `apps/${options.directory ? options.directory + '/' : ''}${
60-
options.name
61-
}`,
23+
path: `apps/${options.directory ? options.directory + '/' : ''}${options.name}`,
6224
},
6325
{ interactive: false }
6426
)(tree, context),
@@ -67,9 +29,7 @@ export default function (options: Schema) {
6729
PluginHelpers.addPackageInstallTask(options),
6830
(tree: Tree) => {
6931
const scripts = {};
70-
scripts[
71-
`clean`
72-
] = `npx rimraf hooks node_modules package-lock.json && npm i`;
32+
scripts[`clean`] = `npx rimraf hooks node_modules package-lock.json && npm i`;
7333
return updatePackageScripts(tree, scripts);
7434
},
7535
(tree: Tree, context: SchematicContext) => {
@@ -106,19 +66,15 @@ export default function (options: Schema) {
10666
ios: {
10767
builder: '@nrwl/workspace:run-commands',
10868
options: {
109-
commands: [
110-
`ns debug ios --no-hmr --env.configuration={args.configuration} --env.projectName=${options.name}`,
111-
],
69+
commands: [`ns debug ios --no-hmr --env.configuration={args.configuration} --env.projectName=${options.name}`],
11270
cwd: appPath,
11371
parallel: false,
11472
},
11573
},
11674
android: {
11775
builder: '@nrwl/workspace:run-commands',
11876
options: {
119-
commands: [
120-
`ns debug android --no-hmr --env.configuration={args.configuration} --env.projectName=${options.name}`,
121-
],
77+
commands: [`ns debug android --no-hmr --env.configuration={args.configuration} --env.projectName=${options.name}`],
12278
cwd: appPath,
12379
parallel: false,
12480
},
@@ -173,7 +129,7 @@ function addAppFiles(options: Schema, appName: string, extra: string = ''): Rule
173129
appname,
174130
pathOffset: directory ? '../../../' : '../../',
175131
libFolderName: PluginHelpers.getLibFoldername('nativescript'),
176-
nsWebpackVersion
132+
nsWebpackVersion,
177133
}),
178134
move(`apps/${directory}${appName}`),
179135
])

packages/nx/src/schematics/application/files_angular/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
},
2626
"devDependencies": {
2727
"@angular/compiler-cli": "file:<%= pathOffset %>node_modules/@angular/compiler-cli",
28-
"@ngtools/webpack": "file:<%= pathOffset %>node_modules/@ngtools/webpack",
28+
"@nativescript/types": "file:<%= pathOffset %>node_modules/@nativescript/types",
2929
"@nativescript/webpack": "<%= nsWebpackVersion %>",
30+
"@ngtools/webpack": "file:<%= pathOffset %>node_modules/@ngtools/webpack",
3031
"typescript": "file:<%= pathOffset %>node_modules/typescript"
3132
}
3233
}
Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1+
import { JsonObject } from '@angular-devkit/core';
12
import { chain, Rule } from '@angular-devkit/schematics';
2-
import {
3-
addDepsToPackageJson,
4-
addPackageWithInit,
5-
updateWorkspace,
6-
} from '@nrwl/workspace';
3+
import { addDepsToPackageJson, addPackageWithInit, updateWorkspace } from '@nrwl/workspace';
4+
import { nsCoreVersion, nsThemeVersion } from '../../utils/versions';
75
import { Schema } from './schema';
8-
import {
9-
nsCoreVersion,
10-
nsThemeVersion,
11-
nxVersion,
12-
} from '../../utils/versions';
13-
import { JsonObject } from '@angular-devkit/core';
146

157
export default function (schema: Schema) {
16-
return chain([
17-
setWorkspaceDefaults(),
18-
addPackageWithInit('@nrwl/jest'),
19-
addDependencies(),
20-
]);
8+
return chain([setWorkspaceDefaults(), addPackageWithInit('@nrwl/jest'), addDependencies()]);
219
}
2210

2311
export function addDependencies(): Rule {
@@ -26,20 +14,19 @@ export function addDependencies(): Rule {
2614
'@nativescript/core': nsCoreVersion,
2715
'@nativescript/theme': nsThemeVersion,
2816
},
29-
{}
17+
{
18+
'@nativescript/types': nsCoreVersion,
19+
}
3020
);
3121
}
3222

3323
function setWorkspaceDefaults(): Rule {
3424
return updateWorkspace((workspace) => {
3525
workspace.extensions.cli = workspace.extensions.cli || {};
36-
const defaultCollection: string =
37-
workspace.extensions.cli &&
38-
((workspace.extensions.cli as JsonObject).defaultCollection as string);
26+
const defaultCollection: string = workspace.extensions.cli && ((workspace.extensions.cli as JsonObject).defaultCollection as string);
3927

4028
if (!defaultCollection) {
41-
(workspace.extensions.cli as JsonObject).defaultCollection =
42-
'@nativescript/nx';
29+
(workspace.extensions.cli as JsonObject).defaultCollection = '@nativescript/nx';
4330
}
4431
});
45-
}
32+
}

0 commit comments

Comments
 (0)