Skip to content

Commit 8e2d5f9

Browse files
committed
Revert "refactor(@angular/cli): import markdown files directly for command descriptions"
This reverts commit 3d7f081.
1 parent 6ffd267 commit 8e2d5f9

27 files changed

Lines changed: 59 additions & 119 deletions

File tree

packages/angular/cli/src/command-builder/command-module.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88

99
import { schema } from '@angular-devkit/core';
10+
import { readFileSync } from 'node:fs';
11+
import { join, posix, relative } from 'node:path';
1012
import type { ArgumentsCamelCase, Argv, CommandModule as YargsCommandModule } from 'yargs';
1113
import { Parser as yargsParser } from 'yargs/helpers';
1214
import { getAnalyticsUserId } from '../analytics/analytics';
@@ -18,7 +20,6 @@ import { AngularWorkspace } from '../utilities/config';
1820
import { memoize } from '../utilities/memoize';
1921
import { CommandContext, CommandScope, Options, OtherOptions } from './definitions';
2022
import { Option, addSchemaOptionsToCommand } from './utilities/json-schema';
21-
import '../utilities/markdown-loader';
2223

2324
export { CommandScope };
2425
export type { CommandContext, Options, OtherOptions };
@@ -30,11 +31,8 @@ export interface CommandModuleImplementation<T extends {} = {}> extends Omit<
3031
/** Scope in which the command can be executed in. */
3132
scope: CommandScope;
3233

33-
/** Long description for the command in JSON help text. */
34-
longDescription?: string;
35-
36-
/** Relative path to the long description file for the command in JSON help text. */
37-
longDescriptionRelativePath?: string;
34+
/** Path used to load the long description for the command in JSON help text. */
35+
longDescriptionPath?: string;
3836

