Forgot about logging and housekeeping.
This commit is contained in:
parent
a2c2a5f7b6
commit
8d1650260c
3 changed files with 20 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@flashwave/assproc",
|
"name": "@flashwave/assproc",
|
||||||
"version": "0.0.1",
|
"version": "0.1.0",
|
||||||
"description": "Personal frontend asset processing tool",
|
"description": "Personal frontend asset processing tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { join as pathJoin } from 'path';
|
import { join as pathJoin } from 'path';
|
||||||
|
|
||||||
export const housekeep = path => {
|
export const housekeep = path => {
|
||||||
const files = fs.readdirSync(path).map(fileName => {
|
const files = fs.readdirSync(path).map(fileName => {
|
||||||
const stats = fs.statSync(pathJoin(path, fileName));
|
const stats = fs.statSync(pathJoin(path, fileName));
|
||||||
return {
|
return {
|
||||||
|
|
18
src/index.js
18
src/index.js
|
@ -3,6 +3,7 @@ import apHtml from './handlers/html.js';
|
||||||
import apJs from './handlers/js.js';
|
import apJs from './handlers/js.js';
|
||||||
import apTwig from './handlers/twig.js';
|
import apTwig from './handlers/twig.js';
|
||||||
import apWebManifest from './handlers/webmanifest.js';
|
import apWebManifest from './handlers/webmanifest.js';
|
||||||
|
import { housekeep } from './housekeep.js';
|
||||||
|
|
||||||
const DEFAULT_ENV = {
|
const DEFAULT_ENV = {
|
||||||
debug: false,
|
debug: false,
|
||||||
|
@ -10,6 +11,7 @@ const DEFAULT_ENV = {
|
||||||
public: undefined,
|
public: undefined,
|
||||||
order: undefined,
|
order: undefined,
|
||||||
vars: undefined,
|
vars: undefined,
|
||||||
|
housekeep: undefined,
|
||||||
swc: {
|
swc: {
|
||||||
es: 'es2021',
|
es: 'es2021',
|
||||||
jsx: '$er',
|
jsx: '$er',
|
||||||
|
@ -57,15 +59,31 @@ const public = {
|
||||||
if(!Array.isArray(typeTasks))
|
if(!Array.isArray(typeTasks))
|
||||||
throw 'children of the tasks object must be arrays';
|
throw 'children of the tasks object must be arrays';
|
||||||
|
|
||||||
|
console.info(`Building '${type}' assets...`);
|
||||||
|
|
||||||
const handler = types[type];
|
const handler = types[type];
|
||||||
|
|
||||||
for(const task of typeTasks) {
|
for(const task of typeTasks) {
|
||||||
|
console.info(` => ${task.source}...`);
|
||||||
const path = await handler.process(task, vars);
|
const path = await handler.process(task, vars);
|
||||||
|
|
||||||
if(typeof task.varsName === 'string')
|
if(typeof task.varsName === 'string')
|
||||||
vars[task.varsGroup ?? ''][task.varsName] = path;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue