Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): create create-nx-plugin package to fix npx issues
- Loading branch information
Showing
9 changed files
with
125 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as path from 'path'; | ||
import { execSync } from 'child_process'; | ||
import { output } from '@nrwl/workspace/src/utils/output'; | ||
|
||
export function showNxWarning(workspaceName: string) { | ||
try { | ||
const pathToRunNxCommand = path.resolve(process.cwd(), workspaceName); | ||
execSync('nx --version', { | ||
cwd: pathToRunNxCommand, | ||
stdio: ['ignore', 'ignore', 'ignore'] | ||
}); | ||
} catch (e) { | ||
// no nx found | ||
output.addVerticalSeparator(); | ||
output.note({ | ||
title: `Nx CLI is not installed globally.`, | ||
bodyLines: [ | ||
`This means that you might have to use "yarn nx" or "npm nx" to execute commands in the workspace.`, | ||
`Run "yarn global add @nrwl/cli" or "npm install -g @nrwl/cli" to be able to execute command directly.` | ||
] | ||
}); | ||
} | ||
} | ||
|
||
export function determinePackageManager() { | ||
let packageManager = getPackageManagerFromAngularCLI(); | ||
if (packageManager === 'npm' || isPackageManagerInstalled(packageManager)) { | ||
return packageManager; | ||
} | ||
|
||
if (isPackageManagerInstalled('yarn')) { | ||
return 'yarn'; | ||
} | ||
|
||
if (isPackageManagerInstalled('pnpm')) { | ||
return 'pnpm'; | ||
} | ||
|
||
return 'npm'; | ||
} | ||
|
||
function getPackageManagerFromAngularCLI(): string { | ||
// If you have Angular CLI installed, read Angular CLI config. | ||
// If it isn't installed, default to 'yarn'. | ||
try { | ||
return execSync('ng config -g cli.packageManager', { | ||
stdio: ['ignore', 'pipe', 'ignore'], | ||
timeout: 500 | ||
}) | ||
.toString() | ||
.trim(); | ||
} catch (e) { | ||
return 'yarn'; | ||
} | ||
} | ||
|
||
function isPackageManagerInstalled(packageManager: string) { | ||
let isInstalled = false; | ||
try { | ||
execSync(`${packageManager} --version`, { | ||
stdio: ['ignore', 'ignore', 'ignore'] | ||
}); | ||
isInstalled = true; | ||
} catch (e) { | ||
/* do nothing */ | ||
} | ||
return isInstalled; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "create-nx-plugin", | ||
"version": "0.0.2", | ||
"description": "Extensible Dev Tools for Monorepos", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/nrwl/nx.git" | ||
}, | ||
"keywords": [ | ||
"Monorepo", | ||
"Angular", | ||
"React", | ||
"Web", | ||
"Node", | ||
"Nest", | ||
"Jest", | ||
"Cypress", | ||
"CLI" | ||
], | ||
"bin": { | ||
"create-nx-plugin": "./bin/create-nx-plugin.js" | ||
}, | ||
"author": "Victor Savkin", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/nrwl/nx/issues" | ||
}, | ||
"homepage": "https://nx.dev", | ||
"dependencies": { | ||
"@nrwl/workspace": "*", | ||
"tmp": "0.0.33", | ||
"yargs-parser": "10.0.0", | ||
"yargs": "^11.0.0", | ||
"inquirer": "^6.3.1" | ||
} | ||
} |
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
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