From 7e5b2edb423fca06c9bb129815bfecb7686d51d7 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 22 Oct 2022 04:35:14 +0300 Subject: [PATCH] Create update.js --- scripts/commands/status/update.js | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 scripts/commands/status/update.js diff --git a/scripts/commands/status/update.js b/scripts/commands/status/update.js new file mode 100644 index 00000000..9e3abdba --- /dev/null +++ b/scripts/commands/status/update.js @@ -0,0 +1,52 @@ +const { file, markdown, logger, table } = require('../../core') +const { program } = require('commander') +const _ = require('lodash') + +const CONFIGS_PATH = process.env.CONFIGS_PATH || 'sites/**/*.config.js' + +const options = program + .option('-c, --config ', 'Set path to config file', '.readme/status.json') + .parse(process.argv) + .opts() + +async function main() { + let data = [] + + const files = await file.list(CONFIGS_PATH).catch(console.error) + for (const filepath of files) { + try { + const { site, ignore } = require(file.resolve(filepath)) + + if (ignore) continue + + data.push([ + site, + `${site}` + ]) + } catch (err) { + console.error(err) + continue + } + } + + data = Object.values(_.groupBy(data, item => item[0])) + + const output = table.create(data, [ + 'Site', + 'Status                                                   ' + ]) + + await file.create('./.readme/_sites.md', output) + + await updateMarkdown() +} + +main() + +async function updateMarkdown() { + logger.info('updating status.md...') + + const config = require(file.resolve(options.config)) + await file.createDir(file.dirname(config.build)) + await markdown.compile(options.config) +}