Skip to content

Commit

Permalink
fix(core): update markup generation
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Mar 29, 2022
1 parent 68039be commit 86dee30
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 47 deletions.
6 changes: 6 additions & 0 deletions docs/generated/cli/create-nx-workspace.md
Expand Up @@ -29,6 +29,8 @@ The name of the application when a preset with pregenerated app is selected

### cli

Choices: `["nx", "angular"]`

CLI to power the Nx workspace

### defaultBase
Expand Down Expand Up @@ -59,10 +61,14 @@ Use Nx Cloud

Default: `npm`

Choices: `["npm", "pnpm", "yarn"]`

Package manager to use

### preset

Choices: `["apps", "empty", "core", "npm", "ts", "web-components", "angular", "angular-nest", "react", "react-express", "react-native", "next", "nest", "express"]`

Customizes the initial content of your workspace. To build your own see https://nx.dev/nx-plugin/overview#preset

### style
Expand Down
4 changes: 1 addition & 3 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { exec } from 'child_process';
import { writeFileSync } from 'fs';
import * as enquirer from 'enquirer';
Expand Down Expand Up @@ -168,7 +166,7 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
.option('packageManager', {
alias: 'pm',
describe: `Package manager to use`,
choices: packageManagerList,
choices: [...packageManagerList].sort(),
defaultDescription: 'npm',
type: 'string',
})
Expand Down
2 changes: 2 additions & 0 deletions packages/create-nx-workspace/bin/index.ts
@@ -1,3 +1,5 @@
#!/usr/bin/env node

import { commandsObject } from './create-nx-workspace';

commandsObject.argv;
4 changes: 2 additions & 2 deletions packages/create-nx-workspace/bin/package-manager.ts
Expand Up @@ -7,7 +7,7 @@ import { join } from 'path';
* we duplicate the helper functions from @nrwl/workspace in this file.
*/

export const packageManagerList = ['npm', 'yarn', 'pnpm'] as const;
export const packageManagerList = ['pnpm', 'yarn', 'npm'] as const;

export type PackageManager = typeof packageManagerList[number];

Expand Down Expand Up @@ -109,7 +109,7 @@ export function detectInvokedPackageManager(): PackageManager {
if (!invoker) {
return detectedPackageManager;
}

console.log(invoker.path);
for (const pkgManager of packageManagerList) {
if (invoker.path.includes(pkgManager)) {
detectedPackageManager = pkgManager;
Expand Down
21 changes: 2 additions & 19 deletions scripts/documentation/generate-cli-data.ts
Expand Up @@ -5,6 +5,7 @@ import { join } from 'path';
import {
formatDeprecated,
generateMarkdownFile,
generateOptionsMarkdown,
getCommands,
parseCommand,
ParsedCommand,
Expand Down Expand Up @@ -77,25 +78,7 @@ nx ${command.commandString}
});
}

if (Array.isArray(command.options) && !!command.options.length) {
template += '\n## Options';

command.options
.sort((a, b) => sortAlphabeticallyFunction(a.name, b.name))
.forEach((option) => {
template += dedent`
### ${option.deprecated ? `~~${option.name}~~` : option.name}
${
option.default === undefined || option.default === ''
? ''
: `Default: \`${option.default}\`\n`
}
`;
template += dedent`
${formatDeprecated(option.description, option.deprecated)}
`;
});
}
template += generateOptionsMarkdown(command);

return {
name: command.name
Expand Down
26 changes: 3 additions & 23 deletions scripts/documentation/generate-cnw-documentation.ts
Expand Up @@ -7,6 +7,7 @@ import {
ParsedCommand,
sortAlphabeticallyFunction,
formatDeprecated,
generateOptionsMarkdown,
} from './utils';
const importFresh = require('import-fresh');

Expand Down Expand Up @@ -55,31 +56,10 @@ function generateMarkdown(command: ParsedCommand) {
Install \`create-nx-workspace\` globally to invoke the command directly, or use \`npx create-nx-workspace\`, \`yarn create nx-workspace\`, or \`pnpx create-nx-workspace\`.\n`;

if (Array.isArray(command.options) && !!command.options.length) {
template += '\n## Options';

command.options
.sort((a, b) => sortAlphabeticallyFunction(a.name, b.name))
.forEach((option) => {
template += dedent`
### ${option.deprecated ? `~~${option.name}~~` : option.name}
${
option.default === undefined || option.default === ''
? ''
: `Default: \`${option.default}\`\n`
}
`;
template += dedent`
${formatDeprecated(option.description, option.deprecated)}
`;
});
}
template += generateOptionsMarkdown(command);

return {
name: command.name
.replace(':', '-')
.replace(' ', '-')
.replace(/[\]\[.]+/gm, ''),
name: command.name,
template,
};
}
33 changes: 33 additions & 0 deletions scripts/documentation/utils.ts
Expand Up @@ -155,6 +155,7 @@ export async function parseCommand(
const builderDefaultOptions = builder.getOptions().default;
const builderAutomatedOptions = builder.getOptions().defaultDescription;
const builderDeprecatedOptions = builder.getDeprecatedOptions();
const builderOptionsChoices = builder.getOptions().choices;

return {
name,
Expand All @@ -167,7 +168,39 @@ export async function parseCommand(
? builderDescriptions[key].replace('__yargsString__:', '')
: '',
default: builderDefaultOptions[key] ?? builderAutomatedOptions[key],
choices: builderOptionsChoices[key],
deprecated: builderDeprecatedOptions[key],
})) || null,
};
}

export function generateOptionsMarkdown(command): string {
let response = '';
if (Array.isArray(command.options) && !!command.options.length) {
response += '\n## Options';

command.options
.sort((a, b) => sortAlphabeticallyFunction(a.name, b.name))
.forEach((option) => {
response += dedent`
### ${option.deprecated ? `~~${option.name}~~` : option.name}
${
option.default === undefined || option.default === ''
? ''
: `Default: \`${option.default}\`\n`
}`;
response += dedent`
${
option.choices === undefined
? ''
: `Choices: \`[${option.choices
.map((c) => `"${c}"`)
.join(', ')}]\`\n`
}`;
response += dedent`
${formatDeprecated(option.description, option.deprecated)}
`;
});
}
return response;
}

0 comments on commit 86dee30

Please sign in to comment.