-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(misc): nx init should work on non-monorepo projects
- Loading branch information
Showing
7 changed files
with
357 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
import { execSync } from 'child_process'; | ||
import { existsSync } from 'fs'; | ||
import { readJsonFile } from '../utils/fileutils'; | ||
import { addNxToNpmRepo } from '../nx-init/add-nx-to-npm-repo'; | ||
|
||
export function initHandler() { | ||
export async function initHandler() { | ||
const args = process.argv.slice(2).join(' '); | ||
if (existsSync('package.json')) { | ||
execSync(`npx --yes add-nx-to-monorepo@latest ${args}`, { | ||
stdio: [0, 1, 2], | ||
}); | ||
if (isMonorepo()) { | ||
// TODO: vsavkin remove add-nx-to-monorepo | ||
execSync(`npx --yes add-nx-to-monorepo@latest ${args}`, { | ||
stdio: [0, 1, 2], | ||
}); | ||
} else { | ||
await addNxToNpmRepo(); | ||
} | ||
} else { | ||
execSync(`npx --yes create-nx-workspace@latest ${args}`, { | ||
stdio: [0, 1, 2], | ||
}); | ||
} | ||
} | ||
|
||
function isMonorepo() { | ||
const packageJson = readJsonFile('package.json'); | ||
if (!!packageJson.workspaces) return true; | ||
|
||
if (existsSync('pnpm-workspace.yaml') || existsSync('pnpm-workspace.yml')) | ||
return true; | ||
|
||
if (existsSync('lerna.json')) return true; | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.