PKD Protector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks whether the string contains a given string. | |
* | |
* @memberof JsExtensions | |
* @param {string} string - The string to search for. | |
* @returns {boolean} True if the string contains a given string. | |
* @deprecated includes() should be used instead. | |
*/ | |
String.prototype.contains = function(string) { | |
return this.includes(string); | |
}; | |
// * Вывести себя в console.log | |
String.prototype.p = function () { | |
console.log(this.toString().format(...arguments)); | |
}; | |
/** | |
* Replaces %1, %2 and so on in the string to the arguments. | |
* | |
* @memberof JsExtensions | |
* @param {any} ...args The objects to format. | |
* @returns {string} A formatted string. | |
*/ | |
String.prototype.format = function () { | |
return this.replace(/%([0-9]+)/g, (s, n) => arguments[Number(n) - 1]); | |
}; | |
var masterFileName = 'MasterFile.js'; | |
const testFolder = 'js/plugins'; | |
const fs = require('fs'); | |
// * Данные мастер файла | |
var masterContent = ""; | |
function masterFilePath() { | |
return testFolder + "/" + masterFileName; | |
} | |
// * Получить список имён плагинов | |
function getPluginOrderedList() { | |
var pluginsJS = fs.readFileSync("js/plugins.js", 'utf8'); | |
var re = /("name":"(.+)","status":true)/gm; | |
var founded = pluginsJS.match(re); | |
var pluginNames = []; | |
let reGroups = new RegExp("\"name\":\"(.+)\","); | |
for (const line of founded) { | |
pluginNames.push((line.match(reGroups)[1]) + ".js"); | |
} | |
masterFileName = pluginNames[0]; | |
return pluginNames; | |
} | |
function removeBetween(content, a, b) { | |
var sI = content.indexOf(a); | |
var sE = content.indexOf(b); | |
//console.log(sI); | |
//console.log(sE); | |
if(sI >= 0 && sE >= 0) | |
content = content.replace(content.substring(sI, sE + b.length), ""); | |
return content; | |
} | |
function removeParams(content) { | |
content = content.replace(/~struct~\w+:/gi, "//"); | |
content = content.replace(/@param\s\w+/gi, "//"); | |
content = content.replace(/@text\s\w+/gi, "//"); | |
content = content.replace(/@type\s\w+/gi, "//"); | |
content = content.replace(/@desc\s\w+/gi, "//"); | |
content = content.replace(/@parent\s\w+/gi, "//"); | |
content = content.replace(/@option\s\w+/gi, "//"); | |
content = content.replace(/@value\s\w+/gi, "//"); | |
content = content.replace(/@on\s\w+/gi, "//"); | |
content = content.replace(/@off\s\w+/gi, "//"); | |
content = content.replace(/@default\s\w+/gi, "//"); | |
return content; | |
} | |
let Main = () => { | |
// * Занулить (очистить) мастер файл | |
//fs.writeFileSync(masterFilePath(), ""); | |
let pluginOrderedList = getPluginOrderedList(); | |
for(const name of pluginOrderedList) { | |
console.log("Working with " + name); | |
var pluginContent = fs.readFileSync(testFolder + "/" + name, 'utf8'); | |
console.log("Read - ok " + pluginContent.length); | |
pluginContent = removeBetween(pluginContent, "/*:", "*/"); | |
pluginContent = removeParams(pluginContent); | |
masterContent += pluginContent; | |
console.log("Remove data - ok"); | |
// * Очистить файл | |
fs.writeFileSync(testFolder + "/" + name, "", "utf8"); | |
console.log("Clear file - ok"); | |
//break; | |
} | |
console.log("Write master file"); | |
fs.writeFileSync(masterFilePath(), ""); | |
fs.writeFileSync(masterFilePath(), masterContent, 'utf8'); | |
console.log("ALL DONE"); | |
}; | |
Main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment