isaacscript 1.2.1 → 1.2.2
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/dist/package.json +1 -1
- package/dist/src/commands/copy/copy.js +1 -2
- package/dist/src/commands/copy/copy.js.map +1 -1
- package/dist/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.js +4 -4
- package/dist/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.js.map +1 -1
- package/dist/src/monkeyPatch.js +4 -10
- package/dist/src/monkeyPatch.js.map +1 -1
- package/package.json +1 -1
- package/publish.sh +1 -1
- package/src/commands/copy/copy.ts +1 -2
- package/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.ts +3 -3
- package/src/monkeyPatch.ts +4 -11
- package/publish_npm.py +0 -331
package/dist/package.json
CHANGED
|
@@ -26,7 +26,6 @@ exports.compileAndCopy = exports.copy = void 0;
|
|
|
26
26
|
const path_1 = __importDefault(require("path"));
|
|
27
27
|
const constants_1 = require("../../constants");
|
|
28
28
|
const file = __importStar(require("../../file"));
|
|
29
|
-
const monkeyPatch_1 = require("../../monkeyPatch");
|
|
30
29
|
const util_1 = require("../../util");
|
|
31
30
|
function copy(config) {
|
|
32
31
|
const modTargetDirectoryName = (0, util_1.getModTargetDirectoryName)(config);
|
|
@@ -36,7 +35,7 @@ function copy(config) {
|
|
|
36
35
|
exports.copy = copy;
|
|
37
36
|
function compileAndCopy(modSourcePath, modTargetPath) {
|
|
38
37
|
compile();
|
|
39
|
-
|
|
38
|
+
// monkeyPatchMainLua(modSourcePath);
|
|
40
39
|
copyMod(modSourcePath, modTargetPath);
|
|
41
40
|
}
|
|
42
41
|
exports.compileAndCopy = compileAndCopy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy.js","sourceRoot":"","sources":["../../../../src/commands/copy/copy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,+CAAkD;AAClD,iDAAmC;
|
|
1
|
+
{"version":3,"file":"copy.js","sourceRoot":"","sources":["../../../../src/commands/copy/copy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,+CAAkD;AAClD,iDAAmC;AAEnC,qCAAkE;AAElE,SAAgB,IAAI,CAAC,MAAc;IACjC,MAAM,sBAAsB,GAAG,IAAA,gCAAyB,EAAC,MAAM,CAAC,CAAC;IACjE,MAAM,aAAa,GAAG,cAAI,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,sBAAsB,CAAC,CAAC;IAC9E,cAAc,CAAC,2BAAe,EAAE,aAAa,CAAC,CAAC;AACjD,CAAC;AAJD,oBAIC;AAED,SAAgB,cAAc,CAC5B,aAAqB,EACrB,aAAqB;IAErB,OAAO,EAAE,CAAC;IACV,qCAAqC;IACrC,OAAO,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AACxC,CAAC;AAPD,wCAOC;AAED,SAAS,OAAO;IACd,IAAA,gBAAS,EAAC,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3B,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,OAAO,CAAC,aAAqB,EAAE,aAAqB;IAC3D,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;QAC9B,IAAI,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC;KAC3C;IACD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACxC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -3,10 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const path_1 = __importDefault(require("path"));
|
|
7
6
|
const sync_directory_1 = __importDefault(require("sync-directory"));
|
|
8
7
|
const constants_1 = require("../../../constants");
|
|
9
|
-
const monkeyPatch_1 = require("../../../monkeyPatch");
|
|
10
8
|
let modSourcePath;
|
|
11
9
|
let modTargetPath;
|
|
12
10
|
init();
|
|
@@ -33,9 +31,11 @@ function afterEachSync(params) {
|
|
|
33
31
|
if (params === undefined) {
|
|
34
32
|
return;
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
/*
|
|
35
|
+
if (params.relativePath === path.sep + MAIN_LUA) {
|
|
36
|
+
monkeyPatchMainLua(modTargetPath);
|
|
38
37
|
}
|
|
38
|
+
*/
|
|
39
39
|
if (params.eventType !== "init:copy") {
|
|
40
40
|
send(`${constants_1.FILE_SYNCED_MESSAGE} ${params.relativePath}`);
|
|
41
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modDirectorySyncer.js","sourceRoot":"","sources":["../../../../../src/commands/monitor/modDirectorySyncer/modDirectorySyncer.ts"],"names":[],"mappings":";;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"modDirectorySyncer.js","sourceRoot":"","sources":["../../../../../src/commands/monitor/modDirectorySyncer/modDirectorySyncer.ts"],"names":[],"mappings":";;;;;AAAA,oEAA2C;AAC3C,kDAAyD;AAEzD,IAAI,aAAqB,CAAC;AAC1B,IAAI,aAAqB,CAAC;AAE1B,IAAI,EAAE,CAAC;AAEP,SAAS,IAAI;IACX,MAAM,OAAO,GAAG,CAAC,CAAC;IAClB,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,GAAG,OAAO,EAAE;QACvC,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;KACH;IAED,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChC,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEhC,IAAA,wBAAa,EAAC,aAAa,EAAE,aAAa,EAAE;QAC1C,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,MAAM;QACZ,aAAa;QACb,OAAO;QACP,oBAAoB,EAAE;YACpB,gBAAgB,EAAE;gBAChB,kBAAkB,EAAE,IAAI;aACzB;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,MAMtB;IACC,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,OAAO;KACR;IAED;;;;MAIE;IAEF,IAAI,MAAM,CAAC,SAAS,KAAK,WAAW,EAAE;QACpC,IAAI,CAAC,GAAG,+BAAmB,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;KACvD;AACH,CAAC;AAED,SAAS,OAAO,CAAC,GAAU;IACzB,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,GAAG,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,IAAI,CAAC,GAAW;IACvB,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE;QACtC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACnB;AACH,CAAC"}
|
package/dist/src/monkeyPatch.js
CHANGED
|
@@ -43,24 +43,18 @@ see the official website: https://isaacscript.github.io/
|
|
|
43
43
|
|
|
44
44
|
`;
|
|
45
45
|
const MAIN_LUA_REPLACEMENTS = [
|
|
46
|
-
// For TSTL v1.2.X
|
|
46
|
+
// For TSTL v1.2.X-v1.3.3
|
|
47
|
+
// (fixed with GlassBrick's PR)
|
|
47
48
|
["WeakMap = __TS__Class()", "WeakMap = WeakMap or __TS__Class()"],
|
|
48
49
|
["WeakSet = __TS__Class()", "WeakSet = WeakSet or __TS__Class()"],
|
|
49
50
|
["Map = __TS__Class()", "Map = Map or __TS__Class()"],
|
|
50
51
|
["Set = __TS__Class()", "Set = Set or __TS__Class()"],
|
|
51
|
-
// For TSTL v1.1.1
|
|
52
|
-
/*
|
|
53
|
-
["WeakMap = (function", "WeakMap = WeakMap or (function"],
|
|
54
|
-
["WeakSet = (function", "WeakSet = WeakSet or (function"],
|
|
55
|
-
["Map = (function", "Map = Map or (function"],
|
|
56
|
-
["Set = (function", "Set = Set or (function"],
|
|
57
|
-
*/
|
|
58
52
|
];
|
|
59
53
|
function monkeyPatchMainLua(targetModDirectory) {
|
|
60
54
|
const mainLuaPath = path_1.default.join(targetModDirectory, constants_1.MAIN_LUA);
|
|
61
|
-
|
|
55
|
+
const mainLua = file.read(mainLuaPath);
|
|
62
56
|
// mainLua = patchInformationalHeader(mainLua);
|
|
63
|
-
mainLua = patchGlobalObjects(mainLua);
|
|
57
|
+
// mainLua = patchGlobalObjects(mainLua);
|
|
64
58
|
file.write(mainLuaPath, mainLua);
|
|
65
59
|
}
|
|
66
60
|
exports.monkeyPatchMainLua = monkeyPatchMainLua;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monkeyPatch.js","sourceRoot":"","sources":["../../src/monkeyPatch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,2CAAuC;AACvC,6CAA+B;AAE/B,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;CAe5B,CAAC;AAEF,MAAM,qBAAqB,GAAG;IAC5B,
|
|
1
|
+
{"version":3,"file":"monkeyPatch.js","sourceRoot":"","sources":["../../src/monkeyPatch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,2CAAuC;AACvC,6CAA+B;AAE/B,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;CAe5B,CAAC;AAEF,MAAM,qBAAqB,GAAG;IAC5B,yBAAyB;IACzB,+BAA+B;IAC/B,CAAC,yBAAyB,EAAE,oCAAoC,CAAC;IACjE,CAAC,yBAAyB,EAAE,oCAAoC,CAAC;IACjE,CAAC,qBAAqB,EAAE,4BAA4B,CAAC;IACrD,CAAC,qBAAqB,EAAE,4BAA4B,CAAC;CACtD,CAAC;AAEF,SAAgB,kBAAkB,CAAC,kBAA0B;IAC3D,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,oBAAQ,CAAC,CAAC;IAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEvC,+CAA+C;IAC/C,yCAAyC;IAEzC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACnC,CAAC;AARD,gDAQC;AAED,kFAAkF;AAClF,6DAA6D;AAC7D,SAAS,wBAAwB,CAAC,OAAe;IAC/C,OAAO,oBAAoB,GAAG,OAAO,CAAC;AACxC,CAAC;AAED,2EAA2E;AAC3E,mFAAmF;AACnF,oDAAoD;AACpD,kGAAkG;AAClG,6BAA6B;AAC7B,SAAS,kBAAkB,CAAC,eAAuB;IACjD,IAAI,OAAO,GAAG,eAAe,CAAC;IAE9B,KAAK,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,IAAI,qBAAqB,EAAE;QAC/D,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;KACtD;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
package/publish.sh
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { MOD_SOURCE_PATH } from "../../constants";
|
|
3
3
|
import * as file from "../../file";
|
|
4
|
-
import { monkeyPatchMainLua } from "../../monkeyPatch";
|
|
5
4
|
import { Config } from "../../types/Config";
|
|
6
5
|
import { execShell, getModTargetDirectoryName } from "../../util";
|
|
7
6
|
|
|
@@ -16,7 +15,7 @@ export function compileAndCopy(
|
|
|
16
15
|
modTargetPath: string,
|
|
17
16
|
): void {
|
|
18
17
|
compile();
|
|
19
|
-
monkeyPatchMainLua(modSourcePath);
|
|
18
|
+
// monkeyPatchMainLua(modSourcePath);
|
|
20
19
|
copyMod(modSourcePath, modTargetPath);
|
|
21
20
|
}
|
|
22
21
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import path from "path";
|
|
2
1
|
import syncDirectory from "sync-directory";
|
|
3
|
-
import { FILE_SYNCED_MESSAGE
|
|
4
|
-
import { monkeyPatchMainLua } from "../../../monkeyPatch";
|
|
2
|
+
import { FILE_SYNCED_MESSAGE } from "../../../constants";
|
|
5
3
|
|
|
6
4
|
let modSourcePath: string;
|
|
7
5
|
let modTargetPath: string;
|
|
@@ -43,9 +41,11 @@ function afterEachSync(params?: {
|
|
|
43
41
|
return;
|
|
44
42
|
}
|
|
45
43
|
|
|
44
|
+
/*
|
|
46
45
|
if (params.relativePath === path.sep + MAIN_LUA) {
|
|
47
46
|
monkeyPatchMainLua(modTargetPath);
|
|
48
47
|
}
|
|
48
|
+
*/
|
|
49
49
|
|
|
50
50
|
if (params.eventType !== "init:copy") {
|
|
51
51
|
send(`${FILE_SYNCED_MESSAGE} ${params.relativePath}`);
|
package/src/monkeyPatch.ts
CHANGED
|
@@ -20,27 +20,20 @@ see the official website: https://isaacscript.github.io/
|
|
|
20
20
|
`;
|
|
21
21
|
|
|
22
22
|
const MAIN_LUA_REPLACEMENTS = [
|
|
23
|
-
// For TSTL v1.2.X
|
|
23
|
+
// For TSTL v1.2.X-v1.3.3
|
|
24
|
+
// (fixed with GlassBrick's PR)
|
|
24
25
|
["WeakMap = __TS__Class()", "WeakMap = WeakMap or __TS__Class()"],
|
|
25
26
|
["WeakSet = __TS__Class()", "WeakSet = WeakSet or __TS__Class()"],
|
|
26
27
|
["Map = __TS__Class()", "Map = Map or __TS__Class()"],
|
|
27
28
|
["Set = __TS__Class()", "Set = Set or __TS__Class()"],
|
|
28
|
-
|
|
29
|
-
// For TSTL v1.1.1
|
|
30
|
-
/*
|
|
31
|
-
["WeakMap = (function", "WeakMap = WeakMap or (function"],
|
|
32
|
-
["WeakSet = (function", "WeakSet = WeakSet or (function"],
|
|
33
|
-
["Map = (function", "Map = Map or (function"],
|
|
34
|
-
["Set = (function", "Set = Set or (function"],
|
|
35
|
-
*/
|
|
36
29
|
];
|
|
37
30
|
|
|
38
31
|
export function monkeyPatchMainLua(targetModDirectory: string): void {
|
|
39
32
|
const mainLuaPath = path.join(targetModDirectory, MAIN_LUA);
|
|
40
|
-
|
|
33
|
+
const mainLua = file.read(mainLuaPath);
|
|
41
34
|
|
|
42
35
|
// mainLua = patchInformationalHeader(mainLua);
|
|
43
|
-
mainLua = patchGlobalObjects(mainLua);
|
|
36
|
+
// mainLua = patchGlobalObjects(mainLua);
|
|
44
37
|
|
|
45
38
|
file.write(mainLuaPath, mainLua);
|
|
46
39
|
}
|
package/publish_npm.py
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
|
|
3
|
-
import argparse
|
|
4
|
-
import hashlib
|
|
5
|
-
import json
|
|
6
|
-
import os
|
|
7
|
-
import re
|
|
8
|
-
import subprocess
|
|
9
|
-
import sys
|
|
10
|
-
|
|
11
|
-
import pkg_resources
|
|
12
|
-
|
|
13
|
-
if sys.version_info < (3, 0):
|
|
14
|
-
printf("Error: This script requires Python 3.")
|
|
15
|
-
sys.exit(1)
|
|
16
|
-
|
|
17
|
-
# Constants
|
|
18
|
-
VERSION = pkg_resources.get_distribution("publish_npm").version
|
|
19
|
-
DIR = os.getcwd()
|
|
20
|
-
PROJECT_NAME = os.path.basename(DIR)
|
|
21
|
-
PACKAGE_JSON = "package.json"
|
|
22
|
-
PACKAGE_JSON_PATH = os.path.join(DIR, PACKAGE_JSON)
|
|
23
|
-
UPDATE_SCRIPT_NAME = "update.sh"
|
|
24
|
-
UPDATE_SCRIPT_PATH = os.path.join(DIR, UPDATE_SCRIPT_NAME)
|
|
25
|
-
BUILD_SCRIPT_NAME = "build.sh"
|
|
26
|
-
BUILD_SCRIPT_PATH = os.path.join(DIR, BUILD_SCRIPT_NAME)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def main():
|
|
30
|
-
args = parse_command_line_arguments()
|
|
31
|
-
check_package_json_exists()
|
|
32
|
-
check_logged_in_to_npm()
|
|
33
|
-
update_dependencies(args)
|
|
34
|
-
|
|
35
|
-
# Before we increment the version number, make sure that the program compiles
|
|
36
|
-
if is_typescript_project():
|
|
37
|
-
printf("Testing to see if the project compiles...")
|
|
38
|
-
compile_typescript()
|
|
39
|
-
|
|
40
|
-
# Increment the version number
|
|
41
|
-
version = get_version_from_package_json()
|
|
42
|
-
if not args.skip_increment:
|
|
43
|
-
version = increment_version(version)
|
|
44
|
-
put_version(version)
|
|
45
|
-
|
|
46
|
-
# Build the program again so that the new version number is included in the compiled code
|
|
47
|
-
if is_typescript_project():
|
|
48
|
-
printf("Re-compiling the project...")
|
|
49
|
-
compile_typescript()
|
|
50
|
-
|
|
51
|
-
git_commit_if_changes(args, version)
|
|
52
|
-
|
|
53
|
-
publish_to_npm()
|
|
54
|
-
|
|
55
|
-
# Done
|
|
56
|
-
printf(f"Published {PROJECT_NAME} version {version} successfully.")
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def parse_command_line_arguments():
|
|
60
|
-
parser = argparse.ArgumentParser(
|
|
61
|
-
description="Publish a new version of this package to NPM."
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
parser.add_argument(
|
|
65
|
-
"-v",
|
|
66
|
-
"--version",
|
|
67
|
-
action="version",
|
|
68
|
-
help="display the version",
|
|
69
|
-
version=VERSION,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
parser.add_argument(
|
|
73
|
-
"-s",
|
|
74
|
-
"--skip-increment",
|
|
75
|
-
action="store_true",
|
|
76
|
-
help=f'do not increment the version number in the "{PACKAGE_JSON}" file',
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
parser.add_argument(
|
|
80
|
-
"-u",
|
|
81
|
-
"--skip-update",
|
|
82
|
-
action="store_true",
|
|
83
|
-
help=f'do not update NPM dependencies in the "{PACKAGE_JSON}" file',
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
parser.add_argument(
|
|
87
|
-
"-c",
|
|
88
|
-
"--skip-commit",
|
|
89
|
-
action="store_true",
|
|
90
|
-
help="do not make a commit to the git repository",
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
return parser.parse_args()
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def check_package_json_exists():
|
|
97
|
-
if not os.path.isfile(PACKAGE_JSON_PATH):
|
|
98
|
-
error(
|
|
99
|
-
f'Failed to find the "{PACKAGE_JSON}" file in the current working directory.'
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def check_logged_in_to_npm():
|
|
104
|
-
completed_process = subprocess.run(
|
|
105
|
-
["npm", "whoami"],
|
|
106
|
-
shell=True,
|
|
107
|
-
stdout=subprocess.DEVNULL,
|
|
108
|
-
stderr=subprocess.DEVNULL,
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
if completed_process.returncode != 0:
|
|
112
|
-
error(
|
|
113
|
-
'The "npm whoami" command failed, so you are probably not logged in. Try doing "npm login".'
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def update_dependencies(args):
|
|
118
|
-
if args.skip_update:
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
printf("Updating NPM dependencies...")
|
|
122
|
-
|
|
123
|
-
# Get the hash before we potentially modify the "package.json" file
|
|
124
|
-
before_hash = get_hash_of_package_json()
|
|
125
|
-
|
|
126
|
-
if os.path.isfile(UPDATE_SCRIPT_PATH):
|
|
127
|
-
run_script(UPDATE_SCRIPT_NAME, UPDATE_SCRIPT_PATH)
|
|
128
|
-
else:
|
|
129
|
-
completed_process = subprocess.run(
|
|
130
|
-
[
|
|
131
|
-
"npx",
|
|
132
|
-
"npm-check-updates",
|
|
133
|
-
"--upgrade",
|
|
134
|
-
"--packageFile",
|
|
135
|
-
PACKAGE_JSON,
|
|
136
|
-
"--loglevel",
|
|
137
|
-
"silent",
|
|
138
|
-
],
|
|
139
|
-
shell=True,
|
|
140
|
-
)
|
|
141
|
-
if completed_process.returncode != 0:
|
|
142
|
-
error(
|
|
143
|
-
f'Failed to run the "npm-check-updates" program to update the "{PACKAGE_JSON}" dependencies to the latest versions.'
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
after_hash = get_hash_of_package_json()
|
|
147
|
-
if before_hash != after_hash:
|
|
148
|
-
# The package.json file was modified, so install the new dependencies
|
|
149
|
-
printf("Installing NPM dependencies...")
|
|
150
|
-
completed_process = subprocess.run(["npm", "install", "--silent"], shell=True)
|
|
151
|
-
if completed_process.returncode != 0:
|
|
152
|
-
error('Failed to run "npm install".')
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
def get_hash_of_package_json():
|
|
156
|
-
with open(PACKAGE_JSON_PATH, "rb") as file_handle:
|
|
157
|
-
file_hash = hashlib.md5()
|
|
158
|
-
file_contents = file_handle.read()
|
|
159
|
-
file_hash.update(file_contents)
|
|
160
|
-
|
|
161
|
-
return file_hash.hexdigest()
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
def get_version_from_package_json():
|
|
165
|
-
with open(PACKAGE_JSON_PATH, "r", encoding="utf8") as file_handle:
|
|
166
|
-
package_json = json.load(file_handle)
|
|
167
|
-
|
|
168
|
-
if "version" not in package_json:
|
|
169
|
-
error(f'Failed to find the version in the "{PACKAGE_JSON_PATH}" file.')
|
|
170
|
-
|
|
171
|
-
return package_json["version"]
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
def increment_version(version: str):
|
|
175
|
-
match = re.search(r"(.+\..+\.)(.+)", version)
|
|
176
|
-
if not match:
|
|
177
|
-
error(f"Failed to parse the version number of: {version}")
|
|
178
|
-
version_prefix = match.group(1)
|
|
179
|
-
patch_version = int(match.group(2)) # i.e. the third number
|
|
180
|
-
incremented_patch_version = patch_version + 1
|
|
181
|
-
incremented_version = version_prefix + str(incremented_patch_version)
|
|
182
|
-
|
|
183
|
-
return incremented_version
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
def put_version(version: str):
|
|
187
|
-
with open(PACKAGE_JSON_PATH, "r", encoding="utf8") as file_handle:
|
|
188
|
-
package_json = json.load(file_handle)
|
|
189
|
-
|
|
190
|
-
package_json["version"] = version
|
|
191
|
-
|
|
192
|
-
with open(PACKAGE_JSON_PATH, "w", encoding="utf8", newline="\n") as file_handle:
|
|
193
|
-
json.dump(package_json, file_handle, indent=2, separators=(",", ": "))
|
|
194
|
-
file_handle.write("\n")
|
|
195
|
-
|
|
196
|
-
completed_process = subprocess.run(["npx", "sort-package-json"], shell=True)
|
|
197
|
-
if completed_process.returncode != 0:
|
|
198
|
-
error(f'Failed to sort the "{PACKAGE_JSON}" file.')
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
def is_typescript_project():
|
|
202
|
-
with open(
|
|
203
|
-
PACKAGE_JSON_PATH,
|
|
204
|
-
"r",
|
|
205
|
-
encoding="utf8",
|
|
206
|
-
) as file_handle:
|
|
207
|
-
package_json = json.load(file_handle)
|
|
208
|
-
|
|
209
|
-
return (
|
|
210
|
-
"dependencies" in package_json and "typescript" in package_json["dependencies"]
|
|
211
|
-
) or (
|
|
212
|
-
"devDependencies" in package_json
|
|
213
|
-
and "typescript" in package_json["devDependencies"]
|
|
214
|
-
)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
def compile_typescript():
|
|
218
|
-
if os.path.isfile(BUILD_SCRIPT_PATH):
|
|
219
|
-
run_script(BUILD_SCRIPT_NAME, BUILD_SCRIPT_PATH)
|
|
220
|
-
else:
|
|
221
|
-
completed_process = subprocess.run(["rm", "-rf", "dist"], shell=True)
|
|
222
|
-
if completed_process.returncode != 0:
|
|
223
|
-
error('Failed to remove the "dist" directory.')
|
|
224
|
-
|
|
225
|
-
completed_process = subprocess.run(["npx", "tsc"], shell=True)
|
|
226
|
-
if completed_process.returncode != 0:
|
|
227
|
-
error('Failed to build the project with "npx tsc".')
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
def git_commit_if_changes(args, version):
|
|
231
|
-
if args.skip_commit:
|
|
232
|
-
return
|
|
233
|
-
|
|
234
|
-
# Check to see if this is a git repository
|
|
235
|
-
completed_process = subprocess.run(
|
|
236
|
-
["git", "status"],
|
|
237
|
-
stdout=subprocess.DEVNULL,
|
|
238
|
-
stderr=subprocess.DEVNULL,
|
|
239
|
-
)
|
|
240
|
-
if completed_process.returncode != 0:
|
|
241
|
-
error("This is not a git repository.")
|
|
242
|
-
|
|
243
|
-
# Check to see if there are any changes
|
|
244
|
-
# https://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommitted-changes
|
|
245
|
-
completed_process = subprocess.run(["git", "diff-index", "--quiet", "HEAD", "--"])
|
|
246
|
-
changes_to_existing_files = completed_process.returncode != 0
|
|
247
|
-
|
|
248
|
-
# Check to see if there are any untracked files
|
|
249
|
-
# https://stackoverflow.com/questions/11021287/git-detect-if-there-are-untracked-files-quickly
|
|
250
|
-
completed_process = subprocess.run(
|
|
251
|
-
["git", "ls-files", "--other", "--directory", "--exclude-standard"],
|
|
252
|
-
stdout=subprocess.PIPE,
|
|
253
|
-
)
|
|
254
|
-
if completed_process.returncode != 0:
|
|
255
|
-
error("Failed to git ls-files.")
|
|
256
|
-
git_output = completed_process.stdout.decode("utf-8")
|
|
257
|
-
untracked_files_exist = git_output is not None and git_output.strip() != ""
|
|
258
|
-
|
|
259
|
-
if not changes_to_existing_files and not untracked_files_exist:
|
|
260
|
-
printf("There are no changes to push to git.")
|
|
261
|
-
return
|
|
262
|
-
|
|
263
|
-
# Commit to the repository
|
|
264
|
-
printf("Committing to the Git repository...")
|
|
265
|
-
completed_process = subprocess.run(["git", "add", "-A"])
|
|
266
|
-
if completed_process.returncode != 0:
|
|
267
|
-
error("Failed to git add.")
|
|
268
|
-
completed_process = subprocess.run(["git", "commit", "-m", version])
|
|
269
|
-
if completed_process.returncode != 0:
|
|
270
|
-
error("Failed to git commit.")
|
|
271
|
-
completed_process = subprocess.run(["git", "pull", "--rebase"])
|
|
272
|
-
if completed_process.returncode != 0:
|
|
273
|
-
error("Failed to git pull.")
|
|
274
|
-
completed_process = subprocess.run(["git", "push"])
|
|
275
|
-
if completed_process.returncode != 0:
|
|
276
|
-
error("Failed to git push.")
|
|
277
|
-
|
|
278
|
-
printf(f"Pushed a commit to git for version: {version}")
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
def publish_to_npm():
|
|
282
|
-
printf("Publishing to NPM...")
|
|
283
|
-
completed_process = subprocess.run(
|
|
284
|
-
[
|
|
285
|
-
"npm",
|
|
286
|
-
"publish",
|
|
287
|
-
"--access",
|
|
288
|
-
"public",
|
|
289
|
-
],
|
|
290
|
-
shell=True,
|
|
291
|
-
)
|
|
292
|
-
if completed_process.returncode != 0:
|
|
293
|
-
error("Failed to npm publish.")
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
def error(msg):
|
|
297
|
-
printf(f"Error: {msg}")
|
|
298
|
-
sys.exit(1)
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
def run_script(script_name, script_path: str):
|
|
302
|
-
completed_process = subprocess.run(
|
|
303
|
-
["bash", script_path],
|
|
304
|
-
shell=True,
|
|
305
|
-
capture_output=True,
|
|
306
|
-
)
|
|
307
|
-
if completed_process.returncode != 0:
|
|
308
|
-
error_script(completed_process, script_name)
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
def error_script(completed_process: subprocess.CompletedProcess, script_path: str):
|
|
312
|
-
msg = f'Failed to run the "{script_path}" script with return code {completed_process.returncode}'
|
|
313
|
-
stdout = completed_process.stdout.decode().strip()
|
|
314
|
-
stderr = completed_process.stderr.decode().strip()
|
|
315
|
-
if stdout != "" or stderr != "":
|
|
316
|
-
msg += ":\n"
|
|
317
|
-
if stdout != "":
|
|
318
|
-
msg += stdout
|
|
319
|
-
if stderr != "":
|
|
320
|
-
msg += stderr
|
|
321
|
-
else:
|
|
322
|
-
msg += "."
|
|
323
|
-
error(msg)
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
def printf(*args):
|
|
327
|
-
print(*args, flush=True)
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if __name__ == "__main__":
|
|
331
|
-
main()
|