clydin de8336d90a test: update development tslint version (#5936)
Also fixes any encountered errors.

This only changes the version used for the CLI's development.  The project template version of tslint cannot be updated until codelyzer supports the latest version. ([codelyzer tracking issue](https://github.com/mgechev/codelyzer/issues/281))
2017-05-04 20:13:13 +01:00

33 lines
923 B
TypeScript

const SilentError = require('silent-error');
const chalk = require('chalk');
import { oneLine } from 'common-tags';
import { CliConfig } from '../models/config';
export function getAppFromConfig(nameOrIndex?: String) {
const apps: any[] = CliConfig.getValue('apps');
if (!apps) {
throw new SilentError(chalk.red('Unable to find any apps in `.angular-cli.json`.'));
}
if (nameOrIndex) {
if (nameOrIndex.match(/^[0-9]+$/)) {
const index = parseInt(nameOrIndex.toString(), 10);
if (apps[index]) {
return apps[index];
}
} else {
const filtered = apps.filter((currentApp: any) => currentApp.name === nameOrIndex);
if (filtered.length > 0) {
return filtered[0];
}
}
} else {
return apps[0];
}
throw new SilentError(chalk.red(oneLine`
Unable to find app with name or index.
Verify the configuration in \`.angular-cli.json\`
`));
}