-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.ts
269 lines (263 loc) · 9.04 KB
/
main.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import { Command } from "./deps.ts";
import run from "./src/cmd/run.ts";
import init from "./src/cmd/init.ts";
import search from "./src/cmd/search.ts";
import upgrade, { checkForUpdate } from "./src/cmd/upgrade.ts";
import listJobs from "./src/cmd/list.ts";
import docs from "./src/cmd/docs.ts";
import cache from "./src/cmd/cache.ts";
import doctor from "./src/cmd/doctor.ts";
import showEnvs from "./src/cmd/env.ts";
import login from "./src/cmd/login.ts";
import publish from "./src/cmd/publish.ts";
import startAgent, { listAgents } from "./src/cmd/agent.ts";
import whoami from "./src/cmd/whoami.ts";
import { brightGreen } from "./deps.ts";
import { VERSION } from "./src/consts.ts";
import repl from "./src/cmd/repl.ts";
import studio from "./src/cmd/studio.ts";
import * as projects from "./src/cmd/project.ts";
import server from "./src/cmd/server.ts";
import down from "./src/cmd/down.ts";
import up from "./src/cmd/up.ts";
import listServices from "./src/cmd/ps.ts";
import status from "./src/cmd/status.ts";
import restart from "./src/cmd/restart.ts";
import stop from "./src/cmd/stop.ts";
import echo from "./src/cmd/echo.ts";
import community from "./src/cmd/community.ts";
export async function main() {
Deno.env.set(
"PATH",
`${Deno.env.get("HOME")}/.deno/bin:${Deno.env.get("PATH")}`
);
await new Command()
.name("fluentci")
.version(VERSION)
.description(
`
.
______ __ _________
/ __/ /_ _____ ___ / /_/ ___/ _/
/ _// / // / -_) _ \\/ __/ /___/ /
/_/ /_/\\_,_/\\__/_//_/\\__/\\___/___/
FluentCI CLI - An Open Source CI/CD tool written in TypeScript (Deno) based on Wasm Plugins and Dagger
`
)
.arguments("[pipeline:string] [jobs...:string]")
.option("-r, --reload", "Reload pipeline source cache")
.option("-w, --wasm", "Run pipeline as WebAssembly Module")
.option("--remote-exec", "Run pipeline on remote agent")
.option("--work-dir <workDir:string>", "Set working directory")
.option("-*, --* [args:string]", "Pass arguments to pipeline")
.action(function (options, pipeline, ...jobs: [string, ...Array<string>]) {
if (options.wasm) {
Deno.args.findIndex((arg) => arg === pipeline);
const args = Deno.args.slice(
Deno.args.findIndex((arg) => arg === pipeline) + 1
);
run(pipeline || ".", args, options);
return;
}
run(pipeline || ".", jobs, options);
})
.command("run", "Run a pipeline")
.arguments("<pipeline:string> [jobs...:string]")
.option("-r, --reload", "Reload pipeline source cache")
.option("-w, --wasm", "Run pipeline as WebAssembly Module")
.option("--remote-exec", "Run pipeline on remote agent")
.option("--work-dir <workDir:string>", "Set working directory")
.option("-*, --* [args:string]", "Pass arguments to pipeline")
.action(function (options, pipeline, ...jobs: [string, ...Array<string>]) {
if (pipeline.endsWith(".wasm") || pipeline.endsWith("?wasm=1")) {
options.wasm = true;
}
if (options.wasm) {
Deno.args.findIndex((arg) => arg === pipeline);
const args = Deno.args.slice(
Deno.args.findIndex((arg) => arg === pipeline) + 1
);
run(pipeline, args, options);
return;
}
run(pipeline, jobs, options);
})
.command("init", "Initialize a new pipeline")
.arguments("[pipeline-name:string]")
.option("-t, --template <template>", "Initialize pipeline from template")
.option(
"-s, --standalone",
"Initialize pipeline as standalone project, so it can be published and reused in other projects"
)
.option("-w, --wasm", "Initialize pipeline as WebAssembly Module")
.action(async function (options, pipeline) {
await init(options, pipeline);
})
.command("search", "Search for reusable pipelines")
.option(
"-l, --limit <limit:number>",
"Limit the number of results, default: 100",
{ default: 100 }
)
.arguments("<query:string>")
.action(async function (options, query) {
await search(query, options);
})
.command("upgrade", "Upgrade FluentCI CLI to the latest version")
.action(async () => {
await upgrade();
})
.command(
"cache [pipeline:string]",
"Cache remote dependencies of a pipeline"
)
.option("--lock-write", "Update lock file")
.action(async function ({ lockWrite }, pipeline) {
await cache(pipeline, lockWrite);
})
.command("ls, list", "List all jobs in a pipeline")
.arguments("[pipeline:string]")
.action(async (_, pipeline) => {
await listJobs(pipeline);
})
.command("docs, man", "Show documentation for a pipeline")
.arguments("[pipeline:string]")
.action(async function (_, pipeline) {
await docs(pipeline);
})
.command("doctor", "Check if FluentCI CLI is installed correctly")
.action(async function () {
await doctor();
})
.command(
"env",
`Show environment variables (read from ${brightGreen(
".fluentci/.env"
)} file)`
)
.action(async function () {
await showEnvs();
})
.command("login", "Login to FluentCI")
.action(async function () {
await login();
})
.command("publish", "Publish a pipeline to FluentCI Registry")
.option("-w, --wasm", "Publish pipeline as WebAssembly Module")
.action(async function (options) {
await publish(options);
})
.command(
"agent",
new Command()
.command("list", "List all agents")
.alias("ls")
.action(async function () {
await listAgents();
})
)
.description("Start FluentCI Runner Agent")
.action(async function () {
await startAgent();
})
.command("whoami", "Show current logged in user")
.action(async function () {
await whoami();
})
.command("repl", "Start FluentCI REPL")
.arguments("[pipelines...:string]")
.option("--debug", "Show more information for debugging")
.action(async function (options, ...pipelines: [string, ...Array<string>]) {
await repl(options, pipelines);
})
.command("studio", "Start FluentCI Studio, a web-based user interface")
.option("--port <port:number>", "Port to run FluentCI Studio")
.action(async function (options) {
await studio(options);
})
.command(
"project",
new Command()
.command("create", "Create a new project")
.action(async function () {
await projects.create();
})
.command("list", "List all projects")
.action(async function () {
await projects.list();
})
.command("show", "Show a project")
.arguments("<name:string>")
.action(async function (_, name) {
await projects.show(name);
})
.command("export", "Export a project to a specific CI Provider")
.arguments("[name:string]")
.option("--github", "Export to GitHub Actions")
.option("--azure", "Export to Azure Pipelines")
.option("--gitlab", "Export to GitLab CI")
.option("--circleci", "Export to CircleCI")
.option("--aws", "Export to AWS CodePipeline")
.action(async function (options, project) {
await projects.exportActions(options, project);
})
)
.description("Manage projects")
.command("server", "Start FluentCI GraphQL Server")
.option("--port <port:number>", "Port to run FluentCI Server")
.action(function (options) {
server(options);
})
.command("up", "Start services")
.action(async function () {
await up();
})
.command("down", "Stop services")
.action(async function () {
await down();
})
.command("ps", "List services")
.action(async function () {
await listServices();
})
.command("status", "Show status of a service")
.arguments("<service:string>")
.action(async function (_, service) {
await status(service);
})
.command("start", "Start a service")
.arguments("<service:string>")
.action(async function (_, service) {
await restart(service);
})
.command("restart", "Restart a service")
.arguments("<service:string>")
.action(async function (_, service) {
await restart(service);
})
.command("stop", "Stop a service")
.arguments("<service:string>")
.action(async function (_, service) {
await stop(service);
})
.command("echo", "Stream logs of a service")
.arguments("<service:string>")
.action(async function (_, service) {
await echo(service);
})
.command("community", "Join our community Discord to chat with us")
.action(async function () {
await community();
})
.globalOption("--check-update <checkUpdate:boolean>", "check for update", {
default: true,
})
.globalAction(async (options: { checkUpdate: boolean }) => {
await checkForUpdate(options);
})
.parse(Deno.args);
}
// Learn more at https://deno.land/manual/examples/module_metadata#concepts
if (import.meta.main) {
main();
}