Skip to content

Commit 3b29176

Browse files
committed
feat(core): add list command
1 parent 7b37c5e commit 3b29176

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/bin-list.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
3+
import chalk from 'chalk';
4+
import * as program from 'commander';
5+
import * as _ from 'lodash';
6+
import { DEFAULT_PATTERN, OPTION_PACKAGES } from './constants';
7+
import { getVersions } from './manifests';
8+
9+
program.option(OPTION_PACKAGES.spec, OPTION_PACKAGES.description).parse(process.argv);
10+
11+
const { packages = DEFAULT_PATTERN } = program;
12+
13+
getVersions(packages).then((versionByName) => {
14+
_.each(versionByName, (versions, name) => {
15+
if (versions.length > 1) {
16+
console.log(chalk.yellow(name), chalk.dim(versions.join(', ')));
17+
} else {
18+
console.log(chalk.blue(name), chalk.dim(versions[0]));
19+
}
20+
});
21+
});

src/bin.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env node
2+
3+
import * as program from 'commander';
4+
import { COMMAND_LIST } from './constants';
5+
6+
program.version('TODO').command(COMMAND_LIST.name, COMMAND_LIST.description, {
7+
isDefault: true
8+
});
9+
10+
program.parse(process.argv);

src/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { IManifestKey } from './typings';
22

3+
export const COMMAND_LIST = {
4+
description: 'list every dependency used in your packages',
5+
name: 'list'
6+
};
37
export const DEFAULT_PATTERN = './packages/*/package.json';
48
export const DEPENDENCY_TYPES: IManifestKey[] = ['dependencies', 'devDependencies', 'peerDependencies'];
59
export const GREATER = 1;
610
export const LESSER = -1;
11+
export const OPTION_PACKAGES = {
12+
description: `location of packages, defaults to "${DEFAULT_PATTERN}"`,
13+
spec: '-p, --packages <glob>'
14+
};
715
export const SAME = 0;
816
export const SEMVER_ORDER = ['<', '<=', '', '~', '^', '>=', '>', '*'];

0 commit comments

Comments
 (0)