-
Notifications
You must be signed in to change notification settings - Fork 1
/
dep.ts
53 lines (46 loc) · 1.31 KB
/
dep.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// import {flags} from '@oclif/command'
import { BaseCommand } from '../../utls/base-command';
import { BaseAddCommand } from '../../utls/base-add-command';
import { flags } from '@oclif/command';
export default class Dep extends BaseAddCommand {
static description = 'proxy to yarn add, plus gitmoji commit';
static examples = [
`$ nbx add:dep -D eslint`,
`$ nbx add:dep --dev eslint`,
`$ nbx add:dep chalk`,
];
static flags = {
...BaseCommand.flags,
dev: flags.boolean({
default: false,
char: 'D',
description: 'install as a dev dependency',
}),
};
static args = [
{ name: 'dep', description: 'The dependency to install', required: true },
];
async run() {
if (!this.hasDirPackageJson()) {
this.error('There is no package.json not found in the current folder');
}
const {
args: { dep },
flags: { dev },
} = this.parse(Dep);
if (
(dev && this.hasDevDependencyInPackageJson(dep)) ||
this.hasDependencyInPackageJson(dep)
) {
if (this.hasDevDependencyInPackageJson(dep)) {
this.error(`${dep} is already installed in this project.`);
}
}
await this.initGit();
if (dev) {
await this.addDevDependency(dep, true);
} else {
await this.addDependency(dep, true);
}
}
}