Compare commits

...

2 commits

Author SHA1 Message Date
72230e07b0 Added file list generation. 2024-06-09 20:00:58 +00:00
8d1650260c Forgot about logging and housekeeping. 2024-06-09 19:54:05 +00:00
3 changed files with 26 additions and 2 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@flashwave/assproc",
"version": "0.0.1",
"version": "0.2.0",
"description": "Personal frontend asset processing tool",
"main": "index.js",
"scripts": {

View file

@ -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 {

View file

@ -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',
@ -49,6 +51,8 @@ const public = {
if(typeof vars !== 'object' || vars === null)
throw 'env.vars must be a non-null object';
const files = {};
for(const type of order) {
if(!(type in types))
throw `${type} is not a supported build task type`;
@ -57,15 +61,35 @@ 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;
files[task.source] = 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);
}
}
return files;
},
};