@datatruck/cli 0.30.1 → 0.32.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/Action/BackupAction.js +4 -8
- package/Action/ConfigAction.d.ts +1 -0
- package/Action/ConfigAction.js +8 -7
- package/Action/CopyAction.js +1 -1
- package/Action/RestoreAction.js +1 -1
- package/CHANGELOG.md +22 -0
- package/Command/BackupCommand.d.ts +1 -1
- package/Command/CleanCacheCommand.d.ts +1 -1
- package/Command/CommandAbstract.d.ts +2 -1
- package/Command/CommandAbstract.js +3 -1
- package/Command/CopyCommand.d.ts +1 -1
- package/Command/RestoreCommand.d.ts +1 -1
- package/Command/StartServerCommand.js +31 -8
- package/Config/Config.d.ts +7 -1
- package/Config/Config.js +79 -26
- package/Config/RepositoryConfig.d.ts +1 -0
- package/Config/RepositoryConfig.js +6 -1
- package/Factory/CommandFactory.d.ts +1 -1
- package/Factory/CommandFactory.js +2 -2
- package/JsonSchema/backup-def.d.ts +30 -0
- package/JsonSchema/backup-def.js +18 -0
- package/JsonSchema/copy-def.d.ts +24 -0
- package/JsonSchema/copy-def.js +15 -0
- package/Task/ScriptTask.d.ts +2 -11
- package/Task/ScriptTask.js +27 -33
- package/cli.js +1 -1
- package/config.schema.json +227 -40
- package/package.json +5 -4
- package/pkg.d.ts +6 -0
- package/pkg.js +10 -0
- package/utils/cli.d.ts +4 -1
- package/utils/cli.js +23 -3
- package/utils/datatruck/client.js +3 -3
- package/utils/datatruck/cron-server.d.ts +23 -0
- package/utils/datatruck/cron-server.js +59 -0
- package/utils/datatruck/paths.js +4 -6
- package/utils/datatruck/{server.d.ts → repository-server.d.ts} +12 -5
- package/utils/datatruck/{server.js → repository-server.js} +48 -26
- package/utils/fs.js +19 -18
- package/utils/http.d.ts +8 -2
- package/utils/http.js +12 -14
- package/utils/object.d.ts +1 -1
- package/utils/object.js +6 -6
- package/utils/schema.d.ts +34 -0
- package/utils/schema.js +36 -0
- package/utils/steps.d.ts +10 -10
- package/utils/steps.js +22 -8
- package/utils/string.d.ts +0 -3
- package/utils/string.js +22 -42
- package/utils/ObjectVault.d.ts +0 -13
- package/utils/ObjectVault.js +0 -29
package/Task/ScriptTask.js
CHANGED
|
@@ -15,11 +15,13 @@ var ScriptTaskDefinitionEnum;
|
|
|
15
15
|
ScriptTaskDefinitionEnum["processStepConfig"] = "processStepConfig";
|
|
16
16
|
ScriptTaskDefinitionEnum["nodeStepConfig"] = "nodeStepConfig";
|
|
17
17
|
ScriptTaskDefinitionEnum["telegramMessageStepConfig"] = "telegramMessageStepConfig";
|
|
18
|
+
ScriptTaskDefinitionEnum["ntfyStepConfig"] = "ntfyStepConfig";
|
|
18
19
|
})(ScriptTaskDefinitionEnum || (exports.ScriptTaskDefinitionEnum = ScriptTaskDefinitionEnum = {}));
|
|
19
20
|
const stepTypes = {
|
|
20
21
|
process: ScriptTaskDefinitionEnum.processStepConfig,
|
|
21
22
|
node: ScriptTaskDefinitionEnum.nodeStepConfig,
|
|
22
23
|
"telegram-message": ScriptTaskDefinitionEnum.telegramMessageStepConfig,
|
|
24
|
+
ntfy: ScriptTaskDefinitionEnum.ntfyStepConfig,
|
|
23
25
|
};
|
|
24
26
|
exports.scriptTaskName = "script";
|
|
25
27
|
exports.scriptTaskDefinition = {
|
|
@@ -85,6 +87,15 @@ exports.scriptTaskDefinition = {
|
|
|
85
87
|
text: { type: "string" },
|
|
86
88
|
},
|
|
87
89
|
},
|
|
90
|
+
ntfyStepConfig: {
|
|
91
|
+
type: "object",
|
|
92
|
+
required: ["token"],
|
|
93
|
+
properties: {
|
|
94
|
+
token: { type: "string" },
|
|
95
|
+
topic: { type: "string" },
|
|
96
|
+
text: { type: "string" },
|
|
97
|
+
},
|
|
98
|
+
},
|
|
88
99
|
},
|
|
89
100
|
type: "object",
|
|
90
101
|
additionalProperties: false,
|
|
@@ -108,41 +119,22 @@ exports.scriptTaskDefinition = {
|
|
|
108
119
|
};
|
|
109
120
|
class ScriptTask extends TaskAbstract_1.TaskAbstract {
|
|
110
121
|
verbose;
|
|
111
|
-
getVars(data) {
|
|
112
|
-
return {
|
|
113
|
-
process: {
|
|
114
|
-
DTT_SNAPSHOT_ID: data.snapshot.id,
|
|
115
|
-
DTT_SNAPSHOT_DATE: data.snapshot.date,
|
|
116
|
-
DTT_PACKAGE_NAME: data.package.name,
|
|
117
|
-
DTT_PACKAGE_PATH: data.package.path,
|
|
118
|
-
DTT_SNAPSHOT_PATH: data.snapshotPath,
|
|
119
|
-
},
|
|
120
|
-
node: {
|
|
121
|
-
dtt: {
|
|
122
|
-
snapshot: data.snapshot,
|
|
123
|
-
package: data.package,
|
|
124
|
-
snapshotPath: data.snapshotPath,
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
122
|
async backup(data) {
|
|
130
123
|
const config = this.config;
|
|
131
124
|
const snapshotPath = data.package.path ??
|
|
132
125
|
(await (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "backup", "snapshot"));
|
|
133
|
-
const vars = this.getVars({
|
|
134
|
-
...data,
|
|
135
|
-
snapshotPath,
|
|
136
|
-
});
|
|
137
126
|
await (0, steps_1.runSteps)(config.backupSteps, {
|
|
138
127
|
env: config.env,
|
|
128
|
+
vars: {
|
|
129
|
+
dtt: {
|
|
130
|
+
snapshot: data.snapshot,
|
|
131
|
+
snapshotPath: snapshotPath,
|
|
132
|
+
package: data.package,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
139
135
|
cwd: snapshotPath,
|
|
140
136
|
verbose: data.options.verbose,
|
|
141
|
-
|
|
142
|
-
node: {
|
|
143
|
-
tempDir: () => (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "backup", "nodeStep"),
|
|
144
|
-
vars: vars.node,
|
|
145
|
-
},
|
|
137
|
+
tempDir: () => (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "backup", "nodeStep"),
|
|
146
138
|
});
|
|
147
139
|
return { snapshotPath };
|
|
148
140
|
}
|
|
@@ -154,15 +146,17 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
|
|
|
154
146
|
}
|
|
155
147
|
async restore(data) {
|
|
156
148
|
const config = this.config;
|
|
157
|
-
const vars = this.getVars(data);
|
|
158
149
|
await (0, steps_1.runSteps)(config.restoreSteps, {
|
|
159
150
|
env: config.env,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
151
|
+
vars: {
|
|
152
|
+
dtt: {
|
|
153
|
+
snapshot: data.snapshot,
|
|
154
|
+
snapshotPath: data.snapshotPath,
|
|
155
|
+
package: data.package,
|
|
156
|
+
},
|
|
165
157
|
},
|
|
158
|
+
verbose: data.options.verbose,
|
|
159
|
+
tempDir: () => (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "restore", "nodeStep"),
|
|
166
160
|
});
|
|
167
161
|
}
|
|
168
162
|
}
|
package/cli.js
CHANGED
|
@@ -59,7 +59,7 @@ function makeCommandAction(command) {
|
|
|
59
59
|
exitCode = await (0, CommandFactory_1.CommandFactory)(command, {
|
|
60
60
|
...globalOptions,
|
|
61
61
|
config: config.data,
|
|
62
|
-
}, options).onExec();
|
|
62
|
+
}, options, {}, globalOptions.config).onExec();
|
|
63
63
|
}
|
|
64
64
|
catch (e) {
|
|
65
65
|
const error = e;
|
package/config.schema.json
CHANGED
|
@@ -1048,67 +1048,217 @@
|
|
|
1048
1048
|
"type": "object",
|
|
1049
1049
|
"additionalProperties": false,
|
|
1050
1050
|
"properties": {
|
|
1051
|
-
"path": {
|
|
1052
|
-
"type": "string"
|
|
1053
|
-
},
|
|
1054
1051
|
"log": {
|
|
1055
1052
|
"type": "boolean"
|
|
1056
1053
|
},
|
|
1057
|
-
"
|
|
1058
|
-
"type": "array",
|
|
1059
|
-
"items": {
|
|
1060
|
-
"type": "object",
|
|
1061
|
-
"additionalProperties": false,
|
|
1062
|
-
"properties": {
|
|
1063
|
-
"name": {
|
|
1064
|
-
"type": "string"
|
|
1065
|
-
},
|
|
1066
|
-
"password": {
|
|
1067
|
-
"type": "string"
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
},
|
|
1072
|
-
"listen": {
|
|
1054
|
+
"repository": {
|
|
1073
1055
|
"type": "object",
|
|
1074
1056
|
"additionalProperties": false,
|
|
1075
1057
|
"properties": {
|
|
1076
|
-
"
|
|
1077
|
-
"type": "integer"
|
|
1078
|
-
},
|
|
1079
|
-
"address": {
|
|
1080
|
-
"type": "string"
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
},
|
|
1084
|
-
"trustProxy": {
|
|
1085
|
-
"anyOf": [
|
|
1086
|
-
{
|
|
1058
|
+
"enabled": {
|
|
1087
1059
|
"type": "boolean"
|
|
1088
1060
|
},
|
|
1089
|
-
{
|
|
1061
|
+
"listen": {
|
|
1090
1062
|
"type": "object",
|
|
1091
1063
|
"additionalProperties": false,
|
|
1092
|
-
"required": [
|
|
1093
|
-
"remoteAddressHeader"
|
|
1094
|
-
],
|
|
1095
1064
|
"properties": {
|
|
1096
|
-
"
|
|
1065
|
+
"port": {
|
|
1066
|
+
"type": "integer"
|
|
1067
|
+
},
|
|
1068
|
+
"address": {
|
|
1097
1069
|
"type": "string"
|
|
1098
1070
|
}
|
|
1099
1071
|
}
|
|
1072
|
+
},
|
|
1073
|
+
"trustProxy": {
|
|
1074
|
+
"anyOf": [
|
|
1075
|
+
{
|
|
1076
|
+
"type": "boolean"
|
|
1077
|
+
},
|
|
1078
|
+
{
|
|
1079
|
+
"type": "object",
|
|
1080
|
+
"additionalProperties": false,
|
|
1081
|
+
"required": [
|
|
1082
|
+
"remoteAddressHeader"
|
|
1083
|
+
],
|
|
1084
|
+
"properties": {
|
|
1085
|
+
"remoteAddressHeader": {
|
|
1086
|
+
"type": "string"
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
]
|
|
1091
|
+
},
|
|
1092
|
+
"allowlist": {
|
|
1093
|
+
"type": "object",
|
|
1094
|
+
"additionalProperties": false,
|
|
1095
|
+
"properties": {
|
|
1096
|
+
"enabled": {
|
|
1097
|
+
"type": "boolean"
|
|
1098
|
+
},
|
|
1099
|
+
"remoteAddresses": {
|
|
1100
|
+
"$ref": "#/definitions/stringlist-util"
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
},
|
|
1104
|
+
"backends": {
|
|
1105
|
+
"type": "array",
|
|
1106
|
+
"items": {
|
|
1107
|
+
"type": "object",
|
|
1108
|
+
"additionalProperties": false,
|
|
1109
|
+
"required": [
|
|
1110
|
+
"name",
|
|
1111
|
+
"path"
|
|
1112
|
+
],
|
|
1113
|
+
"properties": {
|
|
1114
|
+
"name": {
|
|
1115
|
+
"type": "string"
|
|
1116
|
+
},
|
|
1117
|
+
"path": {
|
|
1118
|
+
"type": "string"
|
|
1119
|
+
},
|
|
1120
|
+
"users": {
|
|
1121
|
+
"type": "array",
|
|
1122
|
+
"items": {
|
|
1123
|
+
"type": "object",
|
|
1124
|
+
"additionalProperties": false,
|
|
1125
|
+
"required": [
|
|
1126
|
+
"name",
|
|
1127
|
+
"password"
|
|
1128
|
+
],
|
|
1129
|
+
"properties": {
|
|
1130
|
+
"enabled": {
|
|
1131
|
+
"type": "boolean"
|
|
1132
|
+
},
|
|
1133
|
+
"name": {
|
|
1134
|
+
"type": "string"
|
|
1135
|
+
},
|
|
1136
|
+
"password": {
|
|
1137
|
+
"type": "string"
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1100
1144
|
}
|
|
1101
|
-
|
|
1145
|
+
}
|
|
1102
1146
|
},
|
|
1103
|
-
"
|
|
1147
|
+
"cron": {
|
|
1104
1148
|
"type": "object",
|
|
1105
1149
|
"additionalProperties": false,
|
|
1106
1150
|
"properties": {
|
|
1107
1151
|
"enabled": {
|
|
1108
1152
|
"type": "boolean"
|
|
1109
1153
|
},
|
|
1110
|
-
"
|
|
1111
|
-
"
|
|
1154
|
+
"actions": {
|
|
1155
|
+
"type": "array",
|
|
1156
|
+
"items": {
|
|
1157
|
+
"allOf": [
|
|
1158
|
+
{
|
|
1159
|
+
"type": "object",
|
|
1160
|
+
"required": [
|
|
1161
|
+
"schedule"
|
|
1162
|
+
],
|
|
1163
|
+
"properties": {
|
|
1164
|
+
"schedule": {
|
|
1165
|
+
"type": "string"
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
},
|
|
1169
|
+
{
|
|
1170
|
+
"anyOf": [
|
|
1171
|
+
{
|
|
1172
|
+
"if": {
|
|
1173
|
+
"type": "object",
|
|
1174
|
+
"properties": {
|
|
1175
|
+
"type": {
|
|
1176
|
+
"const": "backup"
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
},
|
|
1180
|
+
"then": {
|
|
1181
|
+
"type": "object",
|
|
1182
|
+
"properties": {
|
|
1183
|
+
"options": {
|
|
1184
|
+
"type": "object",
|
|
1185
|
+
"additionalProperties": false,
|
|
1186
|
+
"properties": {
|
|
1187
|
+
"package": {
|
|
1188
|
+
"type": "string"
|
|
1189
|
+
},
|
|
1190
|
+
"packageTask": {
|
|
1191
|
+
"type": "string"
|
|
1192
|
+
},
|
|
1193
|
+
"repository": {
|
|
1194
|
+
"type": "string"
|
|
1195
|
+
},
|
|
1196
|
+
"repositoryType": {
|
|
1197
|
+
"enum": [
|
|
1198
|
+
"restic",
|
|
1199
|
+
"datatruck",
|
|
1200
|
+
"git"
|
|
1201
|
+
]
|
|
1202
|
+
},
|
|
1203
|
+
"tag": {
|
|
1204
|
+
"type": "string"
|
|
1205
|
+
},
|
|
1206
|
+
"date": {
|
|
1207
|
+
"type": "string"
|
|
1208
|
+
},
|
|
1209
|
+
"prune": {
|
|
1210
|
+
"type": "boolean"
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
},
|
|
1216
|
+
"else": false
|
|
1217
|
+
},
|
|
1218
|
+
{
|
|
1219
|
+
"if": {
|
|
1220
|
+
"type": "object",
|
|
1221
|
+
"properties": {
|
|
1222
|
+
"type": {
|
|
1223
|
+
"const": "copy"
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
},
|
|
1227
|
+
"then": {
|
|
1228
|
+
"type": "object",
|
|
1229
|
+
"properties": {
|
|
1230
|
+
"options": {
|
|
1231
|
+
"type": "object",
|
|
1232
|
+
"additionalProperties": false,
|
|
1233
|
+
"properties": {
|
|
1234
|
+
"id": {
|
|
1235
|
+
"type": "string"
|
|
1236
|
+
},
|
|
1237
|
+
"last": {
|
|
1238
|
+
"type": "integer"
|
|
1239
|
+
},
|
|
1240
|
+
"package": {
|
|
1241
|
+
"type": "string"
|
|
1242
|
+
},
|
|
1243
|
+
"packageTask": {
|
|
1244
|
+
"type": "string"
|
|
1245
|
+
},
|
|
1246
|
+
"repository": {
|
|
1247
|
+
"type": "string"
|
|
1248
|
+
},
|
|
1249
|
+
"repository2": {
|
|
1250
|
+
"type": "string"
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
},
|
|
1256
|
+
"else": false
|
|
1257
|
+
}
|
|
1258
|
+
]
|
|
1259
|
+
}
|
|
1260
|
+
]
|
|
1261
|
+
}
|
|
1112
1262
|
}
|
|
1113
1263
|
}
|
|
1114
1264
|
}
|
|
@@ -1196,7 +1346,8 @@
|
|
|
1196
1346
|
"enum": [
|
|
1197
1347
|
"process",
|
|
1198
1348
|
"node",
|
|
1199
|
-
"telegram-message"
|
|
1349
|
+
"telegram-message",
|
|
1350
|
+
"ntfy"
|
|
1200
1351
|
]
|
|
1201
1352
|
},
|
|
1202
1353
|
"config": {}
|
|
@@ -1258,6 +1409,25 @@
|
|
|
1258
1409
|
}
|
|
1259
1410
|
},
|
|
1260
1411
|
"else": false
|
|
1412
|
+
},
|
|
1413
|
+
{
|
|
1414
|
+
"if": {
|
|
1415
|
+
"type": "object",
|
|
1416
|
+
"properties": {
|
|
1417
|
+
"type": {
|
|
1418
|
+
"const": "ntfy"
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
},
|
|
1422
|
+
"then": {
|
|
1423
|
+
"type": "object",
|
|
1424
|
+
"properties": {
|
|
1425
|
+
"config": {
|
|
1426
|
+
"$ref": "#/definitions/script-task_ntfyStepConfig"
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
},
|
|
1430
|
+
"else": false
|
|
1261
1431
|
}
|
|
1262
1432
|
]
|
|
1263
1433
|
},
|
|
@@ -1332,6 +1502,23 @@
|
|
|
1332
1502
|
"type": "string"
|
|
1333
1503
|
}
|
|
1334
1504
|
}
|
|
1505
|
+
},
|
|
1506
|
+
"script-task_ntfyStepConfig": {
|
|
1507
|
+
"type": "object",
|
|
1508
|
+
"required": [
|
|
1509
|
+
"token"
|
|
1510
|
+
],
|
|
1511
|
+
"properties": {
|
|
1512
|
+
"token": {
|
|
1513
|
+
"type": "string"
|
|
1514
|
+
},
|
|
1515
|
+
"topic": {
|
|
1516
|
+
"type": "string"
|
|
1517
|
+
},
|
|
1518
|
+
"text": {
|
|
1519
|
+
"type": "string"
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1335
1522
|
}
|
|
1336
1523
|
},
|
|
1337
1524
|
"$ref": "#/definitions/config"
|
package/package.json
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datatruck/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@supercharge/promise-pool": "^3.1.0",
|
|
6
6
|
"ajv": "^8.12.0",
|
|
7
7
|
"async": "^3.2.4",
|
|
8
8
|
"chalk": "^4.1.2",
|
|
9
9
|
"commander": "^11.0.0",
|
|
10
|
+
"croner": "^7.0.4",
|
|
10
11
|
"dayjs": "^1.11.10",
|
|
11
12
|
"fast-folder-size": "^2.2.0",
|
|
12
13
|
"fast-glob": "^3.3.1",
|
|
13
14
|
"listr2": "^7.0.1",
|
|
14
15
|
"micromatch": "^4.0.5",
|
|
15
16
|
"mysql2": "^3.6.1",
|
|
16
|
-
"tty-table": "^4.2.2"
|
|
17
|
+
"tty-table": "^4.2.2",
|
|
18
|
+
"yaml": "^2.3.2"
|
|
17
19
|
},
|
|
18
20
|
"optionalDependencies": {
|
|
19
|
-
"ts-node": "^10.9.1"
|
|
20
|
-
"yaml": "^2.3.2"
|
|
21
|
+
"ts-node": "^10.9.1"
|
|
21
22
|
},
|
|
22
23
|
"engine": {
|
|
23
24
|
"node": ">=16.0.0"
|
package/pkg.d.ts
ADDED
package/pkg.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pkg = void 0;
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const package_json_1 = __importDefault(require("./../package.json"));
|
|
9
|
+
const pkg = package_json_1.default;
|
|
10
|
+
exports.pkg = pkg;
|
package/utils/cli.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare function renderProgressBar(progress: number, size?: number, subpr
|
|
|
4
4
|
export declare function logExec(command: string, argv?: string[], env?: NodeJS.ProcessEnv, logToStderr?: boolean): void;
|
|
5
5
|
export declare function renderResult(error: Error | null | string | boolean | undefined, color?: boolean): string;
|
|
6
6
|
export declare function renderError(error: Error | null | string | undefined, verbose?: number): string;
|
|
7
|
-
export declare function renderObject(object: Record<string, any
|
|
7
|
+
export declare function renderObject(object: Record<string, any>, color?: boolean): string;
|
|
8
8
|
export type OptionsType<T1, T2 extends {
|
|
9
9
|
[K in keyof T1]: unknown;
|
|
10
10
|
}> = {
|
|
@@ -19,4 +19,7 @@ export type OptionsType<T1, T2 extends {
|
|
|
19
19
|
export declare function parseOptions<T1, T2 extends {
|
|
20
20
|
[K in keyof T1]: unknown;
|
|
21
21
|
}>(object: T1, options: OptionsType<T1, T2>): T2;
|
|
22
|
+
export declare function stringifyOptions<T1, T2 extends {
|
|
23
|
+
[K in keyof T1]: unknown;
|
|
24
|
+
}>(options: OptionsType<T1, T2>, object: any): string[];
|
|
22
25
|
export declare function confirm(message: string): Promise<unknown>;
|
package/utils/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
-
exports.confirm = exports.parseOptions = exports.renderObject = exports.renderError = exports.renderResult = exports.logExec = exports.renderProgressBar = exports.showCursorCommand = void 0;
|
|
6
|
+
exports.confirm = exports.stringifyOptions = exports.parseOptions = exports.renderObject = exports.renderError = exports.renderResult = exports.logExec = exports.renderProgressBar = exports.showCursorCommand = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const chalk_2 = require("chalk");
|
|
9
9
|
const readline_1 = require("readline");
|
|
@@ -75,10 +75,10 @@ function renderError(error, verbose) {
|
|
|
75
75
|
return chalk_1.default.red(message.trim());
|
|
76
76
|
}
|
|
77
77
|
exports.renderError = renderError;
|
|
78
|
-
function renderObject(object) {
|
|
78
|
+
function renderObject(object, color) {
|
|
79
79
|
const values = [];
|
|
80
80
|
for (const key in object)
|
|
81
|
-
values.push(`${key}: ${(0, chalk_2.grey)(object[key])}`);
|
|
81
|
+
values.push(`${key}: ${color ? (0, chalk_2.grey)(object[key]) : object[key]}`);
|
|
82
82
|
return values.join(` `);
|
|
83
83
|
}
|
|
84
84
|
exports.renderObject = renderObject;
|
|
@@ -96,6 +96,26 @@ function parseOptions(object, options) {
|
|
|
96
96
|
return result;
|
|
97
97
|
}
|
|
98
98
|
exports.parseOptions = parseOptions;
|
|
99
|
+
function stringifyOptions(options, object) {
|
|
100
|
+
const result = [];
|
|
101
|
+
for (const key in options) {
|
|
102
|
+
const fullOpt = options[key].option;
|
|
103
|
+
const [opt] = fullOpt.split(",");
|
|
104
|
+
const isNegative = fullOpt.startsWith("--no");
|
|
105
|
+
const isBool = !fullOpt.includes("<") && !fullOpt.includes("[");
|
|
106
|
+
const defaultsValue = isNegative ? true : options[key].defaults;
|
|
107
|
+
const value = object?.[key] ?? defaultsValue;
|
|
108
|
+
if (isBool) {
|
|
109
|
+
if (object[key])
|
|
110
|
+
result.push(opt);
|
|
111
|
+
}
|
|
112
|
+
else if (value !== undefined) {
|
|
113
|
+
result.push(opt, `${value}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
exports.stringifyOptions = stringifyOptions;
|
|
99
119
|
function confirm(message) {
|
|
100
120
|
const rl = (0, readline_1.createInterface)({
|
|
101
121
|
input: process.stdin,
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createFs = exports.isRemoteBackend = exports.RemoteFs = void 0;
|
|
4
4
|
const http_1 = require("../http");
|
|
5
5
|
const virtual_fs_1 = require("../virtual-fs");
|
|
6
|
-
const
|
|
6
|
+
const repository_server_1 = require("./repository-server");
|
|
7
7
|
class RemoteFs extends virtual_fs_1.AbstractFs {
|
|
8
8
|
options;
|
|
9
9
|
url;
|
|
@@ -13,8 +13,8 @@ class RemoteFs extends virtual_fs_1.AbstractFs {
|
|
|
13
13
|
this.options = options;
|
|
14
14
|
const url = new URL(options.backend);
|
|
15
15
|
this.headers = {
|
|
16
|
-
[
|
|
17
|
-
[
|
|
16
|
+
[repository_server_1.headerKey.user]: url.username,
|
|
17
|
+
[repository_server_1.headerKey.password]: url.password,
|
|
18
18
|
};
|
|
19
19
|
url.username = "";
|
|
20
20
|
url.password = "";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BackupCommandOptions } from "../../Command/BackupCommand";
|
|
2
|
+
import { CopyCommandOptionsType } from "../../Command/CopyCommand";
|
|
3
|
+
export type CronAction = {
|
|
4
|
+
schedule: string;
|
|
5
|
+
name: "backup";
|
|
6
|
+
options: BackupCommandOptions;
|
|
7
|
+
} | {
|
|
8
|
+
schedule: string;
|
|
9
|
+
name: "copy";
|
|
10
|
+
options: CopyCommandOptionsType;
|
|
11
|
+
};
|
|
12
|
+
export type DatatruckCronServerOptions = {
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
actions?: CronAction[];
|
|
15
|
+
};
|
|
16
|
+
export declare function createCronServer(options: DatatruckCronServerOptions, config: {
|
|
17
|
+
log: boolean;
|
|
18
|
+
verbose: boolean;
|
|
19
|
+
configPath: string;
|
|
20
|
+
}): {
|
|
21
|
+
start: () => void;
|
|
22
|
+
stop: () => void;
|
|
23
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCronServer = void 0;
|
|
4
|
+
const CommandFactory_1 = require("../../Factory/CommandFactory");
|
|
5
|
+
const cli_1 = require("../cli");
|
|
6
|
+
const process_1 = require("../process");
|
|
7
|
+
const croner_1 = require("croner");
|
|
8
|
+
function createJobs(actions, currentJobs = [], worker) {
|
|
9
|
+
const jobs = [];
|
|
10
|
+
for (const action of actions) {
|
|
11
|
+
const index = actions.indexOf(action);
|
|
12
|
+
const context = JSON.stringify({
|
|
13
|
+
index: actions.indexOf(action),
|
|
14
|
+
data: action,
|
|
15
|
+
});
|
|
16
|
+
const job = currentJobs.at(index);
|
|
17
|
+
if (!job || job.options.context !== context) {
|
|
18
|
+
job?.stop();
|
|
19
|
+
jobs.push((0, croner_1.Cron)(action.schedule, {
|
|
20
|
+
paused: true,
|
|
21
|
+
context: JSON.stringify(action),
|
|
22
|
+
catch: true,
|
|
23
|
+
protect: true,
|
|
24
|
+
}, () => worker(action, index)));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return jobs;
|
|
28
|
+
}
|
|
29
|
+
function createCronServer(options, config) {
|
|
30
|
+
const worker = async (action, index) => {
|
|
31
|
+
if (config.log)
|
|
32
|
+
console.info(`> [job] ${index} - ${action.name}`);
|
|
33
|
+
try {
|
|
34
|
+
const Command = (0, CommandFactory_1.CommandConstructorFactory)(action.name);
|
|
35
|
+
const command = new Command({ config: { packages: [], repositories: [] } }, {});
|
|
36
|
+
const cliOptions = (0, cli_1.stringifyOptions)(command.onOptions(), action.options);
|
|
37
|
+
const [node, bin] = process.argv;
|
|
38
|
+
await (0, process_1.exec)(node, [bin, "-c", config.configPath, action.name, ...cliOptions], {}, { log: config.verbose });
|
|
39
|
+
if (config.log)
|
|
40
|
+
console.info(`< [job] ${index} - ${action.name}`);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (config.log)
|
|
44
|
+
console.error(`< [job] ${index} - ${action.name}`, error);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const jobs = createJobs(options.actions || [], [], worker);
|
|
48
|
+
return {
|
|
49
|
+
start: () => {
|
|
50
|
+
for (const job of jobs)
|
|
51
|
+
job.resume();
|
|
52
|
+
},
|
|
53
|
+
stop: () => {
|
|
54
|
+
for (const job of jobs)
|
|
55
|
+
job.stop();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
exports.createCronServer = createCronServer;
|
package/utils/datatruck/paths.js
CHANGED
|
@@ -10,7 +10,7 @@ async function parsePaths(values, options) {
|
|
|
10
10
|
}
|
|
11
11
|
else {
|
|
12
12
|
await (0, steps_1.runSteps)(value, {
|
|
13
|
-
|
|
13
|
+
tempDir: options.tempDir,
|
|
14
14
|
verbose: options.verbose,
|
|
15
15
|
onLine: (path) => paths.push(path),
|
|
16
16
|
});
|
|
@@ -24,11 +24,9 @@ async function parseBackupPaths(paths, options) {
|
|
|
24
24
|
cwd: options.path,
|
|
25
25
|
verbose: options.verbose,
|
|
26
26
|
vars: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
path: options.path,
|
|
31
|
-
},
|
|
27
|
+
package: options.package,
|
|
28
|
+
snapshot: options.snapshot,
|
|
29
|
+
path: options.path,
|
|
32
30
|
},
|
|
33
31
|
});
|
|
34
32
|
}
|