vs-mod-packager 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "vs-mod-packager",
3
+ "version": "1.0.0",
4
+ "description": "Utility to package a Vintage Story mod into a zip using modinfo.json",
5
+ "main": "packager/index.js",
6
+ "bin": {
7
+ "vsmodzip": "./packager/cli.js"
8
+ },
9
+ "scripts": {
10
+ "packagevsmod": "node ./packager/cli.js ."
11
+ },
12
+ "keywords": ["vintagestory", "mod", "zip"],
13
+ "author": "argentskyseer",
14
+ "license": "MIT",
15
+ "files": [
16
+ "packager"
17
+ ],
18
+ "dependencies": {
19
+ "archiver": "^6.0.0",
20
+ "fs-extra": "^11.2.0"
21
+ }
22
+ }
@@ -0,0 +1,20 @@
1
+ const path = require('path');
2
+ const { zipModFolder } = require('./index');
3
+
4
+ const args = process.argv.slice(2);
5
+
6
+ if (args.length < 1) {
7
+ console.log('Usage: modzip <inputFolder>');
8
+ process.exit(1);
9
+ }
10
+
11
+ const inputFolder = path.resolve(args[0]);
12
+
13
+ zipModFolder(inputFolder)
14
+ .then(outputPath => {
15
+ console.log(`Mod Packaged at: ${outputPath}`);
16
+ })
17
+ .catch(err => {
18
+ console.error('Error:', err.message);
19
+ process.exit(1);
20
+ });
@@ -0,0 +1,65 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+ const archiver = require('archiver');
4
+
5
+ async function zipModFolder(inputFolder) {
6
+ const modInfoPath = path.join(inputFolder, 'modinfo.json');
7
+
8
+ if (!(await fs.pathExists(modInfoPath))) {
9
+ throw new Error('modinfo.json not found in input folder');
10
+ }
11
+
12
+ const modInfo = await fs.readJson(modInfoPath);
13
+
14
+ if (!modInfo.modid || !modInfo.version) {
15
+ throw new Error('modinfo.json must contain "modid" and "version"');
16
+ }
17
+
18
+ const zipName = `${modInfo.modid}-${modInfo.version}.zip`;
19
+
20
+ // output to dist
21
+ const outputFolder = path.join(inputFolder, 'dist');
22
+ const outputPath = path.join(outputFolder, zipName);
23
+
24
+ await fs.ensureDir(outputFolder);
25
+
26
+ // Remove existing zip with same name if its there
27
+ if (await fs.pathExists(outputPath)) {
28
+ await fs.remove(outputPath);
29
+ }
30
+
31
+ return new Promise((resolve, reject) => {
32
+ const output = fs.createWriteStream(outputPath);
33
+ const archive = archiver('zip', { zlib: { level: 9 } });
34
+
35
+ output.on('close', () => resolve(outputPath));
36
+ output.on('error', reject);
37
+ archive.on('error', reject);
38
+
39
+ archive.pipe(output);
40
+
41
+ //ignore all the things
42
+ archive.glob('**/*', {
43
+ cwd: inputFolder,
44
+ dot: true,
45
+ ignore: [
46
+ '**/*.zip',
47
+ 'node_modules/**',
48
+ '.git/**',
49
+ 'dist/**',
50
+ '**/*.zip',
51
+ 'node_modules/**',
52
+ '.git/**',
53
+ 'dist/**',
54
+ 'packager/**',
55
+ 'package.json',
56
+ 'package-lock.json',
57
+ '.gitignore'
58
+ ]
59
+ });
60
+
61
+ archive.finalize();
62
+ });
63
+ }
64
+
65
+ module.exports = { zipModFolder };