Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions packages/nx/src/schematics/application/application.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Tree } from '@angular-devkit/schematics';
import { UnitTestTree } from '@angular-devkit/schematics/testing';
import { createEmptyWorkspace } from '@nrwl/workspace/testing';
import * as stripJsonComments from 'strip-json-comments';
import { NxJson, readJsonInTree } from '@nrwl/workspace';
import { createEmptyWorkspace } from '@nrwl/workspace/testing';
import { runSchematic } from '../../utils/testing';
import { nsAngularVersion, nsRxjs, nsZonejs } from '../../utils/versions';

describe('app', () => {
let appTree: Tree;
Expand Down Expand Up @@ -87,15 +87,38 @@ describe('app', () => {
checkFiles(tree, appPath, '../../../');
});

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

expect(tree.exists(`${appPath}/src/app.routing.ts`)).toBeTruthy();
expect(tree.exists(`${appPath}/src/features/home/home.module.ts`)).toBeTruthy();
expect(packageJson['dependencies']['@angular/animations']).toEqual(nsAngularVersion);
expect(packageJson['dependencies']['@angular/common']).toEqual(nsAngularVersion);
expect(packageJson['dependencies']['@angular/compiler']).toEqual(nsAngularVersion);
expect(packageJson['dependencies']['@angular/core']).toEqual(nsAngularVersion);
expect(packageJson['dependencies']['@angular/forms']).toEqual(nsAngularVersion);
expect(packageJson['dependencies']['@angular/platform-browser']).toEqual(nsAngularVersion);
expect(packageJson['dependencies']['@angular/platform-browser-dynamic']).toEqual(nsAngularVersion);
expect(packageJson['dependencies']['@angular/router']).toEqual(nsAngularVersion);
expect(packageJson['dependencies']['rxjs']).toEqual(nsRxjs);
expect(packageJson['dependencies']['zone.js']).toEqual(nsZonejs);
expect(packageJson['dependencies']['@nativescript/angular']).toEqual(nsAngularVersion);
});

it('should not add angular dependencies when framework is not angular', async () => {
const tree = await runSchematic('app', { name: 'myApp', framework: '' }, appTree);
const packageJson = readJsonInTree(tree, `package.json`);

checkFiles(tree, appPath, '../../');
expect(packageJson['dependencies']['@angular/animations']).toBeFalsy();
expect(packageJson['dependencies']['@angular/common']).toBeFalsy();
expect(packageJson['dependencies']['@angular/compiler']).toBeFalsy();
expect(packageJson['dependencies']['@angular/core']).toBeFalsy();
expect(packageJson['dependencies']['@angular/forms']).toBeFalsy();
expect(packageJson['dependencies']['@angular/platform-browser']).toBeFalsy();
expect(packageJson['dependencies']['@angular/platform-browser-dynamic']).toBeFalsy();
expect(packageJson['dependencies']['@angular/router']).toBeFalsy();
expect(packageJson['dependencies']['rxjs']).toBeFalsy();
expect(packageJson['dependencies']['zone.js']).toBeFalsy();
expect(packageJson['dependencies']['@nativescript/angular']).toBeFalsy();
});
});

Expand Down
64 changes: 10 additions & 54 deletions packages/nx/src/schematics/application/application.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,26 @@
import {
apply,
chain,
Tree,
Rule,
url,
move,
template,
mergeWith,
branchAndMerge,
SchematicContext,
SchematicsException,
schematic,
noop,
externalSchematic,
} from '@angular-devkit/schematics';
import {
prerun,
missingArgument,
PluginHelpers,
updatePackageScripts,
getPrefix,
updateWorkspace,
updateNxProjects,
getAppName,
getDefaultTemplateOptions,
getFrontendFramework,
} from '../../utils';
import { apply, branchAndMerge, chain, externalSchematic, mergeWith, move, noop, Rule, SchematicContext, SchematicsException, template, Tree, url } from '@angular-devkit/schematics';
import { getAppName, getDefaultTemplateOptions, getFrontendFramework, getPrefix, missingArgument, PluginHelpers, prerun, updateNxProjects, updatePackageScripts, updateWorkspace } from '../../utils';
import { nsWebpackVersion } from '../../utils/versions';
import { Schema } from './schema';

