|
| 1 | +//Imports |
| 2 | + import ejs from "ejs" |
| 3 | + import fs from "fs/promises" |
| 4 | + import paths from "path" |
| 5 | + import url from "url" |
| 6 | + import sgit from "simple-git" |
| 7 | + import metadata from "../source/app/metrics/metadata.mjs" |
| 8 | + |
| 9 | +//Mode |
| 10 | + const [mode = "dryrun"] = process.argv.slice(2) |
| 11 | + console.log(`Mode: ${mode}`) |
| 12 | + |
| 13 | +//Paths |
| 14 | + const __metrics = paths.join(paths.dirname(url.fileURLToPath(import.meta.url)), "..") |
| 15 | + const __action = paths.join(__metrics, "source/app/action") |
| 16 | + const __web = paths.join(__metrics, "source/app/web") |
| 17 | + const __readme = paths.join(__metrics, ".github/readme") |
| 18 | + |
| 19 | +//Git setup |
| 20 | + const git = sgit(__metrics) |
| 21 | + const staged = new Set() |
| 22 | + |
| 23 | +//Load plugins metadata |
| 24 | + const {plugins, templates} = await metadata({log:false}) |
| 25 | + |
| 26 | +//Update generated files |
| 27 | + async function update({source, output, options = {}}) { |
| 28 | + //Regenerate file |
| 29 | + console.log(`Generating ${output}`) |
| 30 | + const content = await ejs.renderFile(source, {plugins, templates}, {async:true, ...options}) |
| 31 | + //Save result |
| 32 | + const file = paths.join(__metrics, output) |
| 33 | + await fs.writeFile(file, content) |
| 34 | + //Add to git |
| 35 | + staged.add(file) |
| 36 | + } |
| 37 | + |
| 38 | +//Rendering |
| 39 | + await update({source:paths.join(__readme, "README.md"), output:"README.md", options:{root:__readme}}) |
| 40 | + await update({source:paths.join(__readme, "partials/documentation/plugins.md"), output:"source/plugins/README.md"}) |
| 41 | + await update({source:paths.join(__readme, "partials/documentation/templates.md"), output:"source/templates/README.md"}) |
| 42 | + await update({source:paths.join(__action, "action.yml"), output:"action.yml"}) |
| 43 | + await update({source:paths.join(__web, "settings.example.json"), output:"settings.example.json"}) |
| 44 | + |
| 45 | +//Commit and push |
| 46 | + if (mode === "publish") { |
| 47 | + await git |
| 48 | + .addConfig("user.name", "GitHub Action") |
| 49 | + .addConfig("user.email", "<>") |
| 50 | + .add(...staged) |
| 51 | + .commit("Auto regenerate files - [Skip GitHub Action]") |
| 52 | + .push("origin", "master") |
| 53 | + } |
0 commit comments