@nxrocks/common-cli
Advanced tools
Comparing version 2.2.2 to 2.2.3
{ | ||
"name": "@nxrocks/common-cli", | ||
"description": "Common library to share code among the `create-*` packages.", | ||
"version": "2.2.2", | ||
"private": false, | ||
@@ -9,3 +8,3 @@ "publishConfig": { | ||
}, | ||
"main": "./src/index.js", | ||
"main": "src/index.js", | ||
"license": "MIT", | ||
@@ -41,3 +40,5 @@ "author": "Tine Kondo ", | ||
"devDependencies": {}, | ||
"type": "commonjs" | ||
"type": "commonjs", | ||
"types": "./src/index.d.ts", | ||
"version": "2.2.3" | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mainCLI = void 0; | ||
const tslib_1 = require("tslib"); | ||
exports.mainCLI = mainCLI; | ||
const prompts_1 = require("@clack/prompts"); | ||
@@ -10,75 +9,75 @@ const create_nx_workspace_1 = require("create-nx-workspace"); | ||
const utils_1 = require("./utils"); | ||
function mainCLI(pkgName, stackName) { | ||
var _a; | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const pkgFolderName = pkgName.replace('@nxrocks/', ''); | ||
const createPkgName = `create-${pkgFolderName}`; | ||
(0, prompts_1.intro)(createPkgName); | ||
const options = yargs | ||
.parserConfiguration({ | ||
'strip-dashed': true, | ||
}) | ||
.command('$0 [name]', `Create a new Nx workspace with ${stackName} support`, (yargs) => yargs.option('name', { | ||
describe: 'Workspace name (e.g. org name)', | ||
type: 'string', | ||
}). | ||
option('useNxWrapper', { | ||
describe: 'Let Nx manages its own installation and updates', | ||
type: 'boolean', | ||
}). | ||
option('nxCloud', { | ||
describe: "Do you want Nx Cloud to make your CI fast?", | ||
choices: ['yes', 'github', 'circleci', 'skip'] | ||
}). | ||
option('verbose', { | ||
describe: "Enable more logging information", | ||
type: 'boolean', | ||
default: process.env['NX_VERBOSE_LOGGING'] === 'true', | ||
})) | ||
.help('help', 'Show help').parseSync(); | ||
let { name, useNxWrapper, nxCloud } = options; | ||
const { _, $0, name: ignoredName, verbose } = options, restArgs = tslib_1.__rest(options, ["_", "$0", "name", "verbose"]); | ||
name || (name = (yield (0, prompts_1.text)({ | ||
message: 'What is the name of your workspace (e.g. org name)?', | ||
initialValue: 'myorg', | ||
validate: (value) => ((value === null || value === void 0 ? void 0 : value.length) === 0) ? 'You need to provide one' : void 0, | ||
}))); | ||
useNxWrapper !== null && useNxWrapper !== void 0 ? useNxWrapper : (useNxWrapper = (yield (0, prompts_1.confirm)({ | ||
message: `Would you like to use Nx Wrapper? [ ${linkify('Nx Wrapper', 'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper')} ]`, | ||
initialValue: true | ||
}))); | ||
nxCloud !== null && nxCloud !== void 0 ? nxCloud : (nxCloud = (yield (0, prompts_1.select)({ | ||
message: `Would you like Nx Cloud to make your CI faster? [ ${linkify('Nx Cloud', 'https://nx.app/?utm_source=' + createPkgName)} ]`, | ||
options: [ | ||
{ value: 'yes', label: 'Yes' }, | ||
{ value: 'github', label: 'Github' }, | ||
{ value: 'circleci', label: 'Circle CI' }, | ||
{ value: 'skip', label: 'Skip for now' }, | ||
], | ||
initialValue: 'skip' | ||
}))); | ||
const presetVersion = 'latest'; | ||
let directory; | ||
const notes = [ | ||
`- Go to [ ${linkify(pkgName, 'https://github.com/tinesoft/nxrocks/tree/develop/packages/' + pkgFolderName)} ] to get started with Nx and ${stackName} plugin.`, | ||
`- Run [ ${(0, utils_1.getNxCommand)(useNxWrapper)} g ${pkgName}:project ] to add more projects.` | ||
]; | ||
if (useNxWrapper) { | ||
notes.push(`- Go to [ ${linkify('Nx Wrapper', 'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper')} ] to get started with Nx Wrapper.`); | ||
const allArgs = Object.entries(restArgs).map(([key, value]) => `--${key}=${value}`).join(' '); | ||
const s = (0, prompts_1.spinner)(); | ||
s.start('Initializing your workspace'); | ||
directory = (0, utils_1.createWorkspaceWithNxWrapper)(name, pkgName, allArgs, nxCloud, presetVersion, utils_1.createNxWorkspaceVersion, !verbose); | ||
s.stop(`Successfully created the workspace: ${name}`); | ||
} | ||
else { | ||
directory = (_a = (yield (0, create_nx_workspace_1.createWorkspace)(`${pkgName}@${presetVersion}`, Object.assign(Object.assign({}, restArgs), { name, | ||
nxCloud, packageManager: 'npm' })))) === null || _a === void 0 ? void 0 : _a.directory; | ||
} | ||
notes.push(`- Go to [ ${linkify('Nx.dev', 'https://nx.dev')} ] to get started with Nx.`); | ||
(0, prompts_1.note)(notes.join('\n'), "Next steps"); | ||
(0, prompts_1.outro)(`Your workspace in ${directory} is all set 🎉. Let's goooooo! 🚀`); | ||
async function mainCLI(pkgName, stackName) { | ||
const pkgFolderName = pkgName.replace('@nxrocks/', ''); | ||
const createPkgName = `create-${pkgFolderName}`; | ||
(0, prompts_1.intro)(createPkgName); | ||
const options = yargs | ||
.parserConfiguration({ | ||
'strip-dashed': true, | ||
}) | ||
.command('$0 [name]', `Create a new Nx workspace with ${stackName} support`, (yargs) => yargs.option('name', { | ||
describe: 'Workspace name (e.g. org name)', | ||
type: 'string', | ||
}). | ||
option('useNxWrapper', { | ||
describe: 'Let Nx manages its own installation and updates', | ||
type: 'boolean', | ||
}). | ||
option('nxCloud', { | ||
describe: "Do you want Nx Cloud to make your CI fast?", | ||
choices: ['yes', 'github', 'circleci', 'skip'] | ||
}). | ||
option('verbose', { | ||
describe: "Enable more logging information", | ||
type: 'boolean', | ||
default: process.env['NX_VERBOSE_LOGGING'] === 'true', | ||
})) | ||
.help('help', 'Show help').parseSync(); | ||
let { name, useNxWrapper, nxCloud } = options; | ||
const { _, $0, name: ignoredName, verbose, ...restArgs } = options; | ||
name ||= await (0, prompts_1.text)({ | ||
message: 'What is the name of your workspace (e.g. org name)?', | ||
initialValue: 'myorg', | ||
validate: (value) => (value?.length === 0) ? 'You need to provide one' : void 0, | ||
}); | ||
useNxWrapper ??= await (0, prompts_1.confirm)({ | ||
message: `Would you like to use Nx Wrapper? [ ${linkify('Nx Wrapper', 'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper')} ]`, | ||
initialValue: true | ||
}); | ||
nxCloud ??= await (0, prompts_1.select)({ | ||
message: `Would you like Nx Cloud to make your CI faster? [ ${linkify('Nx Cloud', 'https://nx.app/?utm_source=' + createPkgName)} ]`, | ||
options: [ | ||
{ value: 'yes', label: 'Yes' }, | ||
{ value: 'github', label: 'Github' }, | ||
{ value: 'circleci', label: 'Circle CI' }, | ||
{ value: 'skip', label: 'Skip for now' }, | ||
], | ||
initialValue: 'skip' | ||
}); | ||
const presetVersion = 'latest'; | ||
let directory; | ||
const notes = [ | ||
`- Go to [ ${linkify(pkgName, 'https://github.com/tinesoft/nxrocks/tree/develop/packages/' + pkgFolderName)} ] to get started with Nx and ${stackName} plugin.`, | ||
`- Run [ ${(0, utils_1.getNxCommand)(useNxWrapper)} g ${pkgName}:project ] to add more projects.` | ||
]; | ||
if (useNxWrapper) { | ||
notes.push(`- Go to [ ${linkify('Nx Wrapper', 'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper')} ] to get started with Nx Wrapper.`); | ||
const allArgs = Object.entries(restArgs).map(([key, value]) => `--${key}=${value}`).join(' '); | ||
const s = (0, prompts_1.spinner)(); | ||
s.start('Initializing your workspace'); | ||
directory = (0, utils_1.createWorkspaceWithNxWrapper)(name, pkgName, allArgs, nxCloud, presetVersion, utils_1.createNxWorkspaceVersion, !verbose); | ||
s.stop(`Successfully created the workspace: ${name}`); | ||
} | ||
else { | ||
directory = (await (0, create_nx_workspace_1.createWorkspace)(`${pkgName}@${presetVersion}`, { | ||
...restArgs, | ||
name, | ||
nxCloud, | ||
packageManager: 'npm' | ||
}))?.directory; | ||
} | ||
notes.push(`- Go to [ ${linkify('Nx.dev', 'https://nx.dev')} ] to get started with Nx.`); | ||
(0, prompts_1.note)(notes.join('\n'), "Next steps"); | ||
(0, prompts_1.outro)(`Your workspace in ${directory} is all set 🎉. Let's goooooo! 🚀`); | ||
} | ||
exports.mainCLI = mainCLI; | ||
function linkify(text, url, fallback = (text, url) => url) { | ||
@@ -85,0 +84,0 @@ return terminalLink(text, url, { fallback }); |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
import type { PackageManager } from '@nx/devkit'; | ||
@@ -3,0 +2,0 @@ import { ExecSyncOptions } from 'child_process'; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isNxWrapperInstalled = exports.getNxCommand = exports.hasNxWrapper = exports.runNxWrapperSync = exports.createWorkspaceWithNxWrapper = exports.createNxWorkspaceVersion = void 0; | ||
exports.createNxWorkspaceVersion = void 0; | ||
exports.createWorkspaceWithNxWrapper = createWorkspaceWithNxWrapper; | ||
exports.runNxWrapperSync = runNxWrapperSync; | ||
exports.hasNxWrapper = hasNxWrapper; | ||
exports.getNxCommand = getNxCommand; | ||
exports.isNxWrapperInstalled = isNxWrapperInstalled; | ||
const child_process_1 = require("child_process"); | ||
@@ -9,5 +13,4 @@ const fs_extra_1 = require("fs-extra"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
exports.createNxWorkspaceVersion = ((_a = require('../../package.json')) === null || _a === void 0 ? void 0 : _a.devDependencies['create-nx-workspace']) || 'latest'; | ||
exports.createNxWorkspaceVersion = require('../../package.json')?.devDependencies['create-nx-workspace'] || 'latest'; | ||
function createWorkspaceWithNxWrapper(name, pkgName, extraArgs = '', nxCloud = 'skip', presetVersion = 'latest', nxVersion = exports.createNxWorkspaceVersion, silent = true) { | ||
var _a, _b; | ||
const directory = (0, path_1.resolve)(process.cwd(), name); | ||
@@ -19,7 +22,10 @@ (0, fs_extra_1.rmSync)(directory, { | ||
(0, fs_extra_1.ensureDirSync)(directory); | ||
(0, child_process_1.execSync)(`npx --yes nx@${nxVersion} init --nxCloud=${nxCloud !== 'skip'} --useDotNxInstallation --no-interactive`, Object.assign({ cwd: directory }, (silent ? { stdio: ['ignore', 'ignore', 'ignore'] } : {}))); | ||
(0, child_process_1.execSync)(`npx --yes nx@${nxVersion} init --nxCloud=${nxCloud !== 'skip'} --useDotNxInstallation --no-interactive`, { | ||
cwd: directory, | ||
...(silent ? { stdio: ['ignore', 'ignore', 'ignore'] } : {}), | ||
}); | ||
const nxJsonPath = (0, path_1.resolve)(directory, 'nx.json'); | ||
const nxJson = (0, fs_extra_1.readJSONSync)(nxJsonPath); | ||
nxJson.installation = (_a = nxJson.installation) !== null && _a !== void 0 ? _a : { version: 'latest', plugins: {} }; | ||
nxJson.installation.plugins = (_b = nxJson.installation.plugins) !== null && _b !== void 0 ? _b : {}; | ||
nxJson.installation = nxJson.installation ?? { version: 'latest', plugins: {} }; | ||
nxJson.installation.plugins = nxJson.installation.plugins ?? {}; | ||
nxJson.installation.plugins[pkgName] = presetVersion; | ||
@@ -34,10 +40,8 @@ (0, fs_extra_1.writeJsonSync)(nxJsonPath, nxJson, { spaces: 2 }); | ||
} | ||
exports.createWorkspaceWithNxWrapper = createWorkspaceWithNxWrapper; | ||
// Inspired from https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/child-process.ts#runNxSync() | ||
function runNxWrapperSync(cmd, options) { | ||
var _a, _b; | ||
let baseCmd; | ||
options !== null && options !== void 0 ? options : (options = {}); | ||
(_a = options.cwd) !== null && _a !== void 0 ? _a : (options.cwd = process.cwd()); | ||
const offsetFromRoot = (0, path_1.relative)(options.cwd, (_b = workspaceRootInner(options.cwd, null)) !== null && _b !== void 0 ? _b : ''); | ||
options ??= {}; | ||
options.cwd ??= process.cwd(); | ||
const offsetFromRoot = (0, path_1.relative)(options.cwd, workspaceRootInner(options.cwd, null) ?? ''); | ||
if (process.platform === 'win32') { | ||
@@ -51,3 +55,2 @@ baseCmd = '.\\' + (0, path_1.join)(`${offsetFromRoot}`, 'nx.bat'); | ||
} | ||
exports.runNxWrapperSync = runNxWrapperSync; | ||
function hasNxWrapper(cwd) { | ||
@@ -61,3 +64,2 @@ return [ | ||
} | ||
exports.hasNxWrapper = hasNxWrapper; | ||
function getNxCommand(useNxWrapper = true, pkgManager = 'npm') { | ||
@@ -75,3 +77,2 @@ if (!useNxWrapper) { | ||
} | ||
exports.getNxCommand = getNxCommand; | ||
function isNxWrapperInstalled(cwd) { | ||
@@ -83,3 +84,2 @@ return hasNxWrapper(cwd) && [ | ||
} | ||
exports.isNxWrapperInstalled = isNxWrapperInstalled; | ||
// Copied from https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/workspace-root.ts | ||
@@ -86,0 +86,0 @@ // Mainly because workspaceRootInner is not exported by @nx/devkit |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24673
219