Skip to content

feat(@schematics/angular): search in specific doc version #11355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 41 additions & 4 deletions packages/angular/cli/commands/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ const opn = require('opn');
export interface Options {
keyword: string;
search?: boolean;
searchDocVersion?: boolean;
version: string;
}

enum DocumentVersions {
v4 = 'v4',
v5 = 'v5',
next = 'next',
}

export default class DocCommand extends Command {
public readonly name = 'doc';
public readonly description = 'Opens the official Angular API documentation for a given keyword.';
public readonly description =
'Opens the official Angular API documentation for a given keyword.';
public static aliases = ['d'];
public readonly arguments = ['keyword'];
public readonly arguments = ['keyword', 'version'];
public readonly options = [
{
name: 'search',
Expand All @@ -27,6 +36,13 @@ export default class DocCommand extends Command {
default: false,
description: 'Search whole angular.io instead of just api.',
},
{
name: 'search-doc-version',
aliases: ['v'],
type: Boolean,
default: false,
description: 'Search in specific doc version: [v4, v5, next].',
},
];

public validate(options: Options) {
Expand All @@ -40,9 +56,30 @@ export default class DocCommand extends Command {
}

public async run(options: Options) {
let searchUrl = `https://angular.io/api?query=${options.keyword}`;
let version = '';
let searchUrl = '';

if (options.searchDocVersion) {
switch (options.version) {
case 'v4':
version = DocumentVersions.v4;
break;
case 'v5':
version = DocumentVersions.v5;
break;
case 'next':
version = DocumentVersions.next;
break;
}
searchUrl = `https://${version}.angular.io/api?query=${options.keyword}`;
} else {
searchUrl = `https://angular.io/api?query=${options.keyword}`;
}

if (options.search) {
searchUrl = `https://www.google.com/search?q=site%3Aangular.io+${options.keyword}`;
searchUrl = `https://www.google.com/search?q=site%3Aangular.io+${
options.keyword
}`;
}

return opn(searchUrl);
Expand Down