generated from stegripe/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractImage.mjs
35 lines (27 loc) · 1.05 KB
/
extractImage.mjs
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
#!/usr/bin/env node
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { EOL } from "node:os";
const path = process.argv.at(2);
const key = process.argv.at(3);
const getValue = string => /[^:]+$/u.exec(string)?.at(0).trim();
const applyVariant = (string, variant) => `${string}-${variant}`;
const lines = readFileSync(resolve(path)).toString().split(EOL);
const originalTags = getValue(lines.at(0))?.split(", ") ?? [];
const variant = getValue(lines.at(1));
const version = getValue(lines.at(3)).split("-").at(0);
const semverArray = version.split(".");
const versions = semverArray.map((_, i) => semverArray.slice(0, semverArray.length - i).join("."));
const recipe = {
tags: [...versions, ...originalTags].map(t => variant !== undefined ? (applyVariant(t, variant)) : t),
variant,
platforms: getValue(lines.at(2))?.split(", ") ?? [],
version
};
if (key) {
let value = recipe[key];
if (value instanceof Array) value = value.join("\n");
console.info(value);
} else {
console.info(JSON.stringify(recipe, null, 4));
}