Website Structure

This commit is contained in:
supalerk-ar66 2026-01-13 10:46:40 +07:00
parent 62812f2090
commit 71f0676a62
22365 changed files with 4265753 additions and 791 deletions

View file

@ -0,0 +1,45 @@
'use strict';
/**
* Dependencies
*/
const fs = require('fs');
const makeReplacements = require('./make-replacements');
/**
* Helper to replace in a single file (async)
*/
module.exports = function replaceAsync(file, from, to, config) {
//Extract relevant config
const {encoding, dry, countMatches} = config;
//Wrap in promise
return new Promise((resolve, reject) => {
fs.readFile(file, encoding, (error, contents) => {
//istanbul ignore if
if (error) {
return reject(error);
}
//Make replacements
const [result, newContents] = makeReplacements(
contents, from, to, file, countMatches
);
//Not changed or dry run?
if (!result.hasChanged || dry) {
return resolve(result);
}
//Write to file
fs.writeFile(file, newContents, encoding, error => {
//istanbul ignore if
if (error) {
return reject(error);
}
resolve(result);
});
});
});
};