Skip to content

Commit

Permalink
feat(conventions): Allow to specify interactive value to decide if in…
Browse files Browse the repository at this point in the history
…put are requested or not from create-workspace or project type generator
  • Loading branch information
jogelin committed May 5, 2024
1 parent 0d85afd commit f684594
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ProjectTypeGeneratorExtraSchema = ProjectTypeGeneratorSchema & { extraOptio
async function runGenerator(generator: string, options: GeneratorOptions) {
installNxPlugin(generator.split(':')[0]);

const generatorCmd = `${getPmc().exec} nx g ${generator} ${objectToInlineArgs(options)} --no-interactive`;
const generatorCmd = `${getPmc().exec} nx g ${generator} ${objectToInlineArgs(options)}`;
output.log({
title: `Apply generator ${generator} on project ${options.name}`,
bodyLines: [generatorCmd],
Expand Down
20 changes: 10 additions & 10 deletions packages/create-huge-nx/bin/create-huge-nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { showNxWarning } from 'create-nx-workspace/src/utils/nx/show-nx-warning'
import { existsSync } from 'node:fs';
import * as chalk from 'chalk';
import { execSync } from 'node:child_process';
import { hugeNxVersion } from '@huge-nx/devkit';
import { hugeNxVersion, objectToInlineArgs } from '@huge-nx/devkit';

interface Arguments extends CreateWorkspaceOptions {
hugeNxConventions: string;
Expand Down Expand Up @@ -41,6 +41,11 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
describe: chalk.dim`Nx version to use in the new workspace`,
default: 'latest',
type: 'string',
})
.option('interactive', {
describe: 'When false disables interactive input prompts for options.',
type: 'boolean',
default: true,
}),
withNxCloud,
withAllPrompts,
Expand Down Expand Up @@ -71,7 +76,7 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
async function main(parsedArgs: yargs.Arguments<Arguments>) {
const createNxWorkspaceCmd = `npx --yes create-nx-workspace@${parsedArgs.nxVersion} --preset "@huge-nx/conventions@${hugeNxVersion}" ${getInlineArgv(
parsedArgs
)} --no-interactive`;
)}`;

output.log({
title: `Creating your Huge Nx workspace with Nx ${parsedArgs.nxVersion} and preset @huge-nx/conventions@${hugeNxVersion}`,
Expand Down Expand Up @@ -124,7 +129,7 @@ function getInlineArgv(argv: yargs.Arguments<Arguments>): string {
'packageManager',
'defaultBase',
'nxCloud',
// 'interactive',
'interactive',
// 'skipGit',
// 'commit',
// 'cliName',
Expand All @@ -136,15 +141,10 @@ function getInlineArgv(argv: yargs.Arguments<Arguments>): string {
...(createNxArgsKeys.includes(key as keyof Arguments) && { [key]: argv[key] }),
}),
{}
) as Arguments;
) as Record<string, string | boolean | number>;

//transform filteredArgv to inline arguments
return Object.entries(filteredArgv).reduce((acc, [key, value]) => {
if (typeof value === 'boolean') {
return acc + (value ? ` --${key}` : '');
}
return acc + ` --${key}=${value}`;
}, '');
return objectToInlineArgs(filteredArgv);
}

function invariant<T = string | number | boolean>(predicate: T, message: CLIErrorMessageConfig): asserts predicate is NonNullable<T> {
Expand Down
2 changes: 1 addition & 1 deletion tools/scripts/publish-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if (!hugeNxConventionsArgv || !workspaceName) {

rmSync(workspaceName, { force: true, recursive: true });

const createCmd = `npx --yes create-huge-nx@latest ${workspaceName} --hugeNxConventions=${hugeNxConventionsArgv} --nxVersion ${nxVersion} --nxCloud skip --verbose`;
const createCmd = `npx --yes create-huge-nx@latest ${workspaceName} --hugeNxConventions=${hugeNxConventionsArgv} --nxVersion ${nxVersion} --nxCloud skip --interactive false --verbose`;

console.log(createCmd);

Expand Down

0 comments on commit f684594

Please sign in to comment.