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
- const
2
- { ZarroError } = requireModule("zarro-error"),
3
- HttpDownloader = require("./http-downloader"),
4
- nugetUpdateSelf = require("./nuget-update-self"),
5
- logger = require("./log"),
6
- path = require("path"),
7
- url = 'http://dist.nuget.org/win-x86-commandline/latest/nuget.exe';
8
-
9
- function downloadNugetTo(targetFolder) {
10
- logger.debug(`Attempting to download nuget.exe to ${targetFolder}`);
11
- const
12
- downloader = new HttpDownloader(),
13
- target = path.join(targetFolder, "nuget.exe");
14
- return downloader
15
- .download(url, path.join(targetFolder, "nuget.exe"))
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
- cached[exePath] = true;
52
- return resolve(exePath);
53
- }).catch(e => {
54
- lastMessage = e.message || lastMessage;
17
+ const shouldLog = !validators[exePath];
55
18
  if (shouldLog) {
56
- logger.debug(`failed to run executable (${
57
- e.message
58
- }); ${
59
- attempts < 9
60
- ? "will try again"
61
- : "giving up"
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
- setTimeout(testExe, 1000);
65
- });
66
- }, 1000);
67
- });
68
- }
69
-
70
- function retry(fn, attempt, maxAttempts, wait) {
71
- attempt = attempt || 0;
72
- maxAttempts = maxAttempts || 10;
73
- wait = wait || 5000;
74
- if (wait < 1000) {
75
- wait *= 1000;
76
- }
77
- return fn().catch(e => {
78
- if (attempt >= maxAttempts) {
79
- throw new ZarroError(`${e} (giving up after ${attempt} attempts)`);
80
- } else {
81
- return new Promise((resolve, reject) => {
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
- module.exports = function downloadNuget(targetFolder) {
97
- return retry(() =>
98
- downloadNugetTo(targetFolder)
99
- ).then(downloaded => {
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-downloader");
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
- const gutil = requireModule("gulp-util"),
2
- DEBUG = 1,
3
- INFO = 2,
4
- NOTICE = 3,
5
- WARNING = 4,
6
- ERROR = 5,
7
- levels = {
8
- DEBUG,
9
- INFO,
10
- NOTICE,
11
- WARNING
12
- };
13
- const LogLevels = function () {
14
- };
15
- LogLevels.prototype = {
16
- get Debug() {
17
- return DEBUG;
18
- },
19
- get Info() {
20
- return INFO;
21
- },
22
- get Notice() {
23
- return NOTICE;
24
- },
25
- get Warning() {
26
- return WARNING;
27
- },
28
- get Error() {
29
- return ERROR;
30
- }
31
- };
32
- const Logger = function () {
33
- this.LogLevels = new LogLevels();
34
- const logLevel = (process.env.LOG_LEVEL || "").toUpperCase();
35
- this.setThreshold(levels[logLevel] || INFO);
36
- this._timestamp = true;
37
- };
38
- Logger.prototype = {
39
- get threshold() {
40
- return this._threshold;
41
- },
42
- setThreshold: function(value) {
43
- const intValue = parseInt(value);
44
- if (isNaN(intValue) || intValue < 1 || intValue > 5) {
45
- throw value +
46
- " is not a valid integer value. Try use one of (logger).LogLevels.{Debug|Info|Notice|Warning|Error}";
47
- }
48
- this._threshold = intValue;
49
- },
50
- debug: function() {
51
- const message = this._resolve(Array.from(arguments));
52
- if (this._threshold > DEBUG) return;
53
- this._print(message, "grey");
54
- },
55
- info: function() {
56
- const message = this._resolve(Array.from(arguments));
57
- if (this._threshold > INFO) return;
58
- this._print(message, "yellow");
59
- },
60
- warning: function() {
61
- const message = this._resolve(Array.from(arguments));
62
- if (this._threshold > WARNING) return;
63
- this._print(message, "magenta");
64
- },
65
- error: function() {
66
- const message = this._resolve(Array.from(arguments));
67
- this._print(message, "red", "bold");
68
- },
69
- fail: function() {
70
- const message = this._resolve(Array.from(arguments));
71
- this.error(message);
72
- },
73
- ok: function() {
74
- const message = this._resolve(Array.from(arguments));
75
- this._print(message, "green");
76
- },
77
- notice: function() {
78
- const message = this._resolve(Array.from(arguments));
79
- if (this._threshold > NOTICE) return;
80
- this._print(message, "cyan");
81
- },
82
- suppressTimeStamps: function() {
83
- this._timestamp = false;
84
- },
85
- showTimeStamps: function() {
86
- this._timestamp = true;
87
- },
88
- _resolve: function(args) {
89
- return args
90
- .map(a => {
91
- if (a === undefined) {
92
- return "(undefined)";
93
- }
94
- if (a === null) {
95
- return "(null)";
96
- }
97
- if (Array.isArray(a)) {
98
- return a.join(",");
99
- }
100
- if (typeof a === "object") {
101
- return JSON.stringify(a);
102
- }
103
- return a.toString();
104
- })
105
- .join(" ");
106
- },
107
- _print: function() {
108
- const message = arguments[0];
109
- const styles = [];
110
- for (let i = 1; i < arguments.length; i++) {
111
- styles.push(arguments[i]); // because arguments is an object, not an array...
112
- }
113
- const styleFunction = styles.reduce(
114
- function (acc, cur) {
115
- const fn = gutil.colors[cur];
116
- if (fn === undefined) {
117
- return acc;
118
- }
119
- return function (s) {
120
- return fn(acc(s));
121
- };
122
- },
123
- function (s) {
124
- return s;
125
- }
126
- );
127
- if (this._timestamp) {
128
- gutil.log(styleFunction(message));
129
- } else {
130
- console.log(styleFunction(message));
131
- }
132
- }
133
- };
134
- const logger = new Logger();
135
- if (logger.threshold === DEBUG) {
136
- logger.debug(" -- testing logger outputs -- ");
137
- logger.debug("debug message");
138
- logger.info("info message");
139
- logger.warning("warning message");
140
- logger.error("error message");
141
- }
142
- module.exports = logger;
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
- const
2
- exec = requireModule("exec");
3
- let updating = null;
4
- module.exports = function (nugetPath) {
5
- if (updating) {
6
- return updating;
7
- }
8
- return exec(nugetPath, [ "update", "-self" ]);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zarro",
3
- "version": "1.141.8",
3
+ "version": "1.141.9",
4
4
  "description": "Some glue to make gulp easier, perhaps even zero- or close-to-zero-conf",
5
5
  "bin": {
6
6
  "zarro": "./index.js"
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>;