Skip to content

Commit

Permalink
feat(console): Add console output when using the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
nicojs committed Jun 7, 2017
1 parent a5b2098 commit 6231b67
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as path from 'path';
import { installLocal } from './index';

export function cli(argv: string[]) {

const args = argv
const directories = argv
.filter((_, i) => i > 1);

if (args.length < 1) {
if (directories.length < 1) {
console.log();
console.log('Install packages locally without changing the package.json');
console.log();
Expand All @@ -22,7 +23,11 @@ export function cli(argv: string[]) {
console.log(' Print this help.');
process.exit(1);
} else {
installLocal({ '.': args }).catch(err => {
installLocal({ '.': directories }).then(packagesBySource => {
Object.keys(packagesBySource).forEach(source => {
console.log(`Installed ${path.basename(source)} into ${packagesBySource[source].map(target => path.basename(target))}`);
});
}).catch(err => {
console.error(err);
process.exit(1);
});
Expand Down
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ export interface ListByPackage {
[key: string]: string[];
}

export function installLocal(packagesByTarget: ListByPackage) {
export function installLocal(packagesByTarget: ListByPackage): Promise<ListByPackage> {
const packagesBySource = mapToPackagesBySource(packagesByTarget);
return Promise.all(Object.keys(packagesBySource)
.map(source => installPackagesInto(source, packagesBySource[source])));
return Promise.all(
Object.keys(packagesBySource)
.map(source => installPackagesInto(source, packagesBySource[source])))
.then(() => packagesBySource);
}

export function mapToPackagesBySource(packagesByTarget: ListByPackage) {
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true
}
},
"exclude": [
"sample",
"node_modules"
]
}

0 comments on commit 6231b67

Please sign in to comment.