-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
executable file
·84 lines (74 loc) · 2.24 KB
/
main.ts
File metadata and controls
executable file
·84 lines (74 loc) · 2.24 KB
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
#!/usr/bin/env -S deno run -A
import { readFile, writeFile, lstat } from "node:fs/promises";
import { $ } from "npm:zx";
import process from "node:process";
import { temporaryDirectory, temporaryWrite } from "npm:tempy";
import { join } from "node:path";
import * as core from "npm:@actions/core";
import { glob } from "npm:glob";
let path = core.getInput("path");
if ((await lstat(path)).isDirectory()) {
console.log("original path");
const pattern = join(path, "[Rr][Ee][Aa][Dd][Mm][Ee].{md,mdown,markdown}");
console.log("glob pattern", pattern);
const globbed = await glob(pattern);
console.log("glob result", globbed);
path = globbed[0];
}
console.log("resolved path", path);
let collection = core.getInput("collection");
if (!collection.includes(":")) {
collection += ":latest";
}
console.log("resolved collection", collection);
let md = await readFile(path, "utf8");
const tempDirPath = temporaryDirectory();
$.cwd = tempDirPath;
await $`oras pull ${collection}`;
const devcontainerCollection = JSON.parse(
await readFile(join($.cwd, "devcontainer-collection.json"), "utf8")
);
console.log(devcontainerCollection);
if (devcontainerCollection.features) {
const featureListMD = devcontainerCollection.features
.map((f) => {
let s
if (f.documentationURL) {
s = `- **[${f.name || f.id}](${f.documentationURL})**`
} else {
s = `- **${f.name || f.id}**`
}
if (f.description) {
s += ` - ${f.description}`
}
return s
})
.join("\n");
console.log(featureListMD);
md = md.replace(
/(<!-- START_FEATURE_LIST -->)([\s\S]*?)(<!-- END_FEATURE_LIST -->)/,
`$1\n\n${featureListMD}\n\n$3`
);
}
if (devcontainerCollection.templates) {
const templateListMD = devcontainerCollection.templates
.map((f) => {
let s
if (f.documentationURL) {
s = `- **[${f.name || f.id}](${f.documentationURL})**`
} else {
s = `- **${f.name || f.id}**`
}
if (f.description) {
s += ` - ${f.description}`
}
return s
})
.join("\n");
console.log(templateListMD);
md = md.replace(
/(<!-- START_TEMPLATE_LIST -->)([\s\S]*?)(<!-- END_TEMPLATE_LIST -->)/,
`$1\n\n${templateListMD}\n\n$3`
);
}
await writeFile(path, md);