11import { execSync } from 'child_process' ;
22import { existsSync } from 'fs' ;
3- import { readJsonFile , directoryExists } from '../utils/fileutils ' ;
3+ import { addNxToNest } from '../nx-init/add-nx-to-nest ' ;
44import { addNxToNpmRepo } from '../nx-init/add-nx-to-npm-repo' ;
5+ import { directoryExists , readJsonFile } from '../utils/fileutils' ;
6+ import { PackageJson } from '../utils/package-json' ;
57
68export async function initHandler ( ) {
79 const args = process . argv . slice ( 2 ) . join ( ' ' ) ;
@@ -10,17 +12,20 @@ export async function initHandler() {
1012 console . log ( `Using version ${ process . env . NX_VERSION } ` ) ;
1113 }
1214 if ( existsSync ( 'package.json' ) ) {
15+ const packageJson : PackageJson = readJsonFile ( 'package.json' ) ;
1316 if ( existsSync ( 'angular.json' ) ) {
1417 // TODO(leo): remove make-angular-cli-faster
1518 execSync ( `npx --yes make-angular-cli-faster@${ version } ${ args } ` , {
1619 stdio : [ 0 , 1 , 2 ] ,
1720 } ) ;
18- } else if ( isCRA ( ) ) {
21+ } else if ( isCRA ( packageJson ) ) {
1922 // TODO(jack): remove cra-to-nx
2023 execSync ( `npx --yes cra-to-nx@${ version } ${ args } ` , {
2124 stdio : [ 0 , 1 , 2 ] ,
2225 } ) ;
23- } else if ( isMonorepo ( ) ) {
26+ } else if ( isNestCLI ( packageJson ) ) {
27+ await addNxToNest ( packageJson ) ;
28+ } else if ( isMonorepo ( packageJson ) ) {
2429 // TODO: vsavkin remove add-nx-to-monorepo
2530 execSync ( `npx --yes add-nx-to-monorepo@${ version } ${ args } ` , {
2631 stdio : [ 0 , 1 , 2 ] ,
@@ -35,8 +40,7 @@ export async function initHandler() {
3540 }
3641}
3742
38- function isCRA ( ) {
39- const packageJson = readJsonFile ( 'package.json' ) ;
43+ function isCRA ( packageJson : PackageJson ) {
4044 const combinedDependencies = {
4145 ...packageJson . dependencies ,
4246 ...packageJson . devDependencies ,
@@ -54,8 +58,19 @@ function isCRA() {
5458 ) ;
5559}
5660
57- function isMonorepo ( ) {
58- const packageJson = readJsonFile ( 'package.json' ) ;
61+ function isNestCLI ( packageJson : PackageJson ) {
62+ const combinedDependencies = {
63+ ...packageJson . dependencies ,
64+ ...packageJson . devDependencies ,
65+ } ;
66+ return (
67+ existsSync ( 'nest-cli.json' ) &&
68+ combinedDependencies [ '@nestjs/core' ] &&
69+ combinedDependencies [ '@nestjs/cli' ]
70+ ) ;
71+ }
72+
73+ function isMonorepo ( packageJson : PackageJson ) {
5974 if ( ! ! packageJson . workspaces ) return true ;
6075
6176 if ( existsSync ( 'pnpm-workspace.yaml' ) || existsSync ( 'pnpm-workspace.yml' ) )
0 commit comments