Skip to content

Commit

Permalink
refactor: Move task logic into commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Brocco committed Mar 12, 2018
1 parent f15c797 commit b1ed4f7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 57 deletions.
24 changes: 15 additions & 9 deletions packages/@angular/cli/commands/doc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { DocTask } from '../tasks/doc';
import { Command } from '../models/command';
import opn from 'opn';

export interface DocOptions {
export interface Options {
keyword: string;
search?: boolean;
}

Expand All @@ -20,14 +21,19 @@ export default class DocCommand extends Command {
}
];

public async run(options: any) {
const keyword = options.keyword;
public validate(options: Options) {
if (!options.keyword) {
this.logger.error(`keyword argument is required.`);
return false;
}
}

const docTask = new DocTask({
ui: this.ui,
project: this.project
});
public async run(options: Options) {
let searchUrl = `https://angular.io/api?query=${options.keyword}`;
if (options.search) {
searchUrl = `https://www.google.com/search?q=site%3Aangular.io+${options.keyword}`;
}

return await docTask.run(keyword, options.search);
return opn(searchUrl, { wait: false });
}
}
19 changes: 15 additions & 4 deletions packages/@angular/cli/commands/update.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command, CommandScope } from '../models/command';
import { UpdateTask } from '../tasks/update';
import SchematicRunTask from '../tasks/schematic-run';

export interface UpdateOptions {
schematic?: boolean;
Expand Down Expand Up @@ -29,13 +29,24 @@ export default class UpdateCommand extends Command {
];

public async run(options: any) {
const schematic = '@schematics/package-update:all';
const collectionName = '@schematics/package-update';
const schematicName = 'all';

const updateTask = new UpdateTask({
const schematicRunTask = new SchematicRunTask({
ui: this.ui,
project: this.project
});

return await updateTask.run(schematic, options);
const schematicRunOptions = {
taskOptions: {
dryRun: options.dryRun,
version: options.next ? 'next' : undefined
},
workingDir: this.project.root,
collectionName,
schematicName
};

return schematicRunTask.run(schematicRunOptions);
}
}
12 changes: 11 additions & 1 deletion packages/@angular/cli/custom-typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ interface IWebpackDevServerConfigurationOptions {
disableHostCheck?: boolean;
}

declare module 'yargs-parser';
declare module 'yargs-parser' {
const parseOptions: any;
const yargsParser: <T = any>(args: string | string[], options?: parseOptions) => T;
export = yargsParser;
}



declare module 'opn' {
export default function(url: string, options?: any): Promise<any>;
}
2 changes: 1 addition & 1 deletion packages/@angular/cli/models/command-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { oneLine } from 'common-tags';
import { logging } from '@angular-devkit/core';
import { camelize } from '@angular-devkit/core/src/utils/strings';

const yargsParser = require('yargs-parser');
import * as yargsParser from 'yargs-parser';

export interface CommandMap {
[key: string]: CommandConstructor;
Expand Down
11 changes: 0 additions & 11 deletions packages/@angular/cli/tasks/doc.ts

This file was deleted.

31 changes: 0 additions & 31 deletions packages/@angular/cli/tasks/update.ts

This file was deleted.

0 comments on commit b1ed4f7

Please sign in to comment.