dcs-git-utils 1.0.8 → 1.0.10
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/.github/workflows/release.yml +2 -2
- package/README.md +4 -1
- package/dist/files/modified-date.js +32 -0
- package/dist/files/modified-date.js.map +1 -0
- package/dist/main.js +14 -3
- package/dist/main.js.map +1 -1
- package/package.json +4 -2
- package/src/files/modified-date.ts +19 -0
- package/src/main.ts +18 -5
- package/config.json +0 -4
package/README.md
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
DCS shuffles the keys in the configs when saving, to be able to version control, we need to sort the keys of config objects.
|
|
4
4
|
|
|
5
5
|
## Getting started
|
|
6
|
+
|
|
6
7
|
Select the .miz you want to work on and use git to version control the mission!
|
|
7
8
|
|
|
8
9
|
## Alternatives to running it
|
|
9
10
|
|
|
10
|
-
- ```npx dcs-git-utils```
|
|
11
|
+
- ```npx dcs-git-utils ./mission.miz```
|
|
11
12
|
- download the exe's from releases
|
|
12
13
|
- clone the repo
|
|
13
14
|
|
|
@@ -19,6 +20,8 @@ Select the .miz you want to work on and use git to version control the mission!
|
|
|
19
20
|
- (When saving in editor) After writing the .miz completes, it unpacks the archive and sorts the content, THEN re-archives into the .miz again to keep everything consistent for version control.
|
|
20
21
|
- When editing anything in ./out, archive (.miz) is created from ./out.
|
|
21
22
|
|
|
23
|
+
- When starting, it checks latest modified of both the outdir and .miz to prevent that something gets overwritten if you start using this tool after saving it in the mission editor.
|
|
24
|
+
|
|
22
25
|
### Cmd args for debugging purposes
|
|
23
26
|
|
|
24
27
|
a single arg of a .miz filepath can be given to override file selection
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.latestModifiedMsFromDir = void 0;
|
|
16
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
17
|
+
const fs_1 = __importDefault(require("fs"));
|
|
18
|
+
const slash_1 = __importDefault(require("slash"));
|
|
19
|
+
const latestModifiedMsFromDir = (dir) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const dirPath = (0, slash_1.default)(dir);
|
|
21
|
+
const files = yield (0, fast_glob_1.default)(`${dirPath}/**/*`, {
|
|
22
|
+
dot: false,
|
|
23
|
+
onlyFiles: true,
|
|
24
|
+
});
|
|
25
|
+
if (files.length === 0)
|
|
26
|
+
return 0;
|
|
27
|
+
const mtimes = files.map(file => fs_1.default.statSync(file).mtimeMs);
|
|
28
|
+
const latestTimestamp = Math.max(...mtimes);
|
|
29
|
+
return latestTimestamp;
|
|
30
|
+
});
|
|
31
|
+
exports.latestModifiedMsFromDir = latestModifiedMsFromDir;
|
|
32
|
+
//# sourceMappingURL=modified-date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modified-date.js","sourceRoot":"","sources":["../../src/files/modified-date.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAA2B;AAC3B,4CAAoB;AACpB,kDAA0B;AAEnB,MAAM,uBAAuB,GAAG,CAAO,GAAW,EAAE,EAAE;IACzD,MAAM,OAAO,GAAG,IAAA,eAAK,EAAC,GAAG,CAAC,CAAC;IAC3B,MAAM,KAAK,GAAG,MAAM,IAAA,mBAAE,EAAC,GAAG,OAAO,OAAO,EAAE;QACtC,GAAG,EAAE,KAAK;QACV,SAAS,EAAE,IAAI;KAClB,CAAC,CAAC;IAEH,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAEjC,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,YAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;IAE5D,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IAE5C,OAAO,eAAe,CAAC;AAC3B,CAAC,CAAA,CAAA;AAdY,QAAA,uBAAuB,2BAcnC"}
|
package/dist/main.js
CHANGED
|
@@ -20,6 +20,7 @@ const watchers_1 = require("./watchers");
|
|
|
20
20
|
const compression_1 = require("./compression");
|
|
21
21
|
const sorting_1 = require("./sorting");
|
|
22
22
|
const config_1 = require("./config");
|
|
23
|
+
const modified_date_1 = require("./files/modified-date");
|
|
23
24
|
const [_0, _1, file, backup] = node_process_1.default.argv;
|
|
24
25
|
const shouldBackup = backup === "--backup";
|
|
25
26
|
const backupMiz = (filepath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -29,17 +30,27 @@ const backupMiz = (filepath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
29
30
|
const fileWithoutExt = filepath.replace(node_path_1.default.extname(filepath), "");
|
|
30
31
|
yield node_fs_1.promises.copyFile(filepath, `${fileWithoutExt}_backup_${new Date().toISOString().replace(/:/g, '-')}.miz`);
|
|
31
32
|
});
|
|
33
|
+
const isOutDirLatest = (outDir, miz) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
if (!(0, node_fs_1.existsSync)(outDir)) {
|
|
35
|
+
console.log(`No outdir at: ${outDir}`);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const latestOutDir = yield (0, modified_date_1.latestModifiedMsFromDir)(outDir);
|
|
39
|
+
const mizModified = (0, node_fs_1.statSync)(miz).mtimeMs;
|
|
40
|
+
console.log(`outDir latest: ${latestOutDir}, miz modified at: ${mizModified}`);
|
|
41
|
+
return latestOutDir > mizModified;
|
|
42
|
+
});
|
|
32
43
|
const initialize = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
44
|
const { missionPath, outDir, } = yield (0, config_1.initializeConfig)({ file });
|
|
34
45
|
if (shouldBackup) {
|
|
35
46
|
backupMiz(missionPath);
|
|
36
47
|
}
|
|
37
|
-
if ((
|
|
38
|
-
console.log('
|
|
48
|
+
if (yield isOutDirLatest(outDir, missionPath)) {
|
|
49
|
+
console.log('using out as source');
|
|
39
50
|
yield (0, compression_1.handleArchive)(outDir, missionPath);
|
|
40
51
|
}
|
|
41
52
|
else {
|
|
42
|
-
console.log("
|
|
53
|
+
console.log("using .miz as source");
|
|
43
54
|
const files = yield (0, compression_1.unpackMiz)(missionPath, outDir);
|
|
44
55
|
const filePaths = files.filter(f => f.type === "file").map(f => node_path_1.default.join(outDir, f.path));
|
|
45
56
|
yield (0, sorting_1.sortFiles)(filePaths);
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,gEAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,gEAAmC;AACnC,qCAA+D;AAC/D,0DAA4B;AAC5B,yCAA2C;AAC3C,+CAAyD;AACzD,uCAAsC;AACtC,qCAA4C;AAC5C,yDAAgE;AAEhE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,sBAAO,CAAC,IAAI,CAAC;A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Y,EAAE,CAAC;QACf,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,MAAM,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC;QAC5C,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACnC,MAAM,IAAA,2BAAa,EAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC7C,CAAC;SAAM,CAAC;QACJ,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;QACpC,MAAM,KAAK,GAAG,MAAM,IAAA,uBAAS,EAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACnD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,mBAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3F,MAAM,IAAA,mBAAS,EAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AAC5C,CAAC,CAAA,CAAA;AAED,CAAC,GAAS,EAAE;IAER,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,EAAE,CAAC;IAE/C,IAAA,wBAAa,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC,CAAA,CAAC,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dcs-git-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -52,10 +52,12 @@
|
|
|
52
52
|
"archiver": "^7.0.1",
|
|
53
53
|
"chokidar": "^3.6.0",
|
|
54
54
|
"decompress": "^4.2.1",
|
|
55
|
+
"fast-glob": "^3.3.3",
|
|
55
56
|
"fengari": "^0.1.4",
|
|
56
57
|
"fengari-interop": "^0.1.3",
|
|
57
58
|
"inquirer": "^8.2.7",
|
|
58
59
|
"lodash": "^4.17.21",
|
|
59
|
-
"luaparse": "^0.3.1"
|
|
60
|
+
"luaparse": "^0.3.1",
|
|
61
|
+
"slash": "^5.1.0"
|
|
60
62
|
}
|
|
61
63
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fg from 'fast-glob';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import slash from 'slash';
|
|
4
|
+
|
|
5
|
+
export const latestModifiedMsFromDir = async (dir: string) => {
|
|
6
|
+
const dirPath = slash(dir);
|
|
7
|
+
const files = await fg(`${dirPath}/**/*`, {
|
|
8
|
+
dot: false,
|
|
9
|
+
onlyFiles: true,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
if (files.length === 0) return 0;
|
|
13
|
+
|
|
14
|
+
const mtimes = files.map(file => fs.statSync(file).mtimeMs);
|
|
15
|
+
|
|
16
|
+
const latestTimestamp = Math.max(...mtimes);
|
|
17
|
+
|
|
18
|
+
return latestTimestamp;
|
|
19
|
+
}
|
package/src/main.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import process from "node:process";
|
|
4
|
-
import { promises as fs, existsSync } from "node:fs";
|
|
4
|
+
import { promises as fs, existsSync, statSync } from "node:fs";
|
|
5
5
|
import path from "node:path"
|
|
6
6
|
import { startWatchers } from "./watchers";
|
|
7
7
|
import { handleArchive, unpackMiz } from "./compression";
|
|
8
8
|
import { sortFiles } from "./sorting";
|
|
9
9
|
import { initializeConfig } from "./config";
|
|
10
|
+
import { latestModifiedMsFromDir } from "./files/modified-date";
|
|
10
11
|
|
|
11
12
|
const [_0, _1, file, backup] = process.argv;
|
|
12
13
|
|
|
@@ -22,6 +23,19 @@ const backupMiz = async (filepath: string) => {
|
|
|
22
23
|
await fs.copyFile(filepath, `${fileWithoutExt}_backup_${new Date().toISOString().replace(/:/g, '-')}.miz`);
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
const isOutDirLatest = async (outDir: string, miz: string) => {
|
|
27
|
+
|
|
28
|
+
if (!existsSync(outDir)) {
|
|
29
|
+
console.log(`No outdir at: ${outDir}`);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const latestOutDir = await latestModifiedMsFromDir(outDir);
|
|
34
|
+
const mizModified = statSync(miz).mtimeMs;
|
|
35
|
+
console.log(`outDir latest: ${latestOutDir}, miz modified at: ${mizModified}`);
|
|
36
|
+
return latestOutDir > mizModified;
|
|
37
|
+
}
|
|
38
|
+
|
|
25
39
|
const initialize = async () => {
|
|
26
40
|
|
|
27
41
|
const { missionPath, outDir, } = await initializeConfig({ file });
|
|
@@ -30,11 +44,11 @@ const initialize = async () => {
|
|
|
30
44
|
backupMiz(missionPath);
|
|
31
45
|
}
|
|
32
46
|
|
|
33
|
-
if (
|
|
34
|
-
console.log('
|
|
47
|
+
if (await isOutDirLatest(outDir, missionPath)) {
|
|
48
|
+
console.log('using out as source');
|
|
35
49
|
await handleArchive(outDir, missionPath);
|
|
36
50
|
} else {
|
|
37
|
-
console.log("
|
|
51
|
+
console.log("using .miz as source");
|
|
38
52
|
const files = await unpackMiz(missionPath, outDir);
|
|
39
53
|
const filePaths = files.filter(f => f.type === "file").map(f => path.join(outDir, f.path));
|
|
40
54
|
await sortFiles(filePaths);
|
|
@@ -43,7 +57,6 @@ const initialize = async () => {
|
|
|
43
57
|
return { mizPath: missionPath, outDir };
|
|
44
58
|
}
|
|
45
59
|
|
|
46
|
-
|
|
47
60
|
(async () => {
|
|
48
61
|
|
|
49
62
|
const { mizPath, outDir } = await initialize();
|
package/config.json
DELETED