-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMypackageBuild.ts
81 lines (70 loc) · 2.67 KB
/
MypackageBuild.ts
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
#!/usr/bin/env node
const fs = require("fs-extra");
const glob = require("glob");
const zip = require('bestzip');
const path = require("path");
const pathToMods = "D:\\spt-381\\user\\mods"
const { author, name:packageName, version } = require("./package.json");
const packageNameRes = packageName.replace(/[^a-z0-9]/gi, "");
const packageNameRes2 = `MarsyApp-${packageNameRes}`;
const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageNameRes}-${version}`;
console.log(`Generated package name: ${modName}`);
fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true });
fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true });
console.log("Previous build files deleted.");
const ignoreList = [
"node_modules/",
// "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules.
"src/**/*.js",
"types/",
".git/",
".gitea/",
".eslintignore",
".eslintrc.json",
".gitignore",
".DS_Store",
"packageBuild.ts",
"mod.code-workspace",
"package-lock.json",
"tsconfig.json",
".idea",
"README.md",
"test.json",
"test2.json",
"test3.json",
"test4.json",
"test5.json",
"test6.json",
"test7.json",
"allItemsName.json",
"MypackageBuild.ts",
"clientMod",
"dist",
modName
];
const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true });
fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) =>
{
return !exclude.includes(filePath);
}});
fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true });
fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${pathToMods}/${packageNameRes2}`));
console.log("Build files copied.");
fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist/user/mods/${packageNameRes2}`));
fs.copySync(path.normalize(`${__dirname}/clientMod/bin/Release/net472/${packageNameRes2}.dll`), path.normalize(`${__dirname}/dist/BepInEx/plugins/${packageNameRes2}.dll`));
console.log("dist files copied.");
const dirsArray = fs.readdirSync(`${__dirname}/dist`);
console.log(dirsArray);
zip({
source: dirsArray,
destination: `${modName}.zip`,
cwd: `${__dirname}/dist`,
}).catch(function(err)
{
console.error("A bestzip error has occurred: ", err.stack);
}).then(function()
{
console.log(`Compressed mod package to: /dist/${modName}.zip`);
fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true });
console.log("Build successful! your zip file has been created and is ready to be uploaded to hub.sp-tarkov.com/files/");
});