Compare commits
2 commits
a2c2a5f7b6
...
72230e07b0
Author | SHA1 | Date | |
---|---|---|---|
72230e07b0 | |||
8d1650260c |
3 changed files with 26 additions and 2 deletions
|
@ -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": {
|
||||
|
|
24
src/index.js
24
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',
|
||||
|
@ -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;
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue