|
| 1 | +import * as TOML from "https://unpkg.com/@aduh95/toml@0.4.2/web/toml2js.js"; |
| 2 | + |
| 3 | +//init toml parser for some reason idk there was no Deno native module |
| 4 | +await TOML.default(); |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +//Read in thunderstore.toml |
| 9 | +const tstore = TOML.parse(await Deno.readTextFile("./thunderstore.toml")); |
| 10 | + |
| 11 | +const name = Deno.env.get("TS_NAME"); |
| 12 | +const version = Deno.env.get("TS_VERSION"); |
| 13 | +const desc = Deno.env.get("TS_DESCRIPTION"); |
| 14 | +const homepage = Deno.env.get("TS_WEBSITE"); |
| 15 | +const categories = Deno.env.get("TS_CATEGORIES").replace(/\n/g, ''); |
| 16 | +const deps = Deno.env.get("TS_DEPS").replace(/\n/g, ' '); |
| 17 | +const community = Deno.env.get("TS_COMMUNITY"); |
| 18 | +const nsfw = Deno.env.get("TS_NSFW"); |
| 19 | +const wrap = Deno.env.get("TS_WRAP"); |
| 20 | + |
| 21 | +console.log(deps) |
| 22 | + |
| 23 | +//these should be set already but we're rewriting the whole file anyways |
| 24 | +tstore.package.name = name; |
| 25 | +tstore.package.versionNumber = version; |
| 26 | +tstore.package.description = desc; |
| 27 | + |
| 28 | +tstore.publish.communities = [community]; |
| 29 | +tstore.build.copy[0].target = wrap; |
| 30 | +tstore.package.dependencies = {}; |
| 31 | + |
| 32 | +console.log(tstore.build); |
| 33 | + |
| 34 | +//check for optional inputs |
| 35 | +if (homepage && homepage !== "") { |
| 36 | + tstore.package.websiteUrl = homepage; |
| 37 | +} |
| 38 | + |
| 39 | +if (nsfw && nsfw !== "" ) { |
| 40 | + tstore.package.containsNsfwContent = true |
| 41 | +} |
| 42 | + |
| 43 | +if (categories && categories !== "") { |
| 44 | + //only keep truthy elements from the split |
| 45 | + tstore.publish.categories = categories.split(' ').filter(e => e).map(e=> e.toLowerCase()); |
| 46 | +} |
| 47 | + |
| 48 | +if (deps && deps !== "") { |
| 49 | + const p = {}; |
| 50 | + for (let d of deps.split(' ')) { |
| 51 | + if(!d) |
| 52 | + continue; |
| 53 | + if (!d.includes('@')) { |
| 54 | + console.log("Malformed dependency at ", d); |
| 55 | + Deno.exit(-1); |
| 56 | + } |
| 57 | + |
| 58 | + const parts = d.split('@'); |
| 59 | + p[parts[0]] = parts[1]; |
| 60 | + } |
| 61 | + |
| 62 | + console.log(p); |
| 63 | + tstore.package.dependencies = p; |
| 64 | +} |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +//write config file back to disk |
| 72 | +Deno.writeTextFile("./thunderstore.toml", TOML.stringify(tstore)); |
0 commit comments