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