Skip to content

Commit baeb72c

Browse files
hanslclydin
authored andcommitted
refactor: fix types to remove any
require() returns any so we were missing some typing errors.
1 parent 08e1762 commit baeb72c

21 files changed

+81
-57
lines changed

Diff for: packages/angular/cli/commands/add.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import { NpmInstall } from '../tasks/npm-install';
1616
import { getPackageManager } from '../utilities/config';
1717

1818

19-
export default class AddCommand extends SchematicCommand {
19+
export class AddCommand extends SchematicCommand {
2020
readonly name = 'add';
2121
readonly description = 'Add support for a library to your project.';
2222
readonly allowPrivateSchematics = true;
23-
scope = CommandScope.inProject;
23+
static aliases = [];
24+
static scope = CommandScope.inProject;
2425
arguments = ['collection'];
2526
options: Option[] = [];
2627

Diff for: packages/angular/cli/commands/build.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
1010
import { CommandScope, Option } from '../models/command';
1111
import { Version } from '../upgrade/version';
1212

13-
export default class BuildCommand extends ArchitectCommand {
13+
export class BuildCommand extends ArchitectCommand {
1414
public readonly name = 'build';
1515
public readonly target = 'build';
1616
public readonly description =
1717
'Builds your app and places it into the output path (dist/ by default).';
1818
public static aliases = ['b'];
19-
public scope = CommandScope.inProject;
19+
public static scope = CommandScope.inProject;
2020
public options: Option[] = [
2121
this.prodOption,
2222
this.configurationOption,

Diff for: packages/angular/cli/commands/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function normalizeValue(value: string, path: string): JsonValue {
178178
return value;
179179
}
180180

181-
export default class ConfigCommand extends Command {
181+
export class ConfigCommand extends Command {
182182
public readonly name = 'config';
183183
public readonly description = 'Get/set configuration values.';
184184
public readonly arguments = ['jsonPath', 'value'];

Diff for: packages/angular/cli/commands/doc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface Options {
1414
search?: boolean;
1515
}
1616

17-
export default class DocCommand extends Command {
17+
export class DocCommand extends Command {
1818
public readonly name = 'doc';
1919
public readonly description = 'Opens the official Angular API documentation for a given keyword.';
2020
public static aliases = ['d'];

Diff for: packages/angular/cli/commands/e2e.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
1010
import { CommandScope, Option } from '../models/command';
1111

1212

13-
export default class E2eCommand extends ArchitectCommand {
13+
export class E2eCommand extends ArchitectCommand {
1414
public readonly name = 'e2e';
1515
public readonly target = 'e2e';
1616
public readonly description = 'Run e2e tests in existing project.';
1717
public static aliases: string[] = ['e'];
18-
public readonly scope = CommandScope.inProject;
18+
public static scope = CommandScope.inProject;
1919
public readonly multiTarget = true;
2020
public readonly options: Option[] = [
2121
this.prodOption,

Diff for: packages/angular/cli/commands/easter-egg.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function pickOne(of: string[]): string {
1313
return of[Math.floor(Math.random() * of.length)];
1414
}
1515

16-
export default class AwesomeCommand extends Command {
16+
export class AwesomeCommand extends Command {
1717
public readonly name = 'make-this-awesome';
1818
public readonly description = '';
1919
public readonly hidden = true;

Diff for: packages/angular/cli/commands/eject.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import { tags } from '@angular-devkit/core';
1010
import { Command, Option } from '../models/command';
1111

1212

13-
export default class EjectCommand extends Command {
13+
export class EjectCommand extends Command {
1414
public readonly name = 'eject';
1515
public readonly description = 'Temporarily disabled. Ejects your app and output the proper '
1616
+ 'webpack configuration and scripts.';
1717
public readonly arguments: string[] = [];
1818
public readonly options: Option[] = [];
19+
public static aliases = [];
1920

2021
run() {
2122
this.logger.info(tags.stripIndents`

Diff for: packages/angular/cli/commands/generate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import {
1717
} from '../utilities/schematics';
1818

1919

20-
export default class GenerateCommand extends SchematicCommand {
20+
export class GenerateCommand extends SchematicCommand {
2121
public readonly name = 'generate';
2222
public readonly description = 'Generates and/or modifies files based on a schematic.';
2323
public static aliases = ['g'];
24-
public readonly scope = CommandScope.inProject;
24+
public static scope = CommandScope.inProject;
2525
public arguments = ['schematic'];
2626
public options: Option[] = [
2727
...this.coreOptions,

Diff for: packages/angular/cli/commands/getset.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface Options {
1313
search?: boolean;
1414
}
1515

16-
export default class GetSetCommand extends Command {
16+
export class GetSetCommand extends Command {
1717
public readonly name = 'getset';
1818
public readonly description = 'Deprecated in favor of config command.';
1919
public readonly arguments: string[] = [];

Diff for: packages/angular/cli/commands/help.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { terminal } from '@angular-devkit/core';
1111
import { Command, Option } from '../models/command';
1212

1313

14-
export default class HelpCommand extends Command {
14+
export class HelpCommand extends Command {
1515
public readonly name = 'help';
1616
public readonly description = 'Help.';
1717
public readonly arguments: string[] = [];

Diff for: packages/angular/cli/commands/lint.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
1010
import { CommandScope, Option } from '../models/command';
1111

1212

13-
export default class LintCommand extends ArchitectCommand {
13+
export class LintCommand extends ArchitectCommand {
1414
public readonly name = 'lint';
1515
public readonly target = 'lint';
1616
public readonly description = 'Lints code in existing project.';
1717
public static aliases = ['l'];
18-
public readonly scope = CommandScope.inProject;
18+
public static scope = CommandScope.inProject;
1919
public readonly multiTarget = true;
2020
public readonly options: Option[] = [
2121
this.configurationOption,

Diff for: packages/angular/cli/commands/new.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import { SchematicCommand } from '../models/schematic-command';
1212
import { getDefaultSchematicCollection } from '../utilities/config';
1313

1414

15-
export default class NewCommand extends SchematicCommand {
15+
export class NewCommand extends SchematicCommand {
1616
public readonly name = 'new';
1717
public readonly description =
1818
'Creates a new directory and a new Angular app.';
1919
public static aliases = ['n'];
20-
public scope = CommandScope.outsideProject;
20+
public static scope = CommandScope.outsideProject;
2121
public readonly allowMissingWorkspace = true;
2222
public arguments: string[] = [];
2323
public options: Option[] = [

Diff for: packages/angular/cli/commands/run.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
1010
import { CommandScope, Option } from '../models/command';
1111

1212

13-
export default class RunCommand extends ArchitectCommand {
13+
export class RunCommand extends ArchitectCommand {
1414
public readonly name = 'run';
1515
public readonly description = 'Runs Architect targets.';
16-
public readonly scope = CommandScope.inProject;
16+
public static scope = CommandScope.inProject;
17+
public static aliases = [];
1718
public readonly arguments: string[] = ['target'];
1819
public readonly options: Option[] = [
1920
this.configurationOption,

Diff for: packages/angular/cli/commands/serve.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import { CommandScope, Option } from '../models/command';
1111
import { Version } from '../upgrade/version';
1212

1313

14-
export default class ServeCommand extends ArchitectCommand {
14+
export class ServeCommand extends ArchitectCommand {
1515
public readonly name = 'serve';
1616
public readonly target = 'serve';
1717
public readonly description = 'Builds and serves your app, rebuilding on file changes.';
1818
public static aliases = ['s'];
19-
public readonly scope = CommandScope.inProject;
19+
public static scope = CommandScope.inProject;
2020
public readonly options: Option[] = [
2121
this.prodOption,
2222
this.configurationOption,

Diff for: packages/angular/cli/commands/test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
1010
import { CommandScope, Option } from '../models/command';
1111

1212

13-
export default class TestCommand extends ArchitectCommand {
13+
export class TestCommand extends ArchitectCommand {
1414
public readonly name = 'test';
1515
public readonly target = 'test';
1616
public readonly description = 'Run unit tests in existing project.';
1717
public static aliases = ['t'];
18-
public readonly scope = CommandScope.inProject;
18+
public static scope = CommandScope.inProject;
1919
public readonly multiTarget = true;
2020
public readonly options: Option[] = [
2121
this.prodOption,

Diff for: packages/angular/cli/commands/update.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export interface UpdateOptions extends CoreSchematicOptions {
1818
}
1919

2020

21-
export default class UpdateCommand extends SchematicCommand {
21+
export class UpdateCommand extends SchematicCommand {
2222
public readonly name = 'update';
2323
public readonly description = 'Updates your application and its dependencies.';
2424
public static aliases: string[] = [];
25-
public readonly scope = CommandScope.everywhere;
25+
public static scope = CommandScope.everywhere;
2626
public arguments: string[] = [ 'packages' ];
2727
public options: Option[] = [
2828
// Remove the --force flag.

Diff for: packages/angular/cli/commands/version.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Command, Option } from '../models/command';
1414
import { findUp } from '../utilities/find-up';
1515

1616

17-
export default class VersionCommand extends Command {
17+
export class VersionCommand extends Command {
1818
public readonly name = 'version';
1919
public readonly description = 'Outputs Angular CLI version.';
2020
public static aliases = ['v'];

Diff for: packages/angular/cli/commands/xi18n.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
1010
import { CommandScope, Option } from '../models/command';
1111

1212

13-
export default class Xi18nCommand extends ArchitectCommand {
13+
export class Xi18nCommand extends ArchitectCommand {
1414
public readonly name = 'xi18n';
1515
public readonly target = 'extract-i18n';
1616
public readonly description = 'Extracts i18n messages from source code.';
17-
public readonly scope = CommandScope.inProject;
17+
public static scope = CommandScope.inProject;
18+
public static aliases = [];
1819
public readonly multiTarget: true;
1920
public readonly options: Option[] = [
2021
this.configurationOption,

Diff for: packages/angular/cli/lib/cli/index.ts

+40-22
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,65 @@
88

99
import { logging, terminal } from '@angular-devkit/core';
1010
import { filter } from 'rxjs/operators';
11-
import { runCommand } from '../../models/command-runner';
11+
import { AddCommand } from '../../commands/add';
12+
import { BuildCommand } from '../../commands/build';
13+
import { ConfigCommand } from '../../commands/config';
14+
import { DocCommand } from '../../commands/doc';
15+
import { E2eCommand } from '../../commands/e2e';
16+
import { AwesomeCommand } from '../../commands/easter-egg';
17+
import { EjectCommand } from '../../commands/eject';
18+
import { GenerateCommand } from '../../commands/generate';
19+
import { GetSetCommand } from '../../commands/getset';
20+
import { HelpCommand } from '../../commands/help';
21+
import { LintCommand } from '../../commands/lint';
22+
import { NewCommand } from '../../commands/new';
23+
import { RunCommand } from '../../commands/run';
24+
import { ServeCommand } from '../../commands/serve';
25+
import { TestCommand } from '../../commands/test';
26+
import { UpdateCommand } from '../../commands/update';
27+
import { VersionCommand } from '../../commands/version';
28+
import { Xi18nCommand } from '../../commands/xi18n';
29+
import { CommandMap, runCommand } from '../../models/command-runner';
1230
import { getProjectDetails } from '../../utilities/project';
1331

1432

15-
function loadCommands() {
33+
async function loadCommands(): Promise<CommandMap> {
1634
return {
1735
// Schematics commands.
18-
'add': require('../../commands/add').default,
19-
'new': require('../../commands/new').default,
20-
'generate': require('../../commands/generate').default,
21-
'update': require('../../commands/update').default,
36+
'add': AddCommand,
37+
'new': NewCommand,
38+
'generate': GenerateCommand,
39+
'update': UpdateCommand,
2240

2341
// Architect commands.
24-
'build': require('../../commands/build').default,
25-
'serve': require('../../commands/serve').default,
26-
'test': require('../../commands/test').default,
27-
'e2e': require('../../commands/e2e').default,
28-
'lint': require('../../commands/lint').default,
29-
'xi18n': require('../../commands/xi18n').default,
30-
'run': require('../../commands/run').default,
42+
'build': BuildCommand,
43+
'serve': ServeCommand,
44+
'test': TestCommand,
45+
'e2e': E2eCommand,
46+
'lint': LintCommand,
47+
'xi18n': Xi18nCommand,
48+
'run': RunCommand,
3149

3250
// Disabled commands.
33-
'eject': require('../../commands/eject').default,
51+
'eject': EjectCommand,
3452

3553
// Easter eggs.
36-
'make-this-awesome': require('../../commands/easter-egg').default,
54+
'make-this-awesome': AwesomeCommand,
3755

3856
// Other.
39-
'config': require('../../commands/config').default,
40-
'help': require('../../commands/help').default,
41-
'version': require('../../commands/version').default,
42-
'doc': require('../../commands/doc').default,
57+
'config': ConfigCommand,
58+
'help': HelpCommand,
59+
'version': VersionCommand,
60+
'doc': DocCommand,
4361

4462
// deprecated
45-
'get': require('../../commands/getset').default,
46-
'set': require('../../commands/getset').default,
63+
'get': GetSetCommand,
64+
'set': GetSetCommand,
4765
};
4866
}
4967

5068
export default async function(options: { testing?: boolean, cliArgs: string[] }) {
51-
const commands = loadCommands();
69+
const commands = await loadCommands();
5270

5371
const logger = new logging.IndentLogger('cling');
5472
let loggingSubscription;

Diff for: packages/angular/cli/models/command-runner.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ export async function runCommand(commandMap: CommandMap,
121121

122122
return;
123123
} else {
124-
if (command.scope !== undefined && command.scope !== CommandScope.everywhere) {
125-
if (command.scope !== executionScope) {
124+
if (Cmd.scope !== undefined && Cmd.scope !== CommandScope.everywhere) {
125+
if (Cmd.scope !== executionScope) {
126126
let errorMessage;
127-
if (command.scope === CommandScope.inProject) {
127+
if (Cmd.scope === CommandScope.inProject) {
128128
errorMessage = `This command can only be run inside of a CLI project.`;
129129
} else {
130130
errorMessage = `This command can not be run inside of a CLI project.`;
@@ -134,7 +134,7 @@ export async function runCommand(commandMap: CommandMap,
134134
return 1;
135135
}
136136

137-
if (command.scope === CommandScope.inProject) {
137+
if (Cmd.scope === CommandScope.inProject) {
138138
if (!context.project.configFile) {
139139
logger.fatal('Invalid project: missing workspace file.');
140140

Diff for: packages/angular/cli/models/command.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import { logging, terminal } from '@angular-devkit/core';
1111

1212
export interface CommandConstructor {
1313
new(context: CommandContext, logger: logging.Logger): Command;
14+
readonly name: string;
1415
aliases: string[];
15-
scope: CommandScope.everywhere;
16+
scope: CommandScope;
1617
}
1718

1819
export enum CommandScope {
@@ -89,7 +90,8 @@ export abstract class Command<T = any> {
8990
public argStrategy = ArgumentStrategy.MapToOptions;
9091
public hidden = false;
9192
public unknown = false;
92-
public scope = CommandScope.everywhere;
93+
public static scope: CommandScope = CommandScope.everywhere;
94+
public static aliases: string[] = [];
9395
protected readonly logger: logging.Logger;
9496
protected readonly project: any;
9597
}

0 commit comments

Comments
 (0)