-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathyalc.ts
199 lines (197 loc) · 5.04 KB
/
yalc.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const generatePackages: Fig.Generator = {
// TODO: use the same as for npm and yarn package.json reverse lookup
script: [
"bash",
"-c",
"command find ~/.yalc/packages -maxdepth 4 -iname 'package.json'",
],
postProcess: (out) =>
out
.split("\n")
.map((path) => {
const pathArr = path.split("/");
const subPath = pathArr.slice(
pathArr.findIndex((val) => val === "packages") + 1,
pathArr.length - 2
);
const version = pathArr[pathArr.length - 2];
return `${subPath.join("/")}@${version}`;
})
.map((path) => ({
name: path,
icon: "📦",
description: path,
})),
};
const getRemovablePackages: Fig.Generator = {
script: ["ls", ".yalc"],
postProcess: (out) =>
out.split("\n").map((path) => ({
name: path,
icon: "📦",
description: path,
})),
};
const completionSpec: Fig.Spec = {
name: "yalc",
description: "Work with yarn/npm packages locally like a boss",
subcommands: [
{
name: "publish",
description:
"Copy all the files that should be published in remote NPM registry",
options: [
{
name: "--push",
description:
"Publish package to the store and propagate all changes to existing yalc package installations",
},
{
name: "--no-scripts",
description: "Publish without running scripts",
},
{
name: "--no-sig",
description:
"Disable adding hash signature of all files when copying package content",
},
{
name: "--content",
description: "Show included files in the published package",
},
{
name: "--no-workspace-resolve",
description: "Do not resolve 'workspace:' protocol in dependencies",
},
{
name: "--private",
description: "Force publishing of private package",
},
],
},
{
name: "push",
description:
"Publish your package to the store and propagate all changes to existing yalc package installations",
},
{
name: "add",
description: "Copy the current version from the store to your project",
args: {
name: "package",
description: "The package you want to add",
generators: generatePackages,
},
options: [
{
name: "--link",
description: "Add a 'link:' dependency instead of 'file:'",
},
{
name: "--dev",
description: "Add yalc package to dev dependencies",
},
{
name: "--pure",
description: "Do not touch 'package.json' or 'node_modules'",
},
{
name: ["--workspace", "-W"],
description: "Add dependency with 'workspace:' protocol",
},
],
},
{
name: "link",
description:
"Alterative to 'add', instead using local '.yalc' as symlink source",
},
{
name: "update",
description: "Update package(s)",
args: {
name: "package",
description: "The package to update",
isOptional: true,
generators: generatePackages,
},
options: [
{
name: ["--update", "--upgrade", "--up"],
description: "Run package manager's update command for packages",
},
],
},
{
name: "remove",
description: "Remove package info from 'package.json' & 'yalc.lock'",
args: {
name: "package",
description: "The package you want to remove",
isOptional: true,
generators: getRemovablePackages,
},
options: [
{
name: "--all",
description: "Remove all packages from project",
},
],
},
{
name: "installations",
requiresSubcommand: true,
subcommands: [
{
name: "clean",
description: "Unpublish a package published with yalc publish",
args: {
name: "package",
generators: generatePackages,
},
},
{
name: "show",
description:
"Show all packages to which chosen package has been added",
args: {
name: "package",
generators: generatePackages,
},
},
],
},
{
name: "dir",
description: "Show yalc system directory",
},
{
name: "check",
description: "Check 'package.json' for yalc packages",
},
{
name: "restore",
description: "Restore retreated packages",
},
{
name: "retreat",
description:
"Remove packages from project, but leave in lock file (to be restored later)",
},
],
options: [
{
name: "--help",
description: "Show help for yalc",
},
{
name: "--no-colors",
description: "Disable colors",
},
{
name: "--quiet",
description: "Fully disable output (except errors)",
},
],
};
export default completionSpec;