Compare commits
4 commits
bb0ac94751
...
b25e0d7390
Author | SHA1 | Date | |
---|---|---|---|
b25e0d7390 | |||
5b9d5c8cc5 | |||
6c9b658860 | |||
0e09f06b02 |
12 changed files with 24 additions and 42 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@flashwave/assproc",
|
||||
"version": "0.3.1",
|
||||
"version": "0.6.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@flashwave/assproc",
|
||||
"version": "0.3.1",
|
||||
"version": "0.6.0",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"@swc/core": "^1.5.25",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@flashwave/assproc",
|
||||
"version": "0.4.0",
|
||||
"version": "0.6.0",
|
||||
"description": "Personal frontend asset processing tool",
|
||||
"main": "./src/index.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -3,7 +3,7 @@ const readline = require('readline');
|
|||
const { join: pathJoin } = require('path');
|
||||
const { trim, trimStart, trimEnd } = require('./trim.js');
|
||||
|
||||
exports.folder = async (root, options) => {
|
||||
module.exports.folder = async (root, options) => {
|
||||
const macroPrefix = options.prefix || '#';
|
||||
const entryPoint = options.entry || '';
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ const combine = require('../combine.js');
|
|||
const { join: pathJoin, dirname } = require('path');
|
||||
const { strtr, shortHash, writeFile } = require('../utils.js');
|
||||
|
||||
exports = function(env) {
|
||||
module.exports = function(env) {
|
||||
const PREFIX = '@';
|
||||
const DEFAULT_ENTRY = 'main.css';
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ const { minify: htmlminify } = require('html-minifier-terser');
|
|||
const { join: pathJoin, dirname } = require('path');
|
||||
const { strtr, shortHash, writeFile } = require('../utils.js');
|
||||
|
||||
exports = function(env) {
|
||||
module.exports = function(env) {
|
||||
const MINIFY_OPTS = {
|
||||
collapseBooleanAttributes: true,
|
||||
collapseWhitespace: true,
|
||||
|
|
|
@ -4,14 +4,14 @@ const { minify: htmlminify } = require('html-minifier-terser');
|
|||
const { join: pathJoin, } = require('path');
|
||||
const { strtr, shortHash, writeFile } = require('../utils.js');
|
||||
|
||||
exports = function(env) {
|
||||
module.exports = function(env) {
|
||||
const PREFIX = '#';
|
||||
const DEFAULT_ENTRY = 'main.js';
|
||||
const DEFAULT_VARS_TARGET = 'window';
|
||||
|
||||
const createJscOpts = () => {
|
||||
return {
|
||||
target: env.swc.es,
|
||||
target: env.swc?.es ?? 'es2021',
|
||||
loose: false,
|
||||
externalHelpers: false,
|
||||
keepClassNames: true,
|
||||
|
@ -19,7 +19,7 @@ exports = function(env) {
|
|||
transform: {},
|
||||
parser: {
|
||||
syntax: 'ecmascript',
|
||||
jsx: env.swc.jsx !== false,
|
||||
jsx: env.swc?.jsx !== false,
|
||||
dynamicImport: false,
|
||||
privateMethod: false,
|
||||
functionBind: false,
|
||||
|
@ -33,7 +33,7 @@ exports = function(env) {
|
|||
transform: {
|
||||
react: {
|
||||
runtime: 'classic',
|
||||
pragma: env.swc.jsx || '',
|
||||
pragma: env.swc?.jsx ?? '$er',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ const { minify: htmlminify } = require('html-minifier-terser');
|
|||
const { join: pathJoin, dirname } = require('path');
|
||||
const { strtr, shortHash, writeFile } = require('../utils.js');
|
||||
|
||||
exports = function(env) {
|
||||
module.exports = function(env) {
|
||||
const MINIFY_OPTS = {
|
||||
collapseBooleanAttributes: true,
|
||||
collapseWhitespace: true,
|
||||
|
@ -22,8 +22,8 @@ exports = function(env) {
|
|||
|
||||
return {
|
||||
process: async (task, vars) => {
|
||||
let { stdout, stderr } = await exec(strtr(env.twig.cmdFormat, {
|
||||
':command': env.twig.cmdPathFull ?? pathJoin(env.root, env.twig.cmdPath),
|
||||
let { stdout, stderr } = await exec(strtr(env.twig?.cmdFormat ?? ':command :path', {
|
||||
':command': env.twig?.cmdPathFull ?? pathJoin(env.root, env.twig?.cmdPath ?? 'tools/render-tpl'),
|
||||
':path': task.source,
|
||||
}));
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ const fs = require('fs');
|
|||
const { join: pathJoin, dirname } = require('path');
|
||||
const { strtr, shortHash, writeFile } = require('../utils.js');
|
||||
|
||||
exports = function(env) {
|
||||
module.exports = function(env) {
|
||||
return {
|
||||
process: async (task, vars) => {
|
||||
let body = JSON.parse(fs.readFileSync(pathJoin(env.source, task.source)));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const fs = require('fs');
|
||||
const { join: pathJoin } = require('path');
|
||||
|
||||
exports.housekeep = path => {
|
||||
module.exports.housekeep = path => {
|
||||
const files = fs.readdirSync(path).map(fileName => {
|
||||
const stats = fs.statSync(pathJoin(path, fileName));
|
||||
return {
|
||||
|
|
22
src/index.js
22
src/index.js
|
@ -5,25 +5,7 @@ const apTwig = require('./handlers/twig.js');
|
|||
const apWebManifest = require('./handlers/webmanifest.js');
|
||||
const { housekeep } = require('./housekeep.js');
|
||||
|
||||
const DEFAULT_ENV = {
|
||||
debug: false,
|
||||
source: undefined,
|
||||
public: undefined,
|
||||
order: undefined,
|
||||
vars: undefined,
|
||||
housekeep: undefined,
|
||||
swc: {
|
||||
es: 'es2021',
|
||||
jsx: '$er',
|
||||
},
|
||||
twig: {
|
||||
cmdFormat: ':command :path',
|
||||
cmdPathFull: undefined,
|
||||
cmdPath: 'tools/render-tpl',
|
||||
},
|
||||
};
|
||||
|
||||
exports.process = async (env, tasks) => {
|
||||
module.exports.process = async (env, tasks) => {
|
||||
if(typeof env.source !== 'string')
|
||||
throw 'env.source must be a path to the source directories';
|
||||
if(typeof env.public !== 'string')
|
||||
|
@ -32,8 +14,6 @@ exports.process = async (env, tasks) => {
|
|||
if(typeof tasks !== 'object' || tasks === null)
|
||||
throw 'tasks must be a non-null object';
|
||||
|
||||
env = { ...DEFAULT_ENV, ...env };
|
||||
|
||||
const types = {
|
||||
js: new apJs(env),
|
||||
css: new apCss(env),
|
||||
|
|
|
@ -16,6 +16,8 @@ const trim = (str, chars = " \n\r\t\v\0", flags = 0) => {
|
|||
return str;
|
||||
};
|
||||
|
||||
exports.trimStart = (str, chars) => trim(str, chars, 0x01);
|
||||
exports.trimEnd = (str, chars) => trim(str, chars, 0x02);
|
||||
exports.trim = (str, chars) => trim(str, chars, 0x03);
|
||||
module.exports = {
|
||||
trimStart: (str, chars) => trim(str, chars, 0x01),
|
||||
trimEnd: (str, chars) => trim(str, chars, 0x02),
|
||||
trim: (str, chars) => trim(str, chars, 0x03),
|
||||
}
|
||||
|
|
|
@ -2,17 +2,17 @@ const crypto = require('crypto');
|
|||
const fs = require('fs');
|
||||
const { dirname } = require('path');
|
||||
|
||||
exports.strtr = (str, replacements) => str.toString().replace(
|
||||
module.exports.strtr = (str, replacements) => str.toString().replace(
|
||||
/{([^}]+)}/g, (match, key) => replacements[key] || match
|
||||
);
|
||||
|
||||
exports.shortHash = text => {
|
||||
module.exports.shortHash = text => {
|
||||
const hash = crypto.createHash('sha256');
|
||||
hash.update(text);
|
||||
return hash.digest('hex').substring(0, 8);
|
||||
};
|
||||
|
||||
exports.writeFile = (path, data) => {
|
||||
module.exports.writeFile = (path, data) => {
|
||||
const folderPath = dirname(path);
|
||||
if(!fs.existsSync(folderPath))
|
||||
fs.mkdirSync(folderPath, { recursive: true });
|
||||
|
|
Loading…
Reference in a new issue