export default function (options: Schema) {
if (!options.name) {
throw new SchematicsException(
missingArgument(
'name',
'Provide a name for your NativeScript app.',
'nx g @nativescript/nx:app name'
)
);
throw new SchematicsException(missingArgument('name', 'Provide a name for your NativeScript app.', 'nx g @nativescript/nx:app name'));
}

return chain([
prerun(options, true),
PluginHelpers.applyAppNamingConvention(options, 'nativescript'),
(tree: Tree, context: SchematicContext) =>
addAppFiles(options, options.name),
(tree: Tree, context: SchematicContext) => addAppFiles(options, options.name),
// add extra files per options
(tree: Tree, context: SchematicContext) =>
options.routing && ['angular'].includes(options.framework)
? addAppFiles(options, options.name, 'routing')
: noop(),
(tree: Tree, context: SchematicContext) => (options.routing && ['angular'].includes(options.framework) ? addAppFiles(options, options.name, 'routing') : noop()),
// add app resources
(tree: Tree, context: SchematicContext) =>
externalSchematic(
'@nativescript/nx',
'app-resources',
{
path: `apps/${options.directory ? options.directory + '/' : ''}${
options.name
}`,
path: `apps/${options.directory ? options.directory + '/' : ''}${options.name}`,
},
{ interactive: false }
)(tree, context),
Expand All @@ -67,9 +29,7 @@ export default function (options: Schema) {
PluginHelpers.addPackageInstallTask(options),
(tree: Tree) => {
const scripts = {};
scripts[
`clean`
] = `npx rimraf hooks node_modules package-lock.json && npm i`;
scripts[`clean`] = `npx rimraf hooks node_modules package-lock.json && npm i`;
return updatePackageScripts(tree, scripts);
},
(tree: Tree, context: SchematicContext) => {
Expand Down Expand Up @@ -106,19 +66,15 @@ export default function (options: Schema) {
ios: {
builder: '@nrwl/workspace:run-commands',
options: {
commands: [
`ns debug ios --no-hmr --env.configuration={args.configuration} --env.projectName=${options.name}`,
],
commands: [`ns debug ios --no-hmr --env.configuration={args.configuration} --env.projectName=${options.name}`],
cwd: appPath,
parallel: false,
},
},
android: {
builder: '@nrwl/workspace:run-commands',
options: {
commands: [
`ns debug android --no-hmr --env.configuration={args.configuration} --env.projectName=${options.name}`,
],
commands: [`ns debug android --no-hmr --env.configuration={args.configuration} --env.projectName=${options.name}`],
cwd: appPath,
parallel: false,
},
Expand Down Expand Up @@ -173,7 +129,7 @@ function addAppFiles(options: Schema, appName: string, extra: string = ''): Rule
appname,
pathOffset: directory ? '../../../' : '../../',
libFolderName: PluginHelpers.getLibFoldername('nativescript'),
nsWebpackVersion
nsWebpackVersion,
}),
move(`apps/${directory}${appName}`),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
},
"devDependencies": {
"@angular/compiler-cli": "file:<%= pathOffset %>node_modules/@angular/compiler-cli",
"@ngtools/webpack": "file:<%= pathOffset %>node_modules/@ngtools/webpack",
"@nativescript/types": "file:<%= pathOffset %>node_modules/@nativescript/types",
"@nativescript/webpack": "<%= nsWebpackVersion %>",
"@ngtools/webpack": "file:<%= pathOffset %>node_modules/@ngtools/webpack",
"typescript": "file:<%= pathOffset %>node_modules/typescript"
}
}
33 changes: 10 additions & 23 deletions packages/nx/src/schematics/init/init.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
import { JsonObject } from '@angular-devkit/core';
import { chain, Rule } from '@angular-devkit/schematics';
import {
addDepsToPackageJson,
addPackageWithInit,
updateWorkspace,
} from '@nrwl/workspace';
import { addDepsToPackageJson, addPackageWithInit, updateWorkspace } from '@nrwl/workspace';
import { nsCoreVersion, nsThemeVersion } from '../../utils/versions';
import { Schema } from './schema';
import {
nsCoreVersion,
nsThemeVersion,
nxVersion,
} from '../../utils/versions';
import { JsonObject } from '@angular-devkit/core';

export default function (schema: Schema) {
return chain([
setWorkspaceDefaults(),
addPackageWithInit('@nrwl/jest'),
addDependencies(),
]);
return chain([setWorkspaceDefaults(), addPackageWithInit('@nrwl/jest'), addDependencies()]);
}

export function addDependencies(): Rule {
Expand All @@ -26,20 +14,19 @@ export function addDependencies(): Rule {
'@nativescript/core': nsCoreVersion,
'@nativescript/theme': nsThemeVersion,
},
{}
{
'@nativescript/types': nsCoreVersion,
}
);
}

function setWorkspaceDefaults(): Rule {
return updateWorkspace((workspace) => {
workspace.extensions.cli = workspace.extensions.cli || {};
const defaultCollection: string =
workspace.extensions.cli &&
((workspace.extensions.cli as JsonObject).defaultCollection as string);
const defaultCollection: string = workspace.extensions.cli && ((workspace.extensions.cli as JsonObject).defaultCollection as string);

if (!defaultCollection) {
(workspace.extensions.cli as JsonObject).defaultCollection =
'@nativescript/nx';
(workspace.extensions.cli as JsonObject).defaultCollection = '@nativescript/nx';
}
});
}
}
Loading