Skip to content

Commit

Permalink
feat(schematics): improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Jan 3, 2018
1 parent 58c8a3b commit 878784a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 5 additions & 3 deletions packages/schematics/src/command-line/affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ try {
rest = p.rest;
apps = getAffectedApps(p.files);
} catch (e) {
printError(command);
printError(command, e);
process.exit(1);
}

switch (command) {
Expand All @@ -25,11 +26,12 @@ switch (command) {
break;
}

function printError(command: string) {
console.error(`Pass the SHA range, as follows: npm run affected:${command} SHA1 SHA2.`);
function printError(command: string, e: any) {
console.error(`Pass the SHA range, as follows: npm run affected:${command} -- SHA1 SHA2.`);
console.error(
`Or pass the list of files, as follows: npm run affected:${command} --files="libs/mylib/index.ts,libs/mylib2/index.ts".`
);
console.error(e.message);
}

function build(apps: string[], rest: string[]) {
Expand Down
8 changes: 5 additions & 3 deletions packages/schematics/src/command-line/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ try {
}
}
} catch (e) {
printError(command);
printError(command, e);
process.exit(1);
}

switch (command) {
Expand All @@ -44,11 +45,12 @@ function getPatternsFromApps(affectedFiles: string[]): string[] {
}
}

function printError(command: string) {
console.error(`Pass the SHA range, as follows: npm run format:${command} SHA1 SHA2.`);
function printError(command: string, e: any) {
console.error(`Pass the SHA range, as follows: npm run format:${command} -- SHA1 SHA2.`);
console.error(
`Or pass the list of files, as follows: npm run format:${command} --files="libs/mylib/index.ts,libs/mylib2/index.ts".`
);
console.error(e.message);
}

function write(patterns: string[]) {
Expand Down
4 changes: 4 additions & 0 deletions packages/schematics/src/command-line/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export function getAffectedApps(touchedFiles: string[]): string[] {
};
});

if (!config.project.npmScope) {
throw new Error(`.angular-cli.json must define the npmScope property.`);
}

return affectedApps(config.project.npmScope, projects, f => fs.readFileSync(f, 'utf-8'), touchedFiles);
}

Expand Down

0 comments on commit 878784a

Please sign in to comment.