zarro 1.141.8 → 1.141.9
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.
|
@@ -1,104 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
.then(() => validateCanRunExe(target));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
validators = {},
|
|
21
|
-
cached = {};
|
|
22
|
-
|
|
23
|
-
function validateCanRunExe(exePath) {
|
|
24
|
-
if (validators[exePath]) {
|
|
25
|
-
return validators[exePath];
|
|
26
|
-
}
|
|
27
|
-
const shouldLog = !validators[exePath];
|
|
28
|
-
if (shouldLog) {
|
|
29
|
-
logger.debug(`validating exe at: ${exePath}`);
|
|
30
|
-
}
|
|
31
|
-
return validators[exePath] = new Promise((resolve, reject) => {
|
|
32
|
-
let lastMessage = "unknown error",
|
|
33
|
-
attempts = 0;
|
|
34
|
-
setTimeout(function testExe() {
|
|
35
|
-
if (cached[exePath]) {
|
|
36
|
-
return resolve(exePath);
|
|
37
|
-
}
|
|
38
|
-
if (attempts === 10) {
|
|
39
|
-
return reject(`Unable to run executable at ${exePath}: ${lastMessage}`);
|
|
40
|
-
}
|
|
41
|
-
attempts++;
|
|
42
|
-
if (shouldLog) {
|
|
43
|
-
logger.debug(`attempt #${attempts} to run ${exePath}`);
|
|
44
|
-
}
|
|
45
|
-
const a = attempts;
|
|
46
|
-
nugetUpdateSelf(exePath).then(() => {
|
|
47
|
-
if (shouldLog) {
|
|
48
|
-
const sub = a > 1 ? ` (${a})` : "";
|
|
49
|
-
logger.info(`nuget.exe appears to be valid!${sub}`);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
(function () {
|
|
4
|
+
const { ZarroError } = requireModule("zarro-error"), HttpClient = requireModule("http-client"), nugetUpdateSelf = requireModule("nuget-update-self"), logger = requireModule("./log"), path = require("path"), url = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe";
|
|
5
|
+
function downloadNugetTo(targetFolder) {
|
|
6
|
+
logger.debug(`Attempting to download nuget.exe to ${targetFolder}`);
|
|
7
|
+
const downloader = HttpClient.create(), target = path.join(targetFolder, "nuget.exe");
|
|
8
|
+
return downloader
|
|
9
|
+
.download(url, path.join(targetFolder, "nuget.exe"))
|
|
10
|
+
.then(() => validateCanRunExe(target));
|
|
11
|
+
}
|
|
12
|
+
const validators = {}, cached = {};
|
|
13
|
+
function validateCanRunExe(exePath) {
|
|
14
|
+
if (!!validators[exePath]) {
|
|
15
|
+
return validators[exePath];
|
|
50
16
|
}
|
|
51
|
-
|
|
52
|
-
return resolve(exePath);
|
|
53
|
-
}).catch(e => {
|
|
54
|
-
lastMessage = e.message || lastMessage;
|
|
17
|
+
const shouldLog = !validators[exePath];
|
|
55
18
|
if (shouldLog) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
attempts
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
19
|
+
logger.debug(`validating exe at: ${exePath}`);
|
|
20
|
+
}
|
|
21
|
+
return validators[exePath] = new Promise((resolve, reject) => {
|
|
22
|
+
let lastMessage = "unknown error", attempts = 0;
|
|
23
|
+
setTimeout(function testExe() {
|
|
24
|
+
if (cached[exePath]) {
|
|
25
|
+
return resolve(exePath);
|
|
26
|
+
}
|
|
27
|
+
if (attempts === 10) {
|
|
28
|
+
return reject(`Unable to run executable at ${exePath}: ${lastMessage}`);
|
|
29
|
+
}
|
|
30
|
+
attempts++;
|
|
31
|
+
if (shouldLog) {
|
|
32
|
+
logger.debug(`attempt #${attempts} to run ${exePath}`);
|
|
33
|
+
}
|
|
34
|
+
const a = attempts;
|
|
35
|
+
nugetUpdateSelf(exePath).then(() => {
|
|
36
|
+
if (shouldLog) {
|
|
37
|
+
const sub = a > 1 ? ` (${a})` : "";
|
|
38
|
+
logger.info(`nuget.exe appears to be valid!${sub}`);
|
|
39
|
+
}
|
|
40
|
+
cached[exePath] = true;
|
|
41
|
+
return resolve(exePath);
|
|
42
|
+
}).catch(e => {
|
|
43
|
+
lastMessage = e.message || lastMessage;
|
|
44
|
+
if (shouldLog) {
|
|
45
|
+
logger.debug(`failed to run executable (${e.message}); ${attempts < 9
|
|
46
|
+
? "will try again"
|
|
47
|
+
: "giving up"}`);
|
|
48
|
+
}
|
|
49
|
+
setTimeout(testExe, 1000);
|
|
50
|
+
});
|
|
51
|
+
}, 1000);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function retry(fn, attempt, maxAttempts, wait) {
|
|
55
|
+
let thisAttempt = attempt !== null && attempt !== void 0 ? attempt : 0;
|
|
56
|
+
const max = maxAttempts !== null && maxAttempts !== void 0 ? maxAttempts : 10;
|
|
57
|
+
let waitMs = wait !== null && wait !== void 0 ? wait : 5000;
|
|
58
|
+
if (waitMs < 1000) {
|
|
59
|
+
waitMs *= 1000;
|
|
63
60
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
setTimeout(() => {
|
|
83
|
-
console.warn(e);
|
|
84
|
-
console.log(`trying again in ${wait / 1000}s (${++attempt} / ${maxAttempts})`);
|
|
85
|
-
retry(fn, attempt, maxAttempts).then(function () {
|
|
86
|
-
resolve(Array.from(arguments));
|
|
87
|
-
}).catch(function () {
|
|
88
|
-
reject(Array.from(arguments));
|
|
89
|
-
});
|
|
90
|
-
}, wait);
|
|
91
|
-
});
|
|
61
|
+
return fn().catch(e => {
|
|
62
|
+
if (thisAttempt >= max) {
|
|
63
|
+
throw new ZarroError(`${e} (giving up after ${attempt} attempts)`);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
console.warn(e);
|
|
69
|
+
console.log(`trying again in ${waitMs / 1000}s (${++thisAttempt} / ${max})`);
|
|
70
|
+
retry(fn, attempt, maxAttempts, wait).then(function () {
|
|
71
|
+
resolve(Array.from(arguments)[0]);
|
|
72
|
+
}).catch(function () {
|
|
73
|
+
reject(Array.from(arguments));
|
|
74
|
+
});
|
|
75
|
+
}, wait);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
92
79
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
console.log(`nuget downloaded to: ${downloaded}`);
|
|
101
|
-
return downloaded;
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
|
|
80
|
+
module.exports = function downloadNuget(targetFolder) {
|
|
81
|
+
return retry(() => downloadNugetTo(targetFolder)).then(downloaded => {
|
|
82
|
+
console.log(`nuget downloaded to: ${downloaded}`);
|
|
83
|
+
return downloaded;
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
})();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
(function () {
|
|
4
|
-
const fs = require("fs"), path = require("path"), { ZarroError } = requireModule("zarro-error"), ensureFolderExists = require("./ensure-folder-exists").sync, request = require("request"), debug = require("debug")("http-
|
|
4
|
+
const fs = require("fs"), path = require("path"), { ZarroError } = requireModule("zarro-error"), ensureFolderExists = require("./ensure-folder-exists").sync, request = require("request"), debug = require("debug")("http-client");
|
|
5
5
|
class HttpClient {
|
|
6
6
|
constructor(infoLogFunction, debugLogFunction) {
|
|
7
7
|
this.aborted = false;
|
|
@@ -1,142 +1,148 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
LogLevels
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
logger
|
|
140
|
-
logger.
|
|
141
|
-
|
|
142
|
-
|
|
1
|
+
(function () {
|
|
2
|
+
// TODO: apply some TS faerie dust
|
|
3
|
+
const gutil = requireModule("gulp-util"),
|
|
4
|
+
DEBUG = 1,
|
|
5
|
+
INFO = 2,
|
|
6
|
+
NOTICE = 3,
|
|
7
|
+
WARNING = 4,
|
|
8
|
+
ERROR = 5,
|
|
9
|
+
levels = {
|
|
10
|
+
DEBUG,
|
|
11
|
+
INFO,
|
|
12
|
+
NOTICE,
|
|
13
|
+
WARNING
|
|
14
|
+
};
|
|
15
|
+
const LogLevels = function () {
|
|
16
|
+
};
|
|
17
|
+
LogLevels.prototype = {
|
|
18
|
+
get Debug() {
|
|
19
|
+
return DEBUG;
|
|
20
|
+
},
|
|
21
|
+
get Info() {
|
|
22
|
+
return INFO;
|
|
23
|
+
},
|
|
24
|
+
get Notice() {
|
|
25
|
+
return NOTICE;
|
|
26
|
+
},
|
|
27
|
+
get Warning() {
|
|
28
|
+
return WARNING;
|
|
29
|
+
},
|
|
30
|
+
get Error() {
|
|
31
|
+
return ERROR;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const Logger = function () {
|
|
35
|
+
this.LogLevels = new LogLevels();
|
|
36
|
+
const logLevel = (process.env.LOG_LEVEL || "").toUpperCase();
|
|
37
|
+
this.setThreshold(levels[logLevel] || INFO);
|
|
38
|
+
this._timestamp = true;
|
|
39
|
+
};
|
|
40
|
+
Logger.prototype = {
|
|
41
|
+
get threshold() {
|
|
42
|
+
return this._threshold;
|
|
43
|
+
},
|
|
44
|
+
setThreshold: function (value) {
|
|
45
|
+
if (levels[value] !== undefined) {
|
|
46
|
+
value = levels[value];
|
|
47
|
+
}
|
|
48
|
+
const intValue = parseInt(value);
|
|
49
|
+
if (isNaN(intValue) || intValue < 1 || intValue > 5) {
|
|
50
|
+
throw value +
|
|
51
|
+
" is not a valid integer value. Try use one of (logger).LogLevels.{Debug|Info|Notice|Warning|Error}";
|
|
52
|
+
}
|
|
53
|
+
this._threshold = intValue;
|
|
54
|
+
},
|
|
55
|
+
debug: function () {
|
|
56
|
+
const message = this._resolve(Array.from(arguments));
|
|
57
|
+
if (this._threshold >= DEBUG) return;
|
|
58
|
+
this._print(message, "grey");
|
|
59
|
+
},
|
|
60
|
+
info: function () {
|
|
61
|
+
const message = this._resolve(Array.from(arguments));
|
|
62
|
+
if (this._threshold >= INFO) return;
|
|
63
|
+
this._print(message, "yellow");
|
|
64
|
+
},
|
|
65
|
+
warning: function () {
|
|
66
|
+
const message = this._resolve(Array.from(arguments));
|
|
67
|
+
if (this._threshold >= WARNING) return;
|
|
68
|
+
this._print(message, "magenta");
|
|
69
|
+
},
|
|
70
|
+
error: function () {
|
|
71
|
+
const message = this._resolve(Array.from(arguments));
|
|
72
|
+
this._print(message, "red", "bold");
|
|
73
|
+
},
|
|
74
|
+
fail: function () {
|
|
75
|
+
const message = this._resolve(Array.from(arguments));
|
|
76
|
+
this.error(message);
|
|
77
|
+
},
|
|
78
|
+
ok: function () {
|
|
79
|
+
const message = this._resolve(Array.from(arguments));
|
|
80
|
+
this._print(message, "green");
|
|
81
|
+
},
|
|
82
|
+
notice: function () {
|
|
83
|
+
const message = this._resolve(Array.from(arguments));
|
|
84
|
+
if (this._threshold > NOTICE) return;
|
|
85
|
+
this._print(message, "cyan");
|
|
86
|
+
},
|
|
87
|
+
suppressTimeStamps: function () {
|
|
88
|
+
this._timestamp = false;
|
|
89
|
+
},
|
|
90
|
+
showTimeStamps: function () {
|
|
91
|
+
this._timestamp = true;
|
|
92
|
+
},
|
|
93
|
+
_resolve: function (args) {
|
|
94
|
+
return args
|
|
95
|
+
.map(a => {
|
|
96
|
+
if (a === undefined) {
|
|
97
|
+
return "(undefined)";
|
|
98
|
+
}
|
|
99
|
+
if (a === null) {
|
|
100
|
+
return "(null)";
|
|
101
|
+
}
|
|
102
|
+
if (Array.isArray(a)) {
|
|
103
|
+
return a.join(",");
|
|
104
|
+
}
|
|
105
|
+
if (typeof a === "object") {
|
|
106
|
+
return JSON.stringify(a);
|
|
107
|
+
}
|
|
108
|
+
return a.toString();
|
|
109
|
+
})
|
|
110
|
+
.join(" ");
|
|
111
|
+
},
|
|
112
|
+
_print: function () {
|
|
113
|
+
const message = arguments[0];
|
|
114
|
+
const styles = [];
|
|
115
|
+
for (let i = 1; i < arguments.length; i++) {
|
|
116
|
+
styles.push(arguments[i]); // because arguments is an object, not an array...
|
|
117
|
+
}
|
|
118
|
+
const styleFunction = styles.reduce(
|
|
119
|
+
function (acc, cur) {
|
|
120
|
+
const fn = gutil.colors[cur];
|
|
121
|
+
if (fn === undefined) {
|
|
122
|
+
return acc;
|
|
123
|
+
}
|
|
124
|
+
return function (s) {
|
|
125
|
+
return fn(acc(s));
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
function (s) {
|
|
129
|
+
return s;
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
if (this._timestamp) {
|
|
133
|
+
gutil.log(styleFunction(message));
|
|
134
|
+
} else {
|
|
135
|
+
console.log(styleFunction(message));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const logger = new Logger();
|
|
140
|
+
if (logger.threshold === DEBUG) {
|
|
141
|
+
logger.debug(" -- testing logger outputs -- ");
|
|
142
|
+
logger.debug("debug message");
|
|
143
|
+
logger.info("info message");
|
|
144
|
+
logger.warning("warning message");
|
|
145
|
+
logger.error("error message");
|
|
146
|
+
}
|
|
147
|
+
module.exports = logger;
|
|
148
|
+
})();
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
(function () {
|
|
3
|
+
const spawn = requireModule("spawn");
|
|
4
|
+
let updating;
|
|
5
|
+
module.exports = function (nugetPath) {
|
|
6
|
+
if (updating) {
|
|
7
|
+
return updating;
|
|
8
|
+
}
|
|
9
|
+
return updating = new Promise(async (resolve, reject) => {
|
|
10
|
+
try {
|
|
11
|
+
await spawn(nugetPath, ["update", "-self"]);
|
|
12
|
+
updating = undefined;
|
|
13
|
+
resolve();
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
updating = undefined;
|
|
17
|
+
reject(e);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
})();
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -19,6 +19,41 @@ interface Logger {
|
|
|
19
19
|
warn(...args: any[]): Logger;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
interface LogLevels {
|
|
23
|
+
Debug: string;
|
|
24
|
+
Info: string;
|
|
25
|
+
Notice: string;
|
|
26
|
+
Warning: string;
|
|
27
|
+
Error: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare enum LogThreshold {
|
|
31
|
+
debug = 1,
|
|
32
|
+
info = 2,
|
|
33
|
+
notice = 3,
|
|
34
|
+
warning = 4,
|
|
35
|
+
error = 5
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface ZarroLogger {
|
|
39
|
+
LogLevels: LogLevels;
|
|
40
|
+
threshold: LogThreshold;
|
|
41
|
+
|
|
42
|
+
setThreshold(threshold: number | string): void;
|
|
43
|
+
debug(...args: any[]): void;
|
|
44
|
+
info(...args: any[]): void;
|
|
45
|
+
notice(...args: any[]): void;
|
|
46
|
+
warning(...args: any[]): void;
|
|
47
|
+
error(...args: any[]): void;
|
|
48
|
+
|
|
49
|
+
fail(...args: any[]): void;
|
|
50
|
+
ok(...args: any[]): void;
|
|
51
|
+
notice(...args: any[]): void;
|
|
52
|
+
suppressTimestamps(): void;
|
|
53
|
+
showTimestamps(): void;
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
22
57
|
declare global {
|
|
23
58
|
function requireModule<T>(module: string): T;
|
|
24
59
|
|
|
@@ -490,6 +525,8 @@ declare global {
|
|
|
490
525
|
|
|
491
526
|
type FailAfter = (ms: number, message?: string) => Failer;
|
|
492
527
|
|
|
528
|
+
type NugetUpdateSelf = (nugetPath: string) => Promise<void>;
|
|
529
|
+
|
|
493
530
|
export interface FileSystemUtils {
|
|
494
531
|
folderExists(at: string): Promise<boolean>;
|
|
495
532
|
fileExists(at: string): Promise<boolean>;
|