-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
404 lines (364 loc) · 11.3 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
// deno-lint-ignore-file no-explicit-any
import { Command } from "commander"
import * as builder from "~/builder.ts"
// import { version } from "./package.json" with { "type": "json" };
import * as target from "~/target.ts"
import Docker from "~/util/docker.ts"
import logger from "~/util/log.ts"
import Tart from "~/util/tart.ts"
import divvunspellLinux from "./pipelines/divvunspell/linux.ts"
import divvunspellMacos from "./pipelines/divvunspell/macos.ts"
import divvunspellWindows from "./pipelines/divvunspell/windows.ts"
function prettyPlatform() {
switch (Deno.build.os) {
case "darwin":
return "macos"
case "windows":
return "windows"
case "linux":
return "linux"
default:
return `unsupported: ${Deno.build.os}`
}
}
logger.info(
`Loading Divvun Actions [Mode: ${builder.mode}] [Env: ${target.env}] [Platform: ${prettyPlatform()}]`,
)
const program = new Command()
program
.name("divvun-actions")
.description("CLI for Divvun Actions")
.option("--log-level <level>", "Log level", "info")
.action((options: any) => {
logger.setLogLevel(options.logLevel)
})
// .version(version)
// program
// .command("build")
// .description("Build the project")
// .option("-p, --platform <platform>", "target platform")
// .action((options) => {
// logger.info("Building for platform:", options.platform)
// // Add your build logic here
// })
// program
// .command("setup")
// .description("Setup the environment")
// .requiredOption("--divvun-key <key>", "Divvun key for authentication")
// .action(async (options) => {
// await setup({ divvunKey: options.divvunKey })
// })
// program
// .command("version")
// .description("Version management")
// .option("--is-xcode", "Is Xcode project")
// .option("--is-nightly", "Is nightly build")
// .option("--cargo-toml <path>", "Path to Cargo.toml")
// .option("--speller-manifest <path>", "Path to speller manifest")
// .option("--plist-path <path>", "Path to plist file")
// .option("--csharp <path>", "Path to C# project")
// .option("--version-from-file <path>", "Get version from file")
// .option("--insta-stable", "Mark as stable")
// .option("--nightly-channel <channel>", "Nightly channel")
// .action(async (options) => {
// await versionCmd(options)
// })
// program
// .command("speller-bundle")
// .description("Bundle speller")
// .requiredOption("--version <version>", "Version")
// .requiredOption("--speller-type <type>", "Speller type")
// .requiredOption("--manifest <path>", "Manifest path")
// .requiredOption("--speller-paths <paths...>", "Speller paths")
// .action(async (options) => {
// await spellerBundle(options)
// })
// program
// .command("speller-deploy")
// .description("Deploy speller")
// .requiredOption("--speller-type <type>", "Speller type")
// .requiredOption("--manifest-path <path>", "Manifest path")
// .requiredOption("--payload-path <path>", "Payload path")
// .requiredOption("--version <version>", "Version")
// .requiredOption("--channel <channel>", "Channel")
// .option("--nightly-channel <channel>", "Nightly channel")
// .requiredOption("--pahkat-repo <repo>", "Pahkat repository")
// .action(async (options) => {
// await spellerDeploy(options)
// })
// program
// .command("keyboard-build")
// .description("Build keyboard")
// .requiredOption("--keyboard-type <type>", "Keyboard type")
// .option("--nightly-channel <channel>", "Nightly channel")
// .requiredOption("--bundle-path <path>", "Bundle path")
// .action(async (options) => {
// await keyboardBuild(options)
// })
// program
// .command("keyboard-deploy")
// .description("Deploy keyboard")
// .requiredOption("--payload-path <path>", "Payload path")
// .requiredOption("--keyboard-type <type>", "Keyboard type")
// .requiredOption("--bundle-path <path>", "Bundle path")
// .requiredOption("--channel <channel>", "Channel")
// .requiredOption("--pahkat-repo <repo>", "Pahkat repository")
// .requiredOption("--package-id <id>", "Package ID")
// .action(async (options) => {
// await keyboardDeploy(options)
// })
// program
// .command("keyboard-build-meta")
// .description("Build keyboard metadata")
// .requiredOption("--keyboard-type <type>", "Keyboard type")
// .requiredOption("--bundle-path <path>", "Bundle path")
// .action(async (options) => {
// await keyboardBuildMeta(options)
// })
// program
// .command("deploy")
// .description("Deploy package")
// .requiredOption("--package-id <id>", "Package ID")
// .requiredOption("--platform <platform>", "Platform")
// .requiredOption("--payload-path <path>", "Payload path")
// .option("--arch <arch>", "Architecture")
// .requiredOption("--channel <channel>", "Channel")
// .option("--dependencies <deps...>", "Dependencies")
// .requiredOption("--pahkat-repo <repo>", "Pahkat repository")
// .requiredOption("--version <version>", "Version")
// .action(async (options) => {
// await deploy(options)
// })
// program
// .command("inno-setup")
// .description("Create Inno Setup installer")
// .action(async (options) => {
// await innoSetup(options)
// })
// program
// .command("lang-install-deps")
// .description("Install language dependencies")
// .option("--requires-apertium", "Requires Apertium")
// .option("--requires-sudo", "Requires sudo")
// .action(async (options) => {
// await langInstallDeps(options)
// })
// program
// .command("enable-languages")
// .description("Enable languages")
// .requiredOption("--tags <tags...>", "Language tags")
// .action(async (options) => {
// await enableLanguages(options)
// })
// program
// .command("pahkat-init")
// .description("Initialize Pahkat")
// .requiredOption("--repo-url <url>", "Repository URL")
// .requiredOption("--channel <channel>", "Channel")
// .requiredOption("--packages <packages...>", "Packages")
// .action(async (options) => {
// await pahkatInit(options)
// })
const divvunspell = program
.command("divvunspell")
.description("Run divvunspell pipeline tasks")
.requiredOption("--platform <platform>", "Target platform (macos, linux)")
divvunspell
.command("build")
.description("Build divvunspell")
.option("--divvun-key <key>", "Divvun key for authentication")
.option("--skip-setup", "Skip setup step")
.option("--ignore-dependencies", "Ignore step dependencies", false)
.action(
async (
options: { divvunKey: any; skipSetup: any; ignoreDependencies: any },
) => {
const { divvunKey, skipSetup, ignoreDependencies } = options
const platform = divvunspell.opts().platform.toLowerCase()
const props = { divvunKey, skipSetup, ignoreDependencies }
await enterEnvironment(platform, async () => {
switch (platform) {
case "macos":
await divvunspellMacos("build", props, {
ignoreDependencies,
})
break
case "linux":
await divvunspellLinux("tarball", props, {
// ignoreDependencies,
})
break
case "windows":
await divvunspellWindows("build", props, {
ignoreDependencies,
})
break
default:
logger.error("Unsupported platform. Use 'macos' or 'linux'")
Deno.exit(1)
}
})
},
)
divvunspell
.command("codesign")
.description("Run codesign step")
.option("-k, --divvun-key <key>", "Divvun key for signing")
.option("--skip-setup", "Skip setup step", false)
.option("--skip-signing", "Skip signing step", false)
.option("--ignore-dependencies", "Ignore step dependencies", false)
.action(
async (
options: {
divvunKey: any
skipSetup: any
skipSigning: any
ignoreDependencies: any
},
) => {
await divvunspellMacos(
"codesign",
{
divvunKey: options.divvunKey,
skipSetup: options.skipSetup,
skipSigning: options.skipSigning,
},
{
ignoreDependencies: options.ignoreDependencies,
},
)
},
)
divvunspell
.command("tarball")
.description("Run tarball step")
.option("-k, --divvun-key <key>", "Divvun key for signing")
.option("--skip-setup", "Skip setup step", false)
.option("--skip-signing", "Skip signing step", false)
.option("--ignore-dependencies", "Ignore step dependencies", false)
.action(
async (
options: {
divvunKey: any
skipSetup: any
skipSigning: any
ignoreDependencies: any
},
) => {
await divvunspellMacos(
"tarball",
{
divvunKey: options.divvunKey,
skipSetup: options.skipSetup,
skipSigning: options.skipSigning,
},
{
ignoreDependencies: options.ignoreDependencies,
},
)
},
)
async function enterEnvironment(
platform: string,
callback: () => Promise<void>,
) {
const workingDir = target.workingDir
let id: string | undefined = undefined
switch (platform) {
case "macos": {
if (Deno.build.os === "darwin") {
const isInVirtualMachine = Tart.isInVirtualMachine()
if (!isInVirtualMachine) {
await Tart.enterVirtualMachine(workingDir)
return
}
id = await Tart.enterWorkspace()
} else {
throw new Error(`Unsupported platform: ${platform}`)
}
break
}
case "linux":
case "windows": {
const isInContainer = await Docker.isInContainer()
if (!isInContainer) {
logger.info(`Working directory: ${workingDir}`)
logger.info("Entering Windows Docker container environment...")
await Docker.enterEnvironment("divvun-actions", workingDir)
return
} else {
id = await Docker.enterWorkspace()
}
break
}
default:
logger.error(`Unsupported platform: ${platform}`)
Deno.exit(1)
}
try {
await callback()
} catch (e) {
logger.error(e)
}
switch (platform) {
case "macos": {
if (id) {
await Tart.exitWorkspace(id)
}
break
}
case "linux":
case "windows": {
if (id) {
await Docker.exitWorkspace(id)
}
break
}
}
}
async function localMain() {
const realWorkingDir = target.workingDir
if (realWorkingDir == null) {
logger.error("main.ts cannot be run directly.")
Deno.exit(1)
}
await program.parseAsync(Deno.args)
}
// function delay(timeout: number) {
// return new Promise((resolve) => setTimeout(resolve, timeout))
// }
async function main() {
// builder.startGroup("hello")
// const secrets = await builder.secrets()
// logger.info(secrets)
// logger.error("oh my")
// await delay(500)
// builder.warning("less oh my")
// logger.info("1")
// logger.info("2")
// logger.info("3")
// await delay(500)
// logger.info("4")
// logger.info("5")
// await delay(1000)
// logger.info("example ends in 2 seconds")
// await delay(2000)
// builder.endGroup()
// await delay(500)
// logger.info("Group is now closed!")
builder.setMaxLines(-1)
switch (builder.mode) {
case "local": {
await localMain()
return
}
default:
throw new Error(`Unknown mode: ${builder.mode}`)
}
}
main()
.then(() => Deno.exit(0))
.catch((e) => {
logger.error(e)
Deno.exit(1)
})