-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbuild.js
96 lines (81 loc) · 3.39 KB
/
build.js
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
const fs = require('fs');
const path = require('path');
// Define paths
const distPath = path.join(__dirname, 'dist/modernbot.user.js');
const modulesPath = path.join(__dirname, 'new/modules');
const menuPath = path.join(__dirname, 'new/menu.js');
const indexPath = path.join(__dirname, 'new/index.js');
const utilsPath = path.join(__dirname, 'new/utils.js');
const windowPath = path.join(__dirname, 'new/window.js');
const stylePath = path.join(__dirname, 'new/style.css');
// Function to get the new version number
function getNextVersion() {
let version = '0.0.1';
// Check if the dist file already exists to retrieve the current version
if (fs.existsSync(distPath)) {
const content = fs.readFileSync(distPath, 'utf-8');
const versionMatch = content.match(/@version\s+(\d+\.\d+\.\d+)/);
if (versionMatch) {
const [major, minor, patch] = versionMatch[1].split('.').map(Number);
version = `${major}.${minor}.${patch + 1}`; // Increment patch version by 1
}
}
return version;
}
// Determine if the version should be updated based on the command-line argument
const shouldUpdateVersion = process.argv.includes('--version');
const version = shouldUpdateVersion ? getNextVersion() : '1.0.0'; // Default version if not updating
// Header template with conditional version
const header = `// ==UserScript==
// @name ModernBot
// @version ${version}
// @description A modern grepolis bot
// @match http://*.grepolis.com/game/*
// @match https://*.grepolis.com/game/*
// @updateURL https://github.com/Sau1707/ModernBot/blob/main/dist/merged.user.js
// @downloadURL https://github.com/Sau1707/ModernBot/blob/main/dist/merged.user.js
// @icon https://raw.githubusercontent.com/Sau1707/ModernBot/main/img/gear.png
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// ==/UserScript==
(function () {
'use strict';
var uw;
if (typeof unsafeWindow == 'undefined') {
uw = window;
} else {
uw = unsafeWindow;
}
// Dynamically add CSS
var style = document.createElement("style");
style.type = "text/css";
style.innerHTML = \`${fs.readFileSync(stylePath, 'utf-8').replace(/`/g, '\\`')}\`;
document.head.appendChild(style);
`;
// Ensure dist folder exists
if (!fs.existsSync(path.dirname(distPath))) {
fs.mkdirSync(path.dirname(distPath), { recursive: true });
}
// Write header and style to the output file
fs.writeFileSync(distPath, header);
// Append utils.js
[utilsPath, windowPath].forEach(filePath => {
const content = fs.readFileSync(filePath, 'utf-8');
const fileName = path.basename(filePath);
fs.appendFileSync(distPath, `\n\n// File: ${fileName}\n${content}`);
});
// Read and append each module file
fs.readdirSync(modulesPath).forEach(file => {
const filePath = path.join(modulesPath, file);
const content = fs.readFileSync(filePath, 'utf-8');
fs.appendFileSync(distPath, `\n\n// Module: ${file}\n${content}`);
});
// Append menu.js and index.js
[menuPath, indexPath].forEach(filePath => {
const content = fs.readFileSync(filePath, 'utf-8');
const fileName = path.basename(filePath);
fs.appendFileSync(distPath, `\n\n// File: ${fileName}\n${content}`);
});
fs.appendFileSync(distPath, `\n})();`);
if (shouldUpdateVersion) {
console.log(`modernbot.user.js created successfully in /dist with version ${version}.`);
}