Fixed exports (again).

This commit is contained in:
flash 2024-06-10 02:33:07 +00:00
parent bb0ac94751
commit 0e09f06b02
10 changed files with 16 additions and 14 deletions

View file

@ -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 || '';

View file

@ -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';

View file

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

View file

@ -4,7 +4,7 @@ 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';

View file

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

View file

@ -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)));

View file

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

View file

@ -23,7 +23,7 @@ const DEFAULT_ENV = {
}, },
}; };
exports.process = async (env, tasks) => { module.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')

View file

@ -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),
}

View file

@ -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 });