-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverters.ts
62 lines (60 loc) · 1.68 KB
/
converters.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
61
62
const convertCommandToNpm = (commands: string[]): string => {
const com = commands[0];
const op = commands.slice(1);
// nyarm
// nyarm install
if (!com || (op.length === 0 && (com === 'install' || com === 'i' || com === 'add'))) {
return 'install';
}
// nyarm install {foo}
// nyarm add {foo}
if (com === 'install' || com === 'i' || com === 'add') {
return `install ${op.join(' ')}`;
}
// nyarm uninstall {foo}
// nyarm remove {foo}
if (com === 'uninstall' || com === 'remove') {
return `uninstall ${op.join(' ')}`;
}
// nyarm run {foo}
if (com === 'run') {
return `run ${op.join(' ')}`;
}
// TODO read scripts in package.json and if there is {com} script, run it.
// nyarm {...commands}
return commands.join(' ');
};
const convertCommandToYarn = (commands: string[]): string => {
const com = commands[0];
const op = commands.slice(1);
// nyarm
// nyarm install
if (op.length === 0 && (!com || com === 'install' || com === 'i' || com === 'add')) {
return 'install';
}
// nyarm install {foo}
// nyarm add {foo}
if (com === 'install' || com === 'i' || com === 'add') {
if (op.includes('-S')) {
const index = op.indexOf('-S');
op.splice(index, 1);
}
if (op.includes('--save')) {
const index = op.indexOf('--save');
op.splice(index, 1);
}
return `add ${op.join(' ')}`;
}
// nyarm uninstall {foo}
// nyarm remove {foo}
if (com === 'uninstall' || com === 'remove') {
return `remove ${op.join(' ')}`;
}
// nyarm run {foo}
if (com === 'run') {
return `${op.join(' ')}`;
}
// nyarm {...commands}
return commands.join(' ');
};
export { convertCommandToNpm, convertCommandToYarn };