Skip to content
Merged
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
6 changes: 4 additions & 2 deletions packages/@angular/cli/models/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {

static fromProject(projectPath?: string): CliConfig {
const configPath = this.configFilePath(projectPath);
if (!configPath || configPath === this.globalConfigFilePath()) {
return null;

if (!configPath ||
(configPath === this.globalConfigFilePath() && process.cwd() !== path.dirname(configPath))) {
return null;
}
if (configCacheMap.has(configPath)) {
return configCacheMap.get(configPath);
Expand Down
10 changes: 7 additions & 3 deletions packages/@angular/cli/models/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ export class CliConfig<JsonType> {
? ts.sys.readFile(configPath)
: '{}';
const schemaContent = fs.readFileSync(DEFAULT_CONFIG_SCHEMA_PATH, 'utf-8');
const otherContents = otherPath
.map(path => fs.existsSync(path) && ts.sys.readFile(path))
.filter(content => !!content);

let otherContents = new Array<string>();
if (configPath !== otherPath[0]) {
otherContents = otherPath
.map(path => fs.existsSync(path) && ts.sys.readFile(path))
.filter(content => !!content);
}

let content: T;
let schema: Object;
Expand Down
7 changes: 7 additions & 0 deletions packages/@angular/cli/utilities/app-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const SilentError = require('silent-error');
const chalk = require('chalk');

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`.'));
}

let app = apps[0];
if (nameOrIndex) {
if (nameOrIndex.match(/^[0-9]+$/)) {
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/tests/generate/generate-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {ng} from '../../utils/process';
import {deleteFile} from '../../utils/fs';
import {expectToFail} from '../../utils/utils';

export default function() {
return deleteFile('.angular-cli.json')
.then(() => expectToFail(() => ng('generate', 'class', 'hello')));
}