feat(misc): move create-nx-plugin create script into create-nx-workspace package
This commit is contained in:
parent
77238e2ce7
commit
6706a05042
@ -8,6 +8,7 @@ import * as path from 'path';
|
|||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import * as inquirer from 'inquirer';
|
import * as inquirer from 'inquirer';
|
||||||
import yargsParser = require('yargs-parser');
|
import yargsParser = require('yargs-parser');
|
||||||
|
import { determinePackageManager, showNxWarning } from './shared';
|
||||||
|
|
||||||
const tsVersion = 'TYPESCRIPT_VERSION';
|
const tsVersion = 'TYPESCRIPT_VERSION';
|
||||||
const cliVersion = 'NX_VERSION';
|
const cliVersion = 'NX_VERSION';
|
||||||
@ -29,7 +30,7 @@ if (parsedArgs.help) {
|
|||||||
|
|
||||||
const packageManager = determinePackageManager();
|
const packageManager = determinePackageManager();
|
||||||
determineWorkspaceName(parsedArgs).then(workspaceName => {
|
determineWorkspaceName(parsedArgs).then(workspaceName => {
|
||||||
return determinPluginName(parsedArgs).then(pluginName => {
|
return determinePluginName(parsedArgs).then(pluginName => {
|
||||||
const tmpDir = createSandbox(packageManager);
|
const tmpDir = createSandbox(packageManager);
|
||||||
createWorkspace(tmpDir, packageManager, parsedArgs, workspaceName);
|
createWorkspace(tmpDir, packageManager, parsedArgs, workspaceName);
|
||||||
createNxPlugin(workspaceName, pluginName);
|
createNxPlugin(workspaceName, pluginName);
|
||||||
@ -113,72 +114,6 @@ function commitChanges(workspaceName) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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.`
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move to @nrwl/workspace package?
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
function determineWorkspaceName(parsedArgs: any): Promise<string> {
|
function determineWorkspaceName(parsedArgs: any): Promise<string> {
|
||||||
const workspaceName: string = parsedArgs._[2];
|
const workspaceName: string = parsedArgs._[2];
|
||||||
|
|
||||||
@ -206,7 +141,7 @@ function determineWorkspaceName(parsedArgs: any): Promise<string> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function determinPluginName(parsedArgs) {
|
function determinePluginName(parsedArgs) {
|
||||||
if (parsedArgs.pluginName) {
|
if (parsedArgs.pluginName) {
|
||||||
return Promise.resolve(parsedArgs.pluginName);
|
return Promise.resolve(parsedArgs.pluginName);
|
||||||
}
|
}
|
||||||
@ -239,7 +174,7 @@ function showHelp() {
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
||||||
name workspace name
|
name workspace name (e.g., org name)
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
@ -8,6 +8,7 @@ import * as inquirer from 'inquirer';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { dirSync } from 'tmp';
|
import { dirSync } from 'tmp';
|
||||||
import * as yargsParser from 'yargs-parser';
|
import * as yargsParser from 'yargs-parser';
|
||||||
|
import { determinePackageManager, showNxWarning } from './shared';
|
||||||
|
|
||||||
enum Preset {
|
enum Preset {
|
||||||
Empty = 'empty',
|
Empty = 'empty',
|
||||||
@ -109,7 +110,7 @@ function showHelp() {
|
|||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
name workspace name
|
name workspace name (e.g., org name)
|
||||||
|
|
||||||
preset What to create in a new workspace (options: ${options})
|
preset What to create in a new workspace (options: ${options})
|
||||||
|
|
||||||
@ -126,51 +127,6 @@ function showHelp() {
|
|||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
function determineWorkspaceName(parsedArgs: any): Promise<string> {
|
function determineWorkspaceName(parsedArgs: any): Promise<string> {
|
||||||
const workspaceName: string = parsedArgs._[2];
|
const workspaceName: string = parsedArgs._[2];
|
||||||
|
|
||||||
@ -464,26 +420,6 @@ function createApp(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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.`
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function showCliWarning(preset: Preset, parsedArgs: yargsParser.Arguments) {
|
function showCliWarning(preset: Preset, parsedArgs: yargsParser.Arguments) {
|
||||||
if (!parsedArgs.cli) {
|
if (!parsedArgs.cli) {
|
||||||
switch (preset) {
|
switch (preset) {
|
||||||
|
|||||||
68
packages/create-nx-workspace/bin/shared.ts
Normal file
68
packages/create-nx-workspace/bin/shared.ts
Normal file
@ -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;
|
||||||
|
}
|
||||||
@ -18,7 +18,8 @@
|
|||||||
"CLI"
|
"CLI"
|
||||||
],
|
],
|
||||||
"bin": {
|
"bin": {
|
||||||
"create-nx-workspace": "./bin/create-nx-workspace.js"
|
"create-nx-workspace": "./bin/create-nx-workspace.js",
|
||||||
|
"create-nx-plugin": "./bin/create-nx-plugin.js"
|
||||||
},
|
},
|
||||||
"author": "Victor Savkin",
|
"author": "Victor Savkin",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@ -1,22 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "@nrwl/nx-plugin",
|
"name": "@nrwl/nx-plugin",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "Node Plugin for Nx",
|
"description": "Plugin for creating plugins for Nx :)",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/nrwl/nx.git"
|
"url": "git+https://github.com/nrwl/nx.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Monorepo",
|
"Monorepo",
|
||||||
"Node",
|
"Nx",
|
||||||
"Nest",
|
|
||||||
"Jest",
|
|
||||||
"Cypress",
|
|
||||||
"CLI"
|
"CLI"
|
||||||
],
|
],
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
"types": "./index.d.ts",
|
"types": "./index.d.ts",
|
||||||
"bin": "./bin/create.js",
|
|
||||||
"author": "Nrwl",
|
"author": "Nrwl",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
@ -35,8 +31,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nrwl/node": "*",
|
"@nrwl/node": "*",
|
||||||
"@nrwl/linter": "*",
|
"@nrwl/linter": "*",
|
||||||
"@nrwl/workspace": "*",
|
|
||||||
"@nrwl/tao": "*",
|
|
||||||
"@angular-devkit/architect": "0.803.23",
|
"@angular-devkit/architect": "0.803.23",
|
||||||
"@angular-devkit/core": "8.3.23",
|
"@angular-devkit/core": "8.3.23",
|
||||||
"@angular-devkit/schematics": "8.3.23",
|
"@angular-devkit/schematics": "8.3.23",
|
||||||
|
|||||||
@ -29,7 +29,7 @@ rm -rf build/packages/angular/bundles/nrwl-angular-testing.umd.min.js.bak
|
|||||||
|
|
||||||
rsync -a --exclude=*.ts packages/ build/packages
|
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-workspace.js
|
||||||
chmod +x build/packages/nx-plugin/bin/create.js
|
chmod +x build/packages/create-nx-workspace/bin/create-nx-plugin.js
|
||||||
chmod +x build/packages/cli/bin/nx.js
|
chmod +x build/packages/cli/bin/nx.js
|
||||||
chmod +x build/packages/tao/index.js
|
chmod +x build/packages/tao/index.js
|
||||||
|
|
||||||
|
|||||||
@ -23,10 +23,10 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
|
|||||||
sed -i "" "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_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|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|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
|
||||||
sed -i "" "s|NX_VERSION|$NX_VERSION|g" nx-plugin/bin/create.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" nx-plugin/bin/create.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" nx-plugin/bin/create.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" nx-plugin/bin/create.js
|
sed -i "" "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-workspace/bin/create-nx-plugin.js
|
||||||
else
|
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|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,nx-plugin}/package.json
|
||||||
@ -34,10 +34,10 @@ else
|
|||||||
sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_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|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|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
|
||||||
sed -i "s|NX_VERSION|$NX_VERSION|g" nx-plugin/bin/create.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" nx-plugin/bin/create.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" nx-plugin/bin/create.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" nx-plugin/bin/create.js
|
sed -i "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-workspace/bin/create-nx-plugin.js
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $NX_VERSION == "*" ]]; then
|
if [[ $NX_VERSION == "*" ]]; then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user