diff --git a/packages/nx/src/schematics/application/application.spec.ts b/packages/nx/src/schematics/application/application.spec.ts index d6669274e..770c39de0 100644 --- a/packages/nx/src/schematics/application/application.spec.ts +++ b/packages/nx/src/schematics/application/application.spec.ts @@ -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; @@ -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(); }); }); diff --git a/packages/nx/src/schematics/application/application.ts b/packages/nx/src/schematics/application/application.ts index 26edb7644..0e805b741 100644 --- a/packages/nx/src/schematics/application/application.ts +++ b/packages/nx/src/schematics/application/application.ts @@ -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), @@ -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) => { @@ -106,9 +66,7 @@ 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, }, @@ -116,9 +74,7 @@ export default function (options: Schema) { 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, }, @@ -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}`), ]) diff --git a/packages/nx/src/schematics/application/files_angular/package.json b/packages/nx/src/schematics/application/files_angular/package.json index 92b6d85e6..e548d9b22 100644 --- a/packages/nx/src/schematics/application/files_angular/package.json +++ b/packages/nx/src/schematics/application/files_angular/package.json @@ -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" } } diff --git a/packages/nx/src/schematics/init/init.ts b/packages/nx/src/schematics/init/init.ts index a1dc40772..f27fd3b00 100644 --- a/packages/nx/src/schematics/init/init.ts +++ b/packages/nx/src/schematics/init/init.ts @@ -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 { @@ -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'; } }); -} \ No newline at end of file +} diff --git a/packages/nx/src/utils/helpers.ts b/packages/nx/src/utils/helpers.ts index d2741f91f..d3b09e393 100644 --- a/packages/nx/src/utils/helpers.ts +++ b/packages/nx/src/utils/helpers.ts @@ -1,54 +1,28 @@ -import { - Tree, - noop, - branchAndMerge, - mergeWith, - apply, - url, - template, - move, - SchematicContext, - Rule, - externalSchematic, - SchematicsException, -} from '@angular-devkit/schematics'; -import { - NodePackageInstallTask, - RunSchematicTask, -} from '@angular-devkit/schematics/tasks'; -import { createSourceFile, ScriptTarget } from 'typescript'; +import { apply, branchAndMerge, externalSchematic, mergeWith, move, noop, Rule, SchematicContext, SchematicsException, template, Tree, url } from '@angular-devkit/schematics'; +import { NodePackageInstallTask, RunSchematicTask } from '@angular-devkit/schematics/tasks'; import { toFileName } from '@nrwl/workspace'; -import { insert, addGlobal } from './ast'; +import { createSourceFile, ScriptTarget } from 'typescript'; +import { addGlobal, insert } from './ast'; +import { generateOptionError, unsupportedFrameworkError } from './errors'; import { FrameworkTypes, + getDefaultTemplateOptions, + getFrontendFramework, + getGroupByName, + getJsonFromFile, + getPrefix, + IPluginSettings, + isXplatWorkspace, + packageSettingKeys, PlatformTypes, sanitizeCommaDelimitedArg, - IPluginSettings, - getPrefix, - getGroupByName, - getFrontendFramework, + stringUtils, supportedFrameworks, supportedPlatforms, - getJsonFromFile, - updateJsonFile, - updateFile, - getNxWorkspaceConfig, supportedSandboxPlatforms, - getDefaultTemplateOptions, - stringUtils, - isXplatWorkspace, - packageSettingKeys, + updateJsonFile, } from './general'; -import { generateOptionError, unsupportedFrameworkError } from './errors'; -import { - nodeSassVersion, - nsAngularVersion, - nsCoreVersion, - nsNxPluginVersion, - nsThemeVersion, - nsNgToolsVersion, - nxVersion, -} from './versions'; +import { nodeSassVersion, nsAngularVersion, nsCoreVersion, nsNgToolsVersion, nsNxPluginVersion, nsRxjs, nsThemeVersion, nsZonejs } from './versions'; export namespace PluginHelpers { export interface Schema { @@ -108,15 +82,10 @@ export namespace PluginHelpers { // will support comma delimited list of frameworks to generate support for // most common to generate 1 at a time but we will allow multiple // always default framework choice to first in list when multiple - return >( - (sanitizeCommaDelimitedArg(frameworkArgument)) - ); + return >(sanitizeCommaDelimitedArg(frameworkArgument)); } - export function getFrameworkChoice( - frameworkArgument: string, - frameworks?: Array - ) { + export function getFrameworkChoice(frameworkArgument: string, frameworks?: Array) { frameworks = frameworks || getFrameworksFromOptions(frameworkArgument); return frameworks.length ? frameworks[0] : null; } @@ -129,18 +98,28 @@ export namespace PluginHelpers { case 'angular': frameworkDependencies['@nativescript/angular'] = nsAngularVersion; frameworkDevDependencies['@ngtools/webpack'] = nsNgToolsVersion; + frameworkDependencies['@angular/animations'] = nsAngularVersion; + frameworkDependencies['@angular/common'] = nsAngularVersion; + frameworkDependencies['@angular/compiler'] = nsAngularVersion; + frameworkDependencies['@angular/core'] = nsAngularVersion; + frameworkDependencies['@angular/forms'] = nsAngularVersion; + frameworkDependencies['@angular/platform-browser'] = nsAngularVersion; + frameworkDependencies['@angular/platform-browser-dynamic'] = nsAngularVersion; + frameworkDependencies['@angular/router'] = nsAngularVersion; + frameworkDependencies['rxjs'] = nsRxjs; + frameworkDependencies['zone.js'] = nsZonejs; break; } return PluginHelpers.updatePackageForWorkspace(options, { dependencies: { '@nativescript/core': nsCoreVersion, 'nativescript-theme-core': nsThemeVersion, - ...frameworkDependencies + ...frameworkDependencies, }, devDependencies: { 'node-sass': nodeSassVersion, '@nativescript/types': nsCoreVersion, - ...frameworkDevDependencies + ...frameworkDevDependencies, }, })(tree, context); }; @@ -165,10 +144,7 @@ export namespace PluginHelpers { export function getUpdatedPluginSettings(options: Schema) { const frameworks = getFrameworksFromOptions(options.framework); - const frameworkChoice = PluginHelpers.getFrameworkChoice( - options.framework, - frameworks - ); + const frameworkChoice = PluginHelpers.getFrameworkChoice(options.framework, frameworks); const pluginSettings: IPluginSettings = { prefix: getPrefix(), }; @@ -192,9 +168,7 @@ export namespace PluginHelpers { */ export function getPlatformName(name: string, platform: PlatformTypes) { const nameSanitized = toFileName(name); - return getGroupByName() - ? `${nameSanitized}-${platform}` - : `${platform}-${nameSanitized}`; + return getGroupByName() ? `${nameSanitized}-${platform}` : `${platform}-${nameSanitized}`; } /** @@ -204,10 +178,7 @@ export namespace PluginHelpers { * @param platform * @param framework */ - export function getLibFoldername( - platform: PlatformTypes, - framework?: FrameworkTypes - ) { + export function getLibFoldername(platform: PlatformTypes, framework?: FrameworkTypes) { const frontendFramework = getFrontendFramework(); // console.log('getLibFoldername frontendFramework:', frontendFramework); // console.log('framework:', framework); @@ -221,11 +192,7 @@ export namespace PluginHelpers { return `${platform}${frameworkSuffix}`; } - export function getExternalChainsForGenerator( - options: Schema, - generator: string, - packagesToRunXplat: Array - ) { + export function getExternalChainsForGenerator(options: Schema, generator: string, packagesToRunXplat: Array) { let generatorSettings: IPluginGeneratorOptions; let isApp = false; switch (generator) { @@ -238,9 +205,7 @@ export namespace PluginHelpers { default: isApp = ['application', 'app'].includes(generator); generatorSettings = { - platforms: >( - (sanitizeCommaDelimitedArg('nativescript')) - ), + platforms: >(sanitizeCommaDelimitedArg('nativescript')), }; break; } @@ -291,17 +256,12 @@ export namespace PluginHelpers { } } else { externalChains.push((tree: Tree, context: SchematicContext) => { - const installPackageTask = context.addTask( - new NodePackageInstallTask() - ); + const installPackageTask = context.addTask(new NodePackageInstallTask()); // console.log('devDependencies:', devDependencies); // console.log('packagesToRunXplat:', packagesToRunXplat); for (const packageName of packagesToRunXplat) { - context.addTask( - new RunSchematicTask(packageName, generator, options), - [installPackageTask] - ); + context.addTask(new RunSchematicTask(packageName, generator, options), [installPackageTask]); } }); } @@ -309,15 +269,9 @@ export namespace PluginHelpers { return externalChains; } - export function getExternalChainsForApplication( - options: Schema, - generator: string, - packagesToRun: Array - ) { + export function getExternalChainsForApplication(options: Schema, generator: string, packagesToRun: Array) { let generatorSettings: IPluginGeneratorOptions = { - platforms: >( - (sanitizeCommaDelimitedArg('nativescript')) - ), + platforms: >(sanitizeCommaDelimitedArg('nativescript')), }; const platforms = generatorSettings.platforms; const externalChains = []; @@ -339,10 +293,7 @@ export namespace PluginHelpers { if (packagesToRun.length) { for (const packageName of packagesToRun) { const nxPlatform = packageName.replace('@nrwl/', ''); - const { name, directory } = getAppNamingConvention( - options, - nxPlatform - ); + const { name, directory } = getAppNamingConvention(options, nxPlatform); externalChains.push( externalSchematic( @@ -362,24 +313,17 @@ export namespace PluginHelpers { } } else { if (targetPlatforms) { - externalChains.push( - externalSchematic('@nativescript/nx', 'app-generate', options) - ); + externalChains.push(externalSchematic('@nativescript/nx', 'app-generate', options)); } if (packagesToRun.length) { externalChains.push((tree: Tree, context: SchematicContext) => { - const installPackageTask = context.addTask( - new NodePackageInstallTask() - ); + const installPackageTask = context.addTask(new NodePackageInstallTask()); // console.log('devDependencies:', devDependencies); // console.log('packagesToRunXplat:', packagesToRunXplat); for (const packageName of packagesToRun) { const nxPlatform = packageName.replace('@nrwl/', ''); - const { name, directory } = getAppNamingConvention( - options, - nxPlatform - ); + const { name, directory } = getAppNamingConvention(options, nxPlatform); context.addTask( new RunSchematicTask(packageName, generator, { ...options, @@ -395,10 +339,7 @@ export namespace PluginHelpers { return externalChains; } - export function applyAppNamingConvention( - options: any, - platform: PlatformTypes - ): Rule { + export function applyAppNamingConvention(options: any, platform: PlatformTypes): Rule { return (tree: Tree, context: SchematicContext) => { const { name, directory } = getAppNamingConvention(options, platform); options.name = name; @@ -409,18 +350,12 @@ export namespace PluginHelpers { }; } - export function getAppNamingConvention( - options: any, - platform: PlatformTypes - ) { + export function getAppNamingConvention(options: any, platform: PlatformTypes) { let name = ''; let directory = ''; if (options.directory) { directory = toFileName(options.directory); - if ( - directory === platform && - supportedPlatforms.includes(directory) - ) { + if (directory === platform && supportedPlatforms.includes(directory)) { name = toFileName(options.name); } else { name = getPlatformName(options.name, platform); @@ -459,7 +394,6 @@ export namespace PluginHelpers { }; return updateJsonFile(tree, packagePath, packageJson); } else if (updates) { - // update root dependencies for the generated support packageJson = { ...packageJson, @@ -575,9 +509,7 @@ export namespace PluginComponentHelpers { isTesting?: boolean; } - export function prepare( - options: Schema - ): PluginHelpers.IPluginGeneratorOptions { + export function prepare(options: Schema): PluginHelpers.IPluginGeneratorOptions { if (!options.name) { throw new Error(generateOptionError('component')); } @@ -604,16 +536,10 @@ export namespace PluginComponentHelpers { const projectParts = name.split('-'); const platPrefix = projectParts[0]; const platSuffix = projectParts.pop(); - if ( - supportedPlatforms.includes(platPrefix) && - !platforms.includes(platPrefix) - ) { + if (supportedPlatforms.includes(platPrefix) && !platforms.includes(platPrefix)) { // if project name is prefixed with supported platform and not already added platforms.push(platPrefix); - } else if ( - supportedPlatforms.includes(platSuffix) && - !platforms.includes(platSuffix) - ) { + } else if (supportedPlatforms.includes(platSuffix) && !platforms.includes(platSuffix)) { platforms.push(platSuffix); } } @@ -671,13 +597,9 @@ export namespace PluginFeatureHelpers { isTesting?: boolean; } - export function prepare( - options: Schema - ): PluginHelpers.IPluginGeneratorOptions { + export function prepare(options: Schema): PluginHelpers.IPluginGeneratorOptions { if (!options.name) { - throw new SchematicsException( - `You did not specify the name of the feature you'd like to generate. For example: nx g @nativescript/nx:feature my-feature` - ); + throw new SchematicsException(`You did not specify the name of the feature you'd like to generate. For example: nx g @nativescript/nx:feature my-feature`); } const featureName = options.name.toLowerCase(); let projects = options.projects; @@ -701,9 +623,7 @@ export namespace PluginFeatureHelpers { if (supportedSandboxPlatforms.includes(p)) { projectSandboxNames.push(`${p}-sandbox`); } else { - throw new SchematicsException( - `The --adjustSandbox flag supports the following at the moment: ${supportedSandboxPlatforms}` - ); + throw new SchematicsException(`The --adjustSandbox flag supports the following at the moment: ${supportedSandboxPlatforms}`); } } projects = projectSandboxNames.join(','); @@ -711,9 +631,7 @@ export namespace PluginFeatureHelpers { } } if (options.routing && !options.onlyProject) { - throw new SchematicsException( - `When generating a feature with the --routing option, please also specify --onlyProject. Support for shared code routing is under development.` - ); + throw new SchematicsException(`When generating a feature with the --routing option, please also specify --onlyProject. Support for shared code routing is under development.`); } if (projects) { @@ -727,16 +645,10 @@ export namespace PluginFeatureHelpers { const projectParts = projectName.split('-'); const platPrefix = projectParts[0]; const platSuffix = projectParts.pop(); - if ( - supportedPlatforms.includes(platPrefix) && - !platforms.includes(platPrefix) - ) { + if (supportedPlatforms.includes(platPrefix) && !platforms.includes(platPrefix)) { // if project name is prefixed with supported platform and not already added platforms.push(platPrefix); - } else if ( - supportedPlatforms.includes(platSuffix) && - !platforms.includes(platSuffix) - ) { + } else if (supportedPlatforms.includes(platSuffix) && !platforms.includes(platSuffix)) { // if project name is suffixed with supported platform and not already added platforms.push(platSuffix); } @@ -754,13 +666,7 @@ export namespace PluginFeatureHelpers { return { featureName, projectNames, platforms }; } - export function addFiles( - options: Schema, - target: string = '', - projectName: string = '', - extra: string = '', - framework?: FrameworkTypes - ) { + export function addFiles(options: Schema, target: string = '', projectName: string = '', extra: string = '', framework?: FrameworkTypes) { let moveTo: string; if (target) { moveTo = getMoveTo(options, target, projectName, framework); @@ -775,57 +681,28 @@ export namespace PluginFeatureHelpers { // console.log('target:', target); // console.log('addFiles moveTo:', moveTo); // console.log('add files from:', `${workingDirectory}/${extra}_files`); - return branchAndMerge( - mergeWith( - apply(url(`./${extra}_files`), [ - template(getTemplateOptions(options, target, framework)), - move(moveTo), - ]) - ) - ); + return branchAndMerge(mergeWith(apply(url(`./${extra}_files`), [template(getTemplateOptions(options, target, framework)), move(moveTo)]))); } - export function adjustBarrelIndex( - options: Schema, - indexFilePath: string - ): Rule { + export function adjustBarrelIndex(options: Schema, indexFilePath: string): Rule { return (tree: Tree) => { // console.log('adjustBarrelIndex indexFilePath:', indexFilePath); // console.log('tree.exists(indexFilePath):', tree.exists(indexFilePath)); const indexSource = tree.read(indexFilePath)!.toString('utf-8'); - const indexSourceFile = createSourceFile( - indexFilePath, - indexSource, - ScriptTarget.Latest, - true - ); - - insert(tree, indexFilePath, [ - ...addGlobal( - indexSourceFile, - indexFilePath, - `export * from './${options.name.toLowerCase()}';`, - true - ), - ]); + const indexSourceFile = createSourceFile(indexFilePath, indexSource, ScriptTarget.Latest, true); + + insert(tree, indexFilePath, [...addGlobal(indexSourceFile, indexFilePath, `export * from './${options.name.toLowerCase()}';`, true)]); return tree; }; } - export function getTemplateOptions( - options: Schema, - platform: string, - framework?: FrameworkTypes - ) { + export function getTemplateOptions(options: Schema, platform: string, framework?: FrameworkTypes) { const nameParts = options.name.split('-'); let endingDashName = nameParts[0]; if (nameParts.length > 1) { endingDashName = stringUtils.capitalize(nameParts[nameParts.length - 1]); } - const libFolderName = PluginHelpers.getLibFoldername( - platform, - framework - ); + const libFolderName = PluginHelpers.getLibFoldername(platform, framework); return { ...(options as any), ...getDefaultTemplateOptions(), @@ -835,22 +712,12 @@ export namespace PluginFeatureHelpers { }; } - export function getMoveTo( - options: Schema, - platform: string, - projectName?: string, - framework?: FrameworkTypes - ) { + export function getMoveTo(options: Schema, platform: string, projectName?: string, framework?: FrameworkTypes) { // console.log('getMoveTo framework:', framework); - const libFolderName = PluginHelpers.getLibFoldername( - platform, - framework - ); + const libFolderName = PluginHelpers.getLibFoldername(platform, framework); // console.log('getMoveTo libFolderName:', libFolderName); const featureName = options.name.toLowerCase(); - let moveTo = `libs/${ - isXplatWorkspace() ? 'xplat/' : '' - }${libFolderName}/features/${featureName}`; + let moveTo = `libs/${isXplatWorkspace() ? 'xplat/' : ''}${libFolderName}/features/${featureName}`; if (projectName) { let appDir = ['web', 'web-angular'].includes(libFolderName) ? '/app' : ''; moveTo = `apps/${projectName}/src${appDir}/features/${featureName}`; diff --git a/packages/nx/src/utils/versions.ts b/packages/nx/src/utils/versions.ts index 60d2799e9..402b9a4a4 100644 --- a/packages/nx/src/utils/versions.ts +++ b/packages/nx/src/utils/versions.ts @@ -8,4 +8,6 @@ export const nodeSassVersion = '^4.14.0'; // Frontend frameworks export const nsAngularVersion = '~11.0.0'; -export const nsNgToolsVersion = '~11.0.0'; \ No newline at end of file +export const nsNgToolsVersion = '~11.0.0'; +export const nsRxjs = '~6.5.5'; +export const nsZonejs = '^0.10.2"';