/
link.command.ts
60 lines (54 loc) · 1.84 KB
/
link.command.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
54
55
56
57
58
59
60
const Listr = require('listr');
import { findSubmodules } from '../utils';
import { npmLink } from '../tasks';
// todo: 'npm-link` doesn't track adding new files,
// so watch mode should be added
export function npmLinkCommand({project, local, deep, verbose, yarn, here}) {
const noDeepLinking = deep === false;
// 1. clean dist folders
// 2.1 merge pkg json
// 2.2 validate pkg (main, module, types)
// 2.3 write pkg
// 3. compile ts
return findSubmodules(project, {local})
.then((opts: TsmOptions[]) => new Listr([
{
title: 'Link all submodules',
task: () => {
const linkingTasks = new Listr(
opts.map(opt => ({
title: `npm link ${opt.pkg.name} (from: ${opt.dist})`,
task: () => npmLink({yarn, cwd: opt.dist})
}))
);
if (noDeepLinking) {
return linkingTasks;
}
opts.filter(opt => opt.cross.length > 0)
.forEach(opt => opt.cross
.forEach(crossName => linkingTasks.add(
{
title: `npm link ${crossName} to ${opt.pkg.name} (${opt.src})`,
task: () => npmLink({yarn, cwd: opt.dist, module: crossName})
}
)));
return linkingTasks;
}
},
{
title: 'Link submodules to local project',
task: () => new Listr(
opts.map(opt => ({
title: `npm link ${opt.pkg.name}`,
task: () => npmLink({yarn, module: opt.pkg.name, cwd: '.'})
}))
),
skip: () => here !== true
}
], {renderer: verbose ? 'verbose' : 'default'}));
}
export function run(cli) {
const {project, verbose, local, deep, yarn, here} = cli.flags;
return npmLinkCommand({project, verbose, local, deep, yarn, here})
.then(tasks => tasks.run());
}