refactor: fix types to remove any

require() returns any so we were missing some typing errors.
This commit is contained in:
Hans 2018-07-10 15:30:11 -07:00
parent 483cbe2665
commit a0978b1db3
21 changed files with 81 additions and 57 deletions

View File

@ -16,11 +16,12 @@ import { NpmInstall } from '../tasks/npm-install';
import { getPackageManager } from '../utilities/config';
export default class AddCommand extends SchematicCommand {
export class AddCommand extends SchematicCommand {
readonly name = 'add';
readonly description = 'Add support for a library to your project.';
readonly allowPrivateSchematics = true;
scope = CommandScope.inProject;
static aliases = [];
static scope = CommandScope.inProject;
arguments = ['collection'];
options: Option[] = [];

View File

@ -10,13 +10,13 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
import { CommandScope, Option } from '../models/command';
import { Version } from '../upgrade/version';
export default class BuildCommand extends ArchitectCommand {
export class BuildCommand extends ArchitectCommand {
public readonly name = 'build';
public readonly target = 'build';
public readonly description =
'Builds your app and places it into the output path (dist/ by default).';
public static aliases = ['b'];
public scope = CommandScope.inProject;
public static scope = CommandScope.inProject;
public options: Option[] = [
this.prodOption,
this.configurationOption,

View File

@ -178,7 +178,7 @@ function normalizeValue(value: string, path: string): JsonValue {
return value;
}
export default class ConfigCommand extends Command {
export class ConfigCommand extends Command {
public readonly name = 'config';
public readonly description = 'Get/set configuration values.';
public readonly arguments = ['jsonPath', 'value'];

View File

@ -14,7 +14,7 @@ export interface Options {
search?: boolean;
}
export default class DocCommand extends Command {
export class DocCommand extends Command {
public readonly name = 'doc';
public readonly description = 'Opens the official Angular API documentation for a given keyword.';
public static aliases = ['d'];

View File

@ -10,12 +10,12 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
import { CommandScope, Option } from '../models/command';
export default class E2eCommand extends ArchitectCommand {
export class E2eCommand extends ArchitectCommand {
public readonly name = 'e2e';
public readonly target = 'e2e';
public readonly description = 'Run e2e tests in existing project.';
public static aliases: string[] = ['e'];
public readonly scope = CommandScope.inProject;
public static scope = CommandScope.inProject;
public readonly multiTarget = true;
public readonly options: Option[] = [
this.prodOption,

View File

@ -13,7 +13,7 @@ function pickOne(of: string[]): string {
return of[Math.floor(Math.random() * of.length)];
}
export default class AwesomeCommand extends Command {
export class AwesomeCommand extends Command {
public readonly name = 'make-this-awesome';
public readonly description = '';
public readonly hidden = true;

View File

@ -10,12 +10,13 @@ import { tags } from '@angular-devkit/core';
import { Command, Option } from '../models/command';
export default class EjectCommand extends Command {
export class EjectCommand extends Command {
public readonly name = 'eject';
public readonly description = 'Temporarily disabled. Ejects your app and output the proper '
+ 'webpack configuration and scripts.';
public readonly arguments: string[] = [];
public readonly options: Option[] = [];
public static aliases = [];
run() {
this.logger.info(tags.stripIndents`

View File

@ -17,11 +17,11 @@ import {
} from '../utilities/schematics';
export default class GenerateCommand extends SchematicCommand {
export class GenerateCommand extends SchematicCommand {
public readonly name = 'generate';
public readonly description = 'Generates and/or modifies files based on a schematic.';
public static aliases = ['g'];
public readonly scope = CommandScope.inProject;
public static scope = CommandScope.inProject;
public arguments = ['schematic'];
public options: Option[] = [
...this.coreOptions,

View File

@ -13,7 +13,7 @@ export interface Options {
search?: boolean;
}
export default class GetSetCommand extends Command {
export class GetSetCommand extends Command {
public readonly name = 'getset';
public readonly description = 'Deprecated in favor of config command.';
public readonly arguments: string[] = [];

View File

@ -11,7 +11,7 @@ import { terminal } from '@angular-devkit/core';
import { Command, Option } from '../models/command';
export default class HelpCommand extends Command {
export class HelpCommand extends Command {
public readonly name = 'help';
public readonly description = 'Help.';
public readonly arguments: string[] = [];

View File

@ -10,12 +10,12 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
import { CommandScope, Option } from '../models/command';
export default class LintCommand extends ArchitectCommand {
export class LintCommand extends ArchitectCommand {
public readonly name = 'lint';
public readonly target = 'lint';
public readonly description = 'Lints code in existing project.';
public static aliases = ['l'];
public readonly scope = CommandScope.inProject;
public static scope = CommandScope.inProject;
public readonly multiTarget = true;
public readonly options: Option[] = [
this.configurationOption,

View File

@ -12,12 +12,12 @@ import { SchematicCommand } from '../models/schematic-command';
import { getDefaultSchematicCollection } from '../utilities/config';
export default class NewCommand extends SchematicCommand {
export class NewCommand extends SchematicCommand {
public readonly name = 'new';
public readonly description =
'Creates a new directory and a new Angular app.';
public static aliases = ['n'];
public scope = CommandScope.outsideProject;
public static scope = CommandScope.outsideProject;
public readonly allowMissingWorkspace = true;
public arguments: string[] = [];
public options: Option[] = [

View File

@ -10,10 +10,11 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
import { CommandScope, Option } from '../models/command';
export default class RunCommand extends ArchitectCommand {
export class RunCommand extends ArchitectCommand {
public readonly name = 'run';
public readonly description = 'Runs Architect targets.';
public readonly scope = CommandScope.inProject;
public static scope = CommandScope.inProject;
public static aliases = [];
public readonly arguments: string[] = ['target'];
public readonly options: Option[] = [
this.configurationOption,

View File

@ -11,12 +11,12 @@ import { CommandScope, Option } from '../models/command';
import { Version } from '../upgrade/version';
export default class ServeCommand extends ArchitectCommand {
export class ServeCommand extends ArchitectCommand {
public readonly name = 'serve';
public readonly target = 'serve';
public readonly description = 'Builds and serves your app, rebuilding on file changes.';
public static aliases = ['s'];
public readonly scope = CommandScope.inProject;
public static scope = CommandScope.inProject;
public readonly options: Option[] = [
this.prodOption,
this.configurationOption,

View File

@ -10,12 +10,12 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
import { CommandScope, Option } from '../models/command';
export default class TestCommand extends ArchitectCommand {
export class TestCommand extends ArchitectCommand {
public readonly name = 'test';
public readonly target = 'test';
public readonly description = 'Run unit tests in existing project.';
public static aliases = ['t'];
public readonly scope = CommandScope.inProject;
public static scope = CommandScope.inProject;
public readonly multiTarget = true;
public readonly options: Option[] = [
this.prodOption,

View File

@ -18,11 +18,11 @@ export interface UpdateOptions extends CoreSchematicOptions {
}
export default class UpdateCommand extends SchematicCommand {
export class UpdateCommand extends SchematicCommand {
public readonly name = 'update';
public readonly description = 'Updates your application and its dependencies.';
public static aliases: string[] = [];
public readonly scope = CommandScope.everywhere;
public static scope = CommandScope.everywhere;
public arguments: string[] = [ 'packages' ];
public options: Option[] = [
// Remove the --force flag.

View File

@ -14,7 +14,7 @@ import { Command, Option } from '../models/command';
import { findUp } from '../utilities/find-up';
export default class VersionCommand extends Command {
export class VersionCommand extends Command {
public readonly name = 'version';
public readonly description = 'Outputs Angular CLI version.';
public static aliases = ['v'];

View File

@ -10,11 +10,12 @@ import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-c
import { CommandScope, Option } from '../models/command';
export default class Xi18nCommand extends ArchitectCommand {
export class Xi18nCommand extends ArchitectCommand {
public readonly name = 'xi18n';
public readonly target = 'extract-i18n';
public readonly description = 'Extracts i18n messages from source code.';
public readonly scope = CommandScope.inProject;
public static scope = CommandScope.inProject;
public static aliases = [];
public readonly multiTarget: true;
public readonly options: Option[] = [
this.configurationOption,

View File

@ -8,47 +8,65 @@
import { logging, terminal } from '@angular-devkit/core';
import { filter } from 'rxjs/operators';
import { runCommand } from '../../models/command-runner';
import { AddCommand } from '../../commands/add';
import { BuildCommand } from '../../commands/build';
import { ConfigCommand } from '../../commands/config';
import { DocCommand } from '../../commands/doc';
import { E2eCommand } from '../../commands/e2e';
import { AwesomeCommand } from '../../commands/easter-egg';
import { EjectCommand } from '../../commands/eject';
import { GenerateCommand } from '../../commands/generate';
import { GetSetCommand } from '../../commands/getset';
import { HelpCommand } from '../../commands/help';
import { LintCommand } from '../../commands/lint';
import { NewCommand } from '../../commands/new';
import { RunCommand } from '../../commands/run';
import { ServeCommand } from '../../commands/serve';
import { TestCommand } from '../../commands/test';
import { UpdateCommand } from '../../commands/update';
import { VersionCommand } from '../../commands/version';
import { Xi18nCommand } from '../../commands/xi18n';
import { CommandMap, runCommand } from '../../models/command-runner';
import { getProjectDetails } from '../../utilities/project';
function loadCommands() {
async function loadCommands(): Promise<CommandMap> {
return {
// Schematics commands.
'add': require('../../commands/add').default,
'new': require('../../commands/new').default,
'generate': require('../../commands/generate').default,
'update': require('../../commands/update').default,
'add': AddCommand,
'new': NewCommand,
'generate': GenerateCommand,
'update': UpdateCommand,
// Architect commands.
'build': require('../../commands/build').default,
'serve': require('../../commands/serve').default,
'test': require('../../commands/test').default,
'e2e': require('../../commands/e2e').default,
'lint': require('../../commands/lint').default,
'xi18n': require('../../commands/xi18n').default,
'run': require('../../commands/run').default,
'build': BuildCommand,
'serve': ServeCommand,
'test': TestCommand,
'e2e': E2eCommand,
'lint': LintCommand,
'xi18n': Xi18nCommand,
'run': RunCommand,
// Disabled commands.
'eject': require('../../commands/eject').default,
'eject': EjectCommand,
// Easter eggs.
'make-this-awesome': require('../../commands/easter-egg').default,
'make-this-awesome': AwesomeCommand,
// Other.
'config': require('../../commands/config').default,
'help': require('../../commands/help').default,
'version': require('../../commands/version').default,
'doc': require('../../commands/doc').default,
'config': ConfigCommand,
'help': HelpCommand,
'version': VersionCommand,
'doc': DocCommand,
// deprecated
'get': require('../../commands/getset').default,
'set': require('../../commands/getset').default,
'get': GetSetCommand,
'set': GetSetCommand,
};
}
export default async function(options: { testing?: boolean, cliArgs: string[] }) {
const commands = loadCommands();
const commands = await loadCommands();
const logger = new logging.IndentLogger('cling');
let loggingSubscription;

View File

@ -121,10 +121,10 @@ export async function runCommand(commandMap: CommandMap,
return;
} else {
if (command.scope !== undefined && command.scope !== CommandScope.everywhere) {
if (command.scope !== executionScope) {
if (Cmd.scope !== undefined && Cmd.scope !== CommandScope.everywhere) {
if (Cmd.scope !== executionScope) {
let errorMessage;
if (command.scope === CommandScope.inProject) {
if (Cmd.scope === CommandScope.inProject) {
errorMessage = `This command can only be run inside of a CLI project.`;
} else {
errorMessage = `This command can not be run inside of a CLI project.`;
@ -134,7 +134,7 @@ export async function runCommand(commandMap: CommandMap,
return 1;
}
if (command.scope === CommandScope.inProject) {
if (Cmd.scope === CommandScope.inProject) {
if (!context.project.configFile) {
logger.fatal('Invalid project: missing workspace file.');

View File

@ -11,8 +11,9 @@ import { logging, terminal } from '@angular-devkit/core';
export interface CommandConstructor {
new(context: CommandContext, logger: logging.Logger): Command;
readonly name: string;
aliases: string[];
scope: CommandScope.everywhere;
scope: CommandScope;
}
export enum CommandScope {
@ -89,7 +90,8 @@ export abstract class Command<T = any> {
public argStrategy = ArgumentStrategy.MapToOptions;
public hidden = false;
public unknown = false;
public scope = CommandScope.everywhere;
public static scope: CommandScope = CommandScope.everywhere;
public static aliases: string[] = [];
protected readonly logger: logging.Logger;
protected readonly project: any;
}