Skip to content

Commit

Permalink
* (bluefox) Added tools for admin: patchHtmlFile
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Aug 29, 2024
1 parent b907a44 commit c4307b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ And use in `package.json` `scripts`:
### **WORK IN PROGRESS**
-->
## Changelog
### 0.0.4 (2024-08-29)
### **WORK IN PROGRESS**
* (bluefox) Added tools for admin: patchHtmlFile

### 0.0.3 (2024-08-29)
Expand Down
26 changes: 25 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ function collectFiles(patterns: string[] | string): { name: string; base: string
export function copyFiles(
patterns: string[] | string,
dest: string,
options?: {
process?: (fileData: string) => string,
replace?: { find: string | RegExp, text: string }[],
},
) {
const files = collectFiles(patterns);
for (let f = 0; f < files.length; f++) {
Expand All @@ -116,7 +120,20 @@ export function copyFiles(
mkdirSync(folder, { recursive: true });
}
console.log(`Copy "${files[f].base}/${files[f].name}" to "${destName}"`);
copyFileSync(`${files[f].base}/${files[f].name}`, destName);
if (options) {
let data = readFileSync(`${files[f].base}/${files[f].name}`).toString('utf8');
if (options.replace) {
for (let r = 0; r < options.replace.length; r++) {
data = data.replace(options.replace[r].find, options.replace[r].text);
}
}
if (options.process) {
data = options.process(data);
}
writeFileSync(destName, data);
} else {
copyFileSync(`${files[f].base}/${files[f].name}`, destName);
}
}
}

Expand Down Expand Up @@ -197,6 +214,13 @@ export function buildCraco(
let script = `${src}/node_modules/@craco/craco/dist/bin/craco.js`;
if (rootDir && !existsSync(script)) {
script = `${rootDir}/node_modules/@craco/craco/dist/bin/craco.js`;
if (!existsSync(script)) {
// admin could have another structure
script = `${rootDir}/../node_modules/@craco/craco/dist/bin/craco.js`;
if (!existsSync(script)) {
script = `${rootDir}/../../node_modules/@craco/craco/dist/bin/craco.js`;
}
}
}
if (!existsSync(script)) {
console.error(`Cannot find execution file: ${script}`);
Expand Down

0 comments on commit c4307b2

Please sign in to comment.