From 8d1650260cb1d073bba389ae1e3d8d9924d3745c Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 9 Jun 2024 19:54:05 +0000 Subject: [PATCH] Forgot about logging and housekeeping. --- package.json | 2 +- src/housekeep.js | 2 +- src/index.js | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c32587c..071b106 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@flashwave/assproc", - "version": "0.0.1", + "version": "0.1.0", "description": "Personal frontend asset processing tool", "main": "index.js", "scripts": { diff --git a/src/housekeep.js b/src/housekeep.js index ad6d8c1..b584920 100644 --- a/src/housekeep.js +++ b/src/housekeep.js @@ -1,7 +1,7 @@ import fs from 'fs'; import { join as pathJoin } from 'path'; -export const housekeep = path => { +export const housekeep = path => { const files = fs.readdirSync(path).map(fileName => { const stats = fs.statSync(pathJoin(path, fileName)); return { diff --git a/src/index.js b/src/index.js index 34f8a34..778ad96 100644 --- a/src/index.js +++ b/src/index.js @@ -3,6 +3,7 @@ import apHtml from './handlers/html.js'; import apJs from './handlers/js.js'; import apTwig from './handlers/twig.js'; import apWebManifest from './handlers/webmanifest.js'; +import { housekeep } from './housekeep.js'; const DEFAULT_ENV = { debug: false, @@ -10,6 +11,7 @@ const DEFAULT_ENV = { public: undefined, order: undefined, vars: undefined, + housekeep: undefined, swc: { es: 'es2021', jsx: '$er', @@ -57,15 +59,31 @@ const public = { if(!Array.isArray(typeTasks)) throw 'children of the tasks object must be arrays'; + console.info(`Building '${type}' assets...`); + const handler = types[type]; for(const task of typeTasks) { + console.info(` => ${task.source}...`); const path = await handler.process(task, vars); if(typeof task.varsName === 'string') vars[task.varsGroup ?? ''][task.varsName] = path; } } + + + const hkDirs = env.housekeep ?? []; + if(!Array.isArray(hkDirs)) + throw 'env.housekeep must be an array of folder paths'; + + if(hkDirs.length > 0) { + console.info(`Doing some housekeeping...`); + for(const path of hkDirs) { + console.info(` => ${path}...`); + housekeep(path); + } + } }, };