Skip to content

Factored out availableOptions / blueprints from commands. #4330

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
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
32 changes: 32 additions & 0 deletions packages/angular-cli/commands/build.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const CommandOptions = [
{
name: 'target',
type: String,
default: 'development',
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
},
{ name: 'environment', type: String, aliases: ['e'] },
{ name: 'output-path', type: 'Path', aliases: ['op'] },
{ name: 'aot', type: Boolean, default: false },
{ name: 'sourcemap', type: Boolean, aliases: ['sm'] },
{ name: 'vendor-chunk', type: Boolean, default: true, aliases: ['vc'] },
{ name: 'base-href', type: String, default: '/', aliases: ['bh'] },
{ name: 'deploy-url', type: String, aliases: ['d'] },
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
{ name: 'progress', type: Boolean, default: true, aliases: ['pr'] },
{ name: 'i18n-file', type: String },
{ name: 'i18n-format', type: String },
{ name: 'locale', type: String },
{ name: 'extract-css', type: Boolean, aliases: ['ec']},
{
name: 'output-hashing',
type: String,
values: ['none', 'all', 'media', 'bundles'],
description: 'define the output filename cache-busting hashing mode',
aliases: ['oh']
}
];

export const availableOptions = CommandOptions.concat([
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] }
]);
34 changes: 3 additions & 31 deletions packages/angular-cli/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
import { BuildOptions } from '../models/webpack-config';
import { availableOptions, CommandOptions } from './build.options';

const Command = require('../ember-cli/lib/models/command');

// defaults for BuildOptions
export const BaseBuildCommandOptions: any = [
{
name: 'target',
type: String,
default: 'development',
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
},
{ name: 'environment', type: String, aliases: ['e'] },
{ name: 'output-path', type: 'Path', aliases: ['op'] },
{ name: 'aot', type: Boolean, default: false },
{ name: 'sourcemap', type: Boolean, aliases: ['sm'] },
{ name: 'vendor-chunk', type: Boolean, default: true, aliases: ['vc'] },
{ name: 'base-href', type: String, default: '/', aliases: ['bh'] },
{ name: 'deploy-url', type: String, aliases: ['d'] },
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
{ name: 'progress', type: Boolean, default: true, aliases: ['pr'] },
{ name: 'i18n-file', type: String },
{ name: 'i18n-format', type: String },
{ name: 'locale', type: String },
{ name: 'extract-css', type: Boolean, aliases: ['ec']},
{
name: 'output-hashing',
type: String,
values: ['none', 'all', 'media', 'bundles'],
description: 'define the output filename cache-busting hashing mode',
aliases: ['oh']
},
];
export const BaseBuildCommandOptions: any = CommandOptions;

export interface BuildTaskOptions extends BuildOptions {
watch?: boolean;
Expand All @@ -41,9 +15,7 @@ const BuildCommand = Command.extend({
description: 'Builds your app and places it into the output path (dist/ by default).',
aliases: ['b'],

availableOptions: BaseBuildCommandOptions.concat([
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] }
]),
availableOptions: availableOptions,

run: function (commandOptions: BuildTaskOptions) {
return require('./build.run').default.call(this, commandOptions);
Expand Down
11 changes: 11 additions & 0 deletions packages/angular-cli/commands/generate.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as fs from 'fs';
import * as path from 'path';

const Blueprint = require('../ember-cli/lib/models/blueprint');

const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));

export const blueprints = blueprintList
.filter(bp => bp.indexOf('-test') === -1)
.filter(bp => bp !== 'ng2')
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));
15 changes: 3 additions & 12 deletions packages/angular-cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';

import { blueprints } from './generate.options';

const chalk = require('chalk');
const EmberGenerateCommand = require('../ember-cli/lib/commands/generate');
const Blueprint = require('../ember-cli/lib/models/blueprint');
const SilentError = require('silent-error');


Expand All @@ -31,17 +32,7 @@ const GenerateCommand = EmberGenerateCommand.extend({

// Override default help to hide ember blueprints
EmberGenerateCommand.prototype.printDetailedHelp = function() {
const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
const blueprints = blueprintList
.filter(bp => bp.indexOf('-test') === -1)
.filter(bp => bp !== 'ng2')
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));

let output = '';
blueprints
.forEach(function (bp) {
output += bp.printBasicHelp(false) + os.EOL;
});
let output = blueprints.map(bp => bp.printBasicHelp(false)).join(os.EOL);
this.ui.writeLine(chalk.cyan(' Available blueprints'));
this.ui.writeLine(output);
};
Expand Down
3 changes: 3 additions & 0 deletions packages/angular-cli/commands/get.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const availableOptions = [
{ name: 'global', type: Boolean, 'default': false }
];
7 changes: 3 additions & 4 deletions packages/angular-cli/commands/get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {CliConfig} from '../models/config';
import { CliConfig } from '../models/config';
import { availableOptions } from './get.options';

