-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
108 lines (94 loc) · 4.26 KB
/
index.js
File metadata and controls
108 lines (94 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* Copyright (c) 2023 - present | LuciferMorningstarDev <contact@lucifer-morningstar.xyz>
* Copyright (c) 2023 - present | whackdevelopment.com <contact@whackdevelopment.com>
* Copyright (c) 2023 - present | whackdevelopment.com team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const fs = require('node:fs');
const minifyBash = require('bash-minifier');
if (!fs.existsSync('./dist/')) {
fs.mkdirSync('./dist/');
}
function isStatEqual(object1, object2) {
return (
object1.dev === object2.dev &&
object1.mode === object2.mode &&
object1.nlink === object2.nlink &&
object1.uid === object2.uid &&
object1.gid === object2.gid &&
object1.rdev === object2.rdev &&
object1.blksize === object2.blksize &&
object1.size === object2.size &&
object1.blocks === object2.blocks &&
object1.atimeMs === object2.atimeMs &&
object1.mtimeMs === object2.mtimeMs &&
object1.ctimeMs === object2.ctimeMs &&
object1.birthtimeMs === object2.birthtimeMs &&
object1.atime === object2.atime &&
object1.mtime === object2.mtime &&
object1.ctime === object2.ctime &&
object1.birthtime === object2.birthtime
);
}
async function recursiveWalkAndCopy(ignore = [], path, dist = './dist') {
console.log('Walking through' + path);
let files = fs.readdirSync(`${path}`);
for (let entity of files) {
let currentPath = `${path}/${entity}`;
let currentDest = currentPath.replace(path, dist);
if (ignore.includes(currentPath) || ignore.includes(currentPath + '/')) continue;
let statCurrent = fs.statSync(currentPath);
if (statCurrent.isDirectory()) {
recursiveWalkAndCopy(ignore, currentPath, currentDest);
} else {
try {
let distArgs = currentDest.split('/');
let filename = distArgs.pop();
let dir = distArgs.join('/');
fs.mkdirSync(dir, { recursive: true });
// console.log('Processing ', { currentPath, to: { dir, filename } });
// continue;
if (currentPath.endsWith('.sh')) {
let newContent = '#!/bin/bash\n' + minifyBash(fs.readFileSync(currentPath, 'utf8'));
let realDist = currentDest.replace(filename, filename.slice(0, -3));
let oldContent = '';
try {
oldContent = fs.readFileSync(realDist, 'utf8');
} catch (err) {}
if (newContent === oldContent) {
console.log('Skipping copy of', currentPath, 'content match in' + realDist);
continue;
}
fs.writeFileSync(realDist, newContent, { encoding: 'utf8', flag: 'w' });
console.log('Copied&Minified ', currentPath, ' to ', currentDest);
continue;
}
if (fs.existsSync(currentDest)) {
console.log('Skipping copy of', currentPath, 'file exists' + currentDest);
continue;
}
// fs.createReadStream(currentPath).pipe(fs.createWriteStream(currentDist));
fs.copyFile(currentPath, currentDest, (err) => {
if (err) throw err;
console.log('Copied', currentPath, 'to', currentDest);
});
} catch (error) {
console.log('ERROR while Copying', currentPath, 'to', currentDest);
console.error(error);
}
}
}
}
recursiveWalkAndCopy(['./src/testing'], './src');