3937
/** Object declaring the options the command accepts, or a function accepting and returning a yargs instance. */
4038
builder(argv: Argv): Promise<Argv<T>> | Argv<T>;
@@ -52,8 +50,7 @@ export interface FullDescribe {
5250
export abstract class CommandModule<T extends {} = {}> implements CommandModuleImplementation<T> {
5351
abstract readonly command: string;
5452
abstract readonly describe: string | false;
55-
readonly longDescription?: string;
56-
readonly longDescriptionRelativePath?: string;
53+
abstract readonly longDescriptionPath?: string;
5754
protected readonly shouldReportAnalytics: boolean = true;
5855
readonly scope: CommandScope = CommandScope.Both;
5956

@@ -71,22 +68,23 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
7168
* `false` will result in a hidden command.
7269
*/
7370
public get fullDescribe(): FullDescribe | false {
74-
if (this.describe === false) {
75-
return false;
76-
}
77-
78-
const description: FullDescribe = {
79-
describe: this.describe,
80-
};
81-
82-
if (this.longDescription) {
83-
description.longDescription = this.longDescription.replace(/\r\n/g, '\n');
84-
description.longDescriptionRelativePath =
85-
this.longDescriptionRelativePath ??
86-
`@angular/cli/src/commands/${this.commandName}/long-description.md`;
87-
}
88-
89-
return description;
71+
return this.describe === false
72+
? false
73+
: {
74+
describe: this.describe,
75+
...(this.longDescriptionPath
76+
? {
77+
longDescriptionRelativePath: relative(
78+
join(__dirname, '../../../../'),
79+
this.longDescriptionPath,
80+
).replace(/\\/g, posix.sep),
81+
longDescription: readFileSync(this.longDescriptionPath, 'utf8').replace(
82+
/\r\n/g,
83+
'\n',
84+
),
85+
}
86+
: {}),
87+
};
9088
}
9189

9290
protected get commandName(): string {

packages/angular/cli/src/commands/add/cli.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ import { NgAddSaveDependency, PackageManifest, PackageMetadata } from '../../pac
2929
import { assertIsError } from '../../utilities/error';
3030
import { isTTY } from '../../utilities/tty';
3131
import { VERSION } from '../../utilities/version';
32-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
33-
// @ts-ignore strict-deps: Markdown files are asset dependencies bundled/loaded at runtime
34-
import longDescription from './long-description.md';
3532

3633
class CommandError extends Error {}
3734

@@ -103,7 +100,7 @@ export default class AddCommandModule
103100
{
104101
command = 'add <collection>';
105102
describe = 'Adds support for an external library to your project.';
106-
override longDescription = longDescription;
103+
longDescriptionPath = join(__dirname, 'long-description.md');
107104
protected override allowPrivateSchematics = true;
108105
private readonly schematicName = 'ng-add';
109106
private rootRequire = createRequire(this.context.root + '/');

packages/angular/cli/src/commands/analytics/cli.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import { join } from 'node:path';
910
import { Argv } from 'yargs';
1011
import {
1112
CommandModule,
@@ -17,9 +18,6 @@ import {
1718
demandCommandFailureMessage,
1819
} from '../../command-builder/utilities/command';
1920
import { AnalyticsInfoCommandModule } from './info/cli';
20-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
21-
// @ts-ignore strict-deps: Markdown files are asset dependencies bundled/loaded at runtime
22-
import longDescription from './long-description.md';
2321
import {
2422
AnalyticsDisableModule,
2523
AnalyticsEnableModule,
@@ -32,7 +30,7 @@ export default class AnalyticsCommandModule
3230
{
3331
command = 'analytics';
3432
describe = 'Configures the gathering of Angular CLI usage metrics.';
35-
override longDescription = longDescription;
33+
longDescriptionPath = join(__dirname, 'long-description.md');
3634

3735
builder(localYargs: Argv): Argv {
3836
const subcommands = [

packages/angular/cli/src/commands/analytics/info/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class AnalyticsInfoCommandModule
2020
{
2121
command = 'info';
2222
describe = 'Prints analytics gathering and reporting configuration in the console.';
23+
longDescriptionPath?: string;
2324

2425
builder(localYargs: Argv): Argv {
2526
return localYargs.strict();

packages/angular/cli/src/commands/analytics/settings/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ abstract class AnalyticsSettingModule
2626
extends CommandModule<AnalyticsCommandArgs>
2727
implements CommandModuleImplementation<AnalyticsCommandArgs>
2828
{
29+
longDescriptionPath?: string;
30+
2931
builder(localYargs: Argv): Argv<AnalyticsCommandArgs> {
3032
return localYargs
3133
.option('global', {

packages/angular/cli/src/commands/build/cli.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import { join } from 'node:path';
910
import { ArchitectCommandModule } from '../../command-builder/architect-command-module';
1011
import { CommandModuleImplementation } from '../../command-builder/command-module';
1112
import { RootCommands } from '../command-config';
12-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
13-
// @ts-ignore strict-deps: Markdown files are asset dependencies bundled/loaded at runtime
14-
import longDescription from './long-description.md';
1513

1614
export default class BuildCommandModule
1715
extends ArchitectCommandModule
@@ -22,5 +20,5 @@ export default class BuildCommandModule
2220
aliases = RootCommands['build'].aliases;
2321
describe =
2422
'Compiles an Angular application or library into an output directory named dist/ at the given output path.';
25-
override longDescription = longDescription;
23+
longDescriptionPath = join(__dirname, 'long-description.md');
2624
}

packages/angular/cli/src/commands/cache/clean/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { getCacheConfig } from '../utilities';
1818
export class CacheCleanModule extends CommandModule implements CommandModuleImplementation {
1919
command = 'clean';
2020
describe = 'Deletes persistent disk cache from disk.';
21+
longDescriptionPath: string | undefined;
2122
override scope = CommandScope.In;
2223

2324
builder(localYargs: Argv): Argv {

packages/angular/cli/src/commands/cache/cli.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import { join } from 'node:path';
910
import { Argv } from 'yargs';
1011
import {
1112
CommandModule,
@@ -19,9 +20,6 @@ import {
1920
} from '../../command-builder/utilities/command';
2021
import { CacheCleanModule } from './clean/cli';
2122
import { CacheInfoCommandModule } from './info/cli';
22-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
23-
// @ts-ignore strict-deps: Markdown files are asset dependencies bundled/loaded at runtime
24-
import longDescription from './long-description.md';
2523
import { CacheDisableModule, CacheEnableModule } from './settings/cli';
2624

2725
export default class CacheCommandModule
@@ -30,7 +28,7 @@ export default class CacheCommandModule
3028
{
3129
command = 'cache';
3230
describe = 'Configure persistent disk cache and retrieve cache statistics.';
33-
override longDescription = longDescription;
31+
longDescriptionPath = join(__dirname, 'long-description.md');
3432
override scope = CommandScope.In;
3533

3634
builder(localYargs: Argv): Argv {

packages/angular/cli/src/commands/cache/info/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { getCacheConfig } from '../utilities';
2121
export class CacheInfoCommandModule extends CommandModule implements CommandModuleImplementation {
2222
command = 'info';
2323
describe = 'Prints persistent disk cache configuration and statistics in the console.';
24+
longDescriptionPath?: string | undefined;
2425
override scope = CommandScope.In;
2526

2627
builder(localYargs: Argv): Argv {

packages/angular/cli/src/commands/cache/settings/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class CacheDisableModule extends CommandModule implements CommandModuleIm
1818
command = 'disable';
1919
aliases = 'off';
2020
describe = 'Disables persistent disk cache for all projects in the workspace.';
21+
longDescriptionPath: string | undefined;
2122
override scope = CommandScope.In;
2223

2324
builder(localYargs: Argv): Argv {
@@ -33,6 +34,7 @@ export class CacheEnableModule extends CommandModule implements CommandModuleImp
3334
command = 'enable';
3435
aliases = 'on';
3536
describe = 'Enables disk cache for all projects in the workspace.';
37+
longDescriptionPath: string | undefined;
3638
override scope = CommandScope.In;
3739

3840
builder(localYargs: Argv): Argv {

0 commit comments

Comments
 (0)