const SilentError = require('silent-error');
const Command = require('../ember-cli/lib/models/command');
Expand All @@ -14,9 +15,7 @@ const GetCommand = Command.extend({
description: 'Get a value from the configuration.',
works: 'everywhere',

availableOptions: [
{ name: 'global', type: Boolean, 'default': false }
],
availableOptions: availableOptions,

run: function (commandOptions: GetOptions, rawArgs: string[]): Promise<void> {
return new Promise<void>(resolve => {
Expand Down
56 changes: 56 additions & 0 deletions packages/angular-cli/commands/github-pages-deploy.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
export const availableOptions: any = [
{
name: 'message',
type: String,
default: 'new gh-pages version',
description: 'The commit message to include with the build, must be wrapped in quotes.'
}, {
name: 'target',
type: String,
default: 'production',
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
}, {
name: 'environment',
type: String,
default: '',
aliases: ['e']
}, {
name: 'user-page',
type: Boolean,
default: false,
description: 'Deploy as a user/org page'
}, {
name: 'skip-build',
type: Boolean,
default: false,
description: 'Skip building the project before deploying'
}, {
name: 'gh-token',
type: String,
default: '',
description: 'GitHub token'
}, {
name: 'gh-username',
type: String,
default: '',
description: 'GitHub username'
}, {
name: 'base-href',
type: String,
default: null,
aliases: ['bh']
}, {
name: 'custom-domain',
type: String,
default: null,
aliases: ['cd'],
description: 'Custom domain for Github Pages'
}, {
name: 'aot',
type: Boolean,
default: false,
}, {
name: 'vendor-chunk',
type: Boolean,
default: false,
}];
58 changes: 2 additions & 56 deletions packages/angular-cli/commands/github-pages-deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Command = require('../ember-cli/lib/models/command');
import { oneLine } from 'common-tags';
import { availableOptions } from './github-pages-deploy.options';

export interface GithubPagesDeployOptions {
message?: string;
Expand All @@ -24,62 +25,7 @@ const GithubPagesDeployCommand = Command.extend({
`,
works: 'insideProject',

availableOptions: [
{
name: 'message',
type: String,
default: 'new gh-pages version',
description: 'The commit message to include with the build, must be wrapped in quotes.'
}, {
name: 'target',
type: String,
default: 'production',
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
}, {
name: 'environment',
type: String,
default: '',
aliases: ['e']
}, {
name: 'user-page',
type: Boolean,
default: false,
description: 'Deploy as a user/org page'
}, {
name: 'skip-build',
type: Boolean,
default: false,
description: 'Skip building the project before deploying'
}, {
name: 'gh-token',
type: String,
default: '',
description: 'GitHub token'
}, {
name: 'gh-username',
type: String,
default: '',
description: 'GitHub username'
}, {
name: 'base-href',
type: String,
default: null,
aliases: ['bh']
}, {
name: 'custom-domain',
type: String,
default: null,
aliases: ['cd'],
description: 'Custom domain for Github Pages'
}, {
name: 'aot',
type: Boolean,
default: false,
}, {
name: 'vendor-chunk',
type: Boolean,
default: false,
}],
availableOptions: availableOptions,

run: function(options: GithubPagesDeployOptions, rawArgs: string[]) {
return require('./github-pages-deploy.run').default.call(this, options, rawArgs);
Expand Down
12 changes: 5 additions & 7 deletions packages/angular-cli/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ const HelpCommand = Command.extend({

run: function (commandOptions: any, rawArgs: any) {
let commandFiles = fs.readdirSync(__dirname)
// Remove files that are not JavaScript or Typescript
.filter(file => file.match(/\.(j|t)s$/) && !file.match(/\.d.ts$/) && !file.match(/\.run.ts$/))
// Remove files that are not pure command Typescript
.filter(file => file.match(/\.ts$/) && !file.match(/\.d.ts$/) &&
!file.match(/\.run.ts$/) && !file.match(/\.options.ts$/))
.map(file => path.parse(file).name)
.map(file => file.toLowerCase());

commandFiles = commandFiles.filter(file => {
return commandsToIgnore.indexOf(file) < 0;
});
.map(file => file.toLowerCase())
.filter(file => commandsToIgnore.indexOf(file) < 0);

let commandMap = commandFiles.reduce((acc: any, curr: string) => {
let classifiedName = stringUtils.classify(curr);
Expand Down
16 changes: 16 additions & 0 deletions packages/angular-cli/commands/init.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const availableOptions: any = [
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },
{ name: 'name', type: String, default: '', aliases: ['n'] },
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
{ name: 'style', type: String, default: 'css' },
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
{ name: 'routing', type: Boolean, default: false },
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
];
18 changes: 2 additions & 16 deletions packages/angular-cli/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
const Command = require('../ember-cli/lib/models/command');
import { availableOptions } from './init.options';

const InitCommand: any = Command.extend({
name: 'init',
description: 'Creates a new angular-cli project in the current folder.',
aliases: ['u', 'update', 'i'],
works: 'everywhere',

availableOptions: [
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },
{ name: 'name', type: String, default: '', aliases: ['n'] },
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
{ name: 'style', type: String, default: 'css' },
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
{ name: 'routing', type: Boolean, default: false },
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
],
availableOptions: availableOptions,

anonymousOptions: ['<glob-pattern>'],

Expand Down
16 changes: 16 additions & 0 deletions packages/angular-cli/commands/new.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const availableOptions: any = [
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },
{ name: 'directory', type: String, aliases: ['dir'] },
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
{ name: 'style', type: String, default: 'css' },
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
{ name: 'routing', type: Boolean, default: false },
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
];
20 changes: 3 additions & 17 deletions packages/angular-cli/commands/new.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as chalk from 'chalk';
import InitCommand from './init';
import {oneLine, stripIndent} from 'common-tags';
import { oneLine, stripIndent } from 'common-tags';
import { availableOptions } from './new.options';

const Command = require('../ember-cli/lib/models/command');
const Project = require('../ember-cli/lib/models/project');
Expand Down Expand Up @@ -28,22 +29,7 @@ const NewCommand = Command.extend({
description: `Creates a new directory and runs ${chalk.green('ng init')} in it.`,
works: 'outsideProject',

availableOptions: [
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },
{ name: 'directory', type: String, aliases: ['dir'] },
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
{ name: 'style', type: String, default: 'css' },
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
{ name: 'routing', type: Boolean, default: false },
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
],
availableOptions: availableOptions,

run: function (commandOptions: any, rawArgs: string[]) {
const packageName = rawArgs.shift();
Expand Down
Loading