Skip to content

Commit

Permalink
feat(core): create create-nx-plugin package to fix npx issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Jan 27, 2020
1 parent 6706a05 commit f5d4af2
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@nrwl/nx-source",
"version": "8.11.2",
"version": "8.12.0-beta.7",
"description": "Extensible Dev Tools for Monorepos",
"homepage": "https://nx.dev",
"main": "index.js",
Expand Down
Expand Up @@ -150,7 +150,7 @@ function determinePluginName(parsedArgs) {
.prompt([
{
name: 'PluginName',
message: `Plugin name `,
message: `Plugin name `,
type: 'string'
}
])
Expand Down
68 changes: 68 additions & 0 deletions packages/create-nx-plugin/bin/shared.ts
@@ -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;
}
36 changes: 36 additions & 0 deletions packages/create-nx-plugin/package.json
@@ -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"
}
}
3 changes: 1 addition & 2 deletions packages/create-nx-workspace/package.json
Expand Up @@ -18,8 +18,7 @@
"CLI"
],
"bin": {
"create-nx-workspace": "./bin/create-nx-workspace.js",
"create-nx-plugin": "./bin/create-nx-plugin.js"
"create-nx-workspace": "./bin/create-nx-workspace.js"
},
"author": "Victor Savkin",
"license": "MIT",
Expand Down
4 changes: 3 additions & 1 deletion scripts/build.sh
Expand Up @@ -29,7 +29,7 @@ rm -rf build/packages/angular/bundles/nrwl-angular-testing.umd.min.js.bak

rsync -a --exclude=*.ts packages/ build/packages
chmod +x build/packages/create-nx-workspace/bin/create-nx-workspace.js
chmod +x build/packages/create-nx-workspace/bin/create-nx-plugin.js
chmod +x build/packages/create-nx-plugin/bin/create-nx-plugin.js
chmod +x build/packages/cli/bin/nx.js
chmod +x build/packages/tao/index.js

Expand All @@ -43,6 +43,7 @@ cp README.md build/packages/builders
cp README.md build/packages/schematics
cp README.md build/packages/nx
cp README.md build/packages/create-nx-workspace
cp README.md build/packages/create-nx-plugin
cp README.md build/packages/workspace
cp README.md build/packages/node
cp README.md build/packages/express
Expand All @@ -65,6 +66,7 @@ cp LICENSE build/packages/builders
cp LICENSE build/packages/schematics
cp LICENSE build/packages/nx
cp LICENSE build/packages/create-nx-workspace
cp LICENSE build/packages/create-nx-plugin
cp LICENSE build/packages/workspace
cp LICENSE build/packages/node
cp LICENSE build/packages/express
Expand Down
2 changes: 2 additions & 0 deletions scripts/check-imports.js
Expand Up @@ -27,6 +27,7 @@ function allFilesInDir(dirName) {
function check() {
const exceptions = [
'packages/create-nx-workspace/bin/create-nx-workspace.ts',
'packages/create-nx-plugin/bin/create-nx-plugin.ts',
'packages/web/src/builders/build/build.impl.ts',
'packages/web/src/builders/build/build.impl.spec.ts',
'packages/web/src/utils/web.config.ts',
Expand All @@ -43,6 +44,7 @@ function check() {

const files = [
...allFilesInDir('packages/create-nx-workspace'),
...allFilesInDir('packages/create-nx-plugin'),
...allFilesInDir('packages/cypress'),
...allFilesInDir('packages/express'),
...allFilesInDir('packages/jest'),
Expand Down
1 change: 1 addition & 0 deletions scripts/nx-release.js
Expand Up @@ -151,6 +151,7 @@ const options = {
'package.json',
'build/npm/schematics/package.json',
'build/npm/create-nx-workspace/package.json',
'build/npm/create-nx-plugin/package.json',
'build/npm/jest/package.json',
'build/npm/cypress/package.json',
'build/npm/storybook/package.json',
Expand Down
24 changes: 12 additions & 12 deletions scripts/package.sh
Expand Up @@ -18,33 +18,33 @@ cd build/packages

if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i "" "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace}/src/utils/versions.js
sed -i "" "s|\*|$NX_VERSION|g" {schematics,react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace,nx-plugin}/package.json
sed -i "" "s|\*|$NX_VERSION|g" {schematics,react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json
sed -i "" "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "" "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "" "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "" "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "" "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-plugin.js
sed -i "" "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-plugin.js
sed -i "" "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-plugin.js
sed -i "" "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-workspace/bin/create-nx-plugin.js
sed -i "" "s|NX_VERSION|$NX_VERSION|g" create-nx-plugin/bin/create-nx-plugin.js
sed -i "" "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-plugin/bin/create-nx-plugin.js
sed -i "" "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-plugin/bin/create-nx-plugin.js
sed -i "" "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-plugin/bin/create-nx-plugin.js
else
sed -i "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace}/src/utils/versions.js
sed -i "s|\*|$NX_VERSION|g" {schematics,react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace,nx-plugin}/package.json
sed -i "s|\*|$NX_VERSION|g" {schematics,react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json
sed -i "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-plugin.js
sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-plugin.js
sed -i "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-plugin.js
sed -i "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-workspace/bin/create-nx-plugin.js
sed -i "s|NX_VERSION|$NX_VERSION|g" create-nx-plugin/bin/create-nx-plugin.js
sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-plugin/bin/create-nx-plugin.js
sed -i "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-plugin/bin/create-nx-plugin.js
sed -i "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-plugin/bin/create-nx-plugin.js
fi

if [[ $NX_VERSION == "*" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -E -i "" "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {schematics,jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace,nx-plugin}/package.json
sed -E -i "" "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {schematics,jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json
else
echo $PWD
sed -E -i "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {schematics,jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace,nx-plugin}/package.json
sed -E -i "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {schematics,jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json
fi
fi

0 comments on commit f5d4af2

Please sign in to comment.