zarro 1.90.0 → 1.94.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/gulp-tasks/modules/download-nuget.js +104 -103
- package/gulp-tasks/modules/ensure-folder-exists.js +28 -21
- package/gulp-tasks/modules/env-helpers.js +4 -3
- package/gulp-tasks/modules/env-helpers.ts +6 -4
- package/gulp-tasks/modules/env.js +4 -3
- package/gulp-tasks/modules/find-npm-base.js +42 -41
- package/gulp-tasks/modules/fs.js +79 -78
- package/gulp-tasks/modules/git-tag.js +36 -35
- package/gulp-tasks/modules/gulp-git-tag-from-csproj.js +4 -4
- package/gulp-tasks/modules/gulp-git-tag-from-csproj.ts +4 -3
- package/gulp-tasks/modules/gulp-git-tag-from-package-nuspec.js +55 -53
- package/gulp-tasks/modules/gulp-increment-nuget-package-version.js +3 -3
- package/gulp-tasks/modules/gulp-increment-nuget-package-version.ts +3 -2
- package/gulp-tasks/modules/gulp-npm-run.js +2 -2
- package/gulp-tasks/modules/gulp-npm-run.ts +2 -1
- package/gulp-tasks/modules/gulp-nuget-pack.js +168 -168
- package/gulp-tasks/modules/http-downloader.js +113 -113
- package/gulp-tasks/modules/increment-version-string.js +18 -16
- package/gulp-tasks/modules/increment-version.js +3 -2
- package/gulp-tasks/modules/increment-version.ts +41 -39
- package/gulp-tasks/modules/install-local-tools.js +2 -1
- package/gulp-tasks/modules/load-xml-file.js +2 -2
- package/gulp-tasks/modules/load-xml-file.ts +2 -1
- package/gulp-tasks/modules/nuget-push.js +2 -1
- package/gulp-tasks/modules/pad.js +25 -23
- package/gulp-tasks/modules/promisify-stream.js +73 -67
- package/gulp-tasks/modules/read-csproj-package-version.js +2 -2
- package/gulp-tasks/modules/read-csproj-package-version.ts +2 -1
- package/gulp-tasks/modules/read-csproj-version.js +2 -2
- package/gulp-tasks/modules/read-csproj-version.ts +2 -1
- package/gulp-tasks/modules/read-git-commit-delta-count.js +2 -2
- package/gulp-tasks/modules/read-git-commit-delta-count.ts +3 -1
- package/gulp-tasks/modules/read-nuspec-version.js +2 -2
- package/gulp-tasks/modules/read-nuspec-version.ts +22 -21
- package/gulp-tasks/modules/read-package-json.js +2 -2
- package/gulp-tasks/modules/read-package-json.ts +22 -21
- package/gulp-tasks/modules/register-environment-variables.js +4 -2
- package/gulp-tasks/modules/resolve-nuget.js +4 -3
- package/gulp-tasks/modules/rewrite-file.js +3 -3
- package/gulp-tasks/modules/rewrite-file.ts +5 -3
- package/gulp-tasks/modules/testutil-finder.js +176 -175
- package/gulp-tasks/modules/zarro-error.js +6 -0
- package/gulp-tasks/nuget-restore.js +57 -57
- package/gulp-tasks/start/gulpfile.js +13 -7
- package/gulp-tasks/start/update-starter-packages.js +63 -70
- package/gulp-tasks/verify-up-to-date.js +4 -4
- package/gulp-tasks/verify-up-to-date.ts +4 -3
- package/index-modules/handlers/invoke-gulp.js +5 -4
- package/index.js +53 -52
- package/package.json +2 -2
|
@@ -1,103 +1,104 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
console.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
};
|
|
103
|
-
|
|
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}`);
|
|
50
|
+
}
|
|
51
|
+
cached[exePath] = true;
|
|
52
|
+
return resolve(exePath);
|
|
53
|
+
}).catch(e => {
|
|
54
|
+
lastMessage = e.message || lastMessage;
|
|
55
|
+
if (shouldLog) {
|
|
56
|
+
logger.debug(`failed to run executable (${
|
|
57
|
+
e.message
|
|
58
|
+
}); ${
|
|
59
|
+
attempts < 9
|
|
60
|
+
? "will try again"
|
|
61
|
+
: "giving up"
|
|
62
|
+
}`);
|
|
63
|
+
}
|
|
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
|
+
});
|
|
92
|
+
}
|
|
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
|
+
|
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
const
|
|
2
|
-
fs = require("fs"),
|
|
3
|
-
debug = require("debug")("ensure-folder-exists")
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
debug(`Ensuring existence of tools folder "${folder}"`);
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
try {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
const
|
|
2
|
+
fs = require("fs"),
|
|
3
|
+
debug = require("debug")("ensure-folder-exists")
|
|
4
|
+
|
|
5
|
+
function ensureFolderExists(folder) {
|
|
6
|
+
debug(`Ensuring existence of tools folder "${folder}"`);
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
try {
|
|
9
|
+
ensureFolderExistsSync(folder);
|
|
10
|
+
debug(`${folder} exists!`);
|
|
11
|
+
resolve();
|
|
12
|
+
} catch (e) {
|
|
13
|
+
debug(`${folder} doesn't exist and not creatable`);
|
|
14
|
+
debug(e);
|
|
15
|
+
reject(e);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function ensureFolderExistsSync(folder) {
|
|
21
|
+
if (!fs.existsSync(folder)) {
|
|
22
|
+
fs.mkdirSync(folder);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
ensureFolderExists.sync = ensureFolderExistsSync;
|
|
27
|
+
|
|
28
|
+
module.exports = ensureFolderExists;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(function () {
|
|
3
|
+
const { ZarroError } = requireModule("zarro-error");
|
|
3
4
|
function env(name, fallback) {
|
|
4
5
|
const value = process.env[name];
|
|
5
6
|
if (value !== undefined) {
|
|
@@ -9,14 +10,14 @@
|
|
|
9
10
|
if (argCount > 1) {
|
|
10
11
|
return fallback;
|
|
11
12
|
}
|
|
12
|
-
throw new
|
|
13
|
+
throw new ZarroError(`environment variable '${name}' is not defined and no fallback provided`);
|
|
13
14
|
}
|
|
14
15
|
function envNumber(name, fallback) {
|
|
15
16
|
const haveFallback = fallback !== undefined, value = haveFallback ? env(name, fallback === null || fallback === void 0 ? void 0 : fallback.toString()) : env(name), parsed = parseInt(value, 10);
|
|
16
17
|
if (!isNaN(parsed)) {
|
|
17
18
|
return parsed;
|
|
18
19
|
}
|
|
19
|
-
throw new
|
|
20
|
+
throw new ZarroError(`environment variable '${name}' is invalid: expected numeric value but found '${value}'`);
|
|
20
21
|
}
|
|
21
22
|
function envFlag(name, fallback) {
|
|
22
23
|
const haveFallback = fallback !== undefined, value = haveFallback ? env(name, fallback === null || fallback === void 0 ? void 0 : fallback.toString()) : env(name);
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
if (falsey.indexOf(value === null || value === void 0 ? void 0 : value.toString()) > -1) {
|
|
39
40
|
return false;
|
|
40
41
|
}
|
|
41
|
-
throw new
|
|
42
|
+
throw new ZarroError(`environment variable '${name}' is invalid: could not parse '${value}' as a boolean value`);
|
|
42
43
|
}
|
|
43
44
|
module.exports = {
|
|
44
45
|
env,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
(function() {
|
|
2
|
+
const { ZarroError } = requireModule("zarro-error");
|
|
3
|
+
|
|
2
4
|
function env(name: string, fallback?: string): string {
|
|
3
5
|
const value = process.env[name];
|
|
4
6
|
if (value !== undefined) {
|
|
@@ -8,7 +10,7 @@
|
|
|
8
10
|
if (argCount > 1) {
|
|
9
11
|
return fallback as string;
|
|
10
12
|
}
|
|
11
|
-
throw new
|
|
13
|
+
throw new ZarroError(
|
|
12
14
|
`environment variable '${ name }' is not defined and no fallback provided`
|
|
13
15
|
);
|
|
14
16
|
}
|
|
@@ -21,7 +23,7 @@
|
|
|
21
23
|
if (!isNaN(parsed)) {
|
|
22
24
|
return parsed;
|
|
23
25
|
}
|
|
24
|
-
throw new
|
|
26
|
+
throw new ZarroError(
|
|
25
27
|
`environment variable '${ name }' is invalid: expected numeric value but found '${ value }'`
|
|
26
28
|
);
|
|
27
29
|
}
|
|
@@ -51,8 +53,8 @@
|
|
|
51
53
|
if (falsey.indexOf(value?.toString()) > -1) {
|
|
52
54
|
return false;
|
|
53
55
|
}
|
|
54
|
-
throw new
|
|
55
|
-
`environment variable '${name}' is invalid: could not parse '${value}' as a
|
|
56
|
+
throw new ZarroError(
|
|
57
|
+
`environment variable '${name}' is invalid: could not parse '${value}' as a boolean value`
|
|
56
58
|
);
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -9,6 +9,7 @@ if (!Array.prototype.flatMap) {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
const
|
|
12
|
+
{ ZarroError } = requireModule("zarro-error"),
|
|
12
13
|
chalk = require("ansi-colors"),
|
|
13
14
|
debug = require("debug")("env"),
|
|
14
15
|
registeredEnvironmentVariables = {},
|
|
@@ -51,7 +52,7 @@ function fallback(name, defaultValue) {
|
|
|
51
52
|
function register(config) {
|
|
52
53
|
let { name, help, tasks, overriddenBy, when } = config;
|
|
53
54
|
if (toExport[name] !== undefined) {
|
|
54
|
-
throw new
|
|
55
|
+
throw new ZarroError(`env var already registered: ${name}`);
|
|
55
56
|
}
|
|
56
57
|
toExport[name] = name;
|
|
57
58
|
// 'default' seems like a more natural name, but we can't use it for a var name...
|
|
@@ -328,7 +329,7 @@ function resolveNumber(name) {
|
|
|
328
329
|
const value = resolveInternal(name),
|
|
329
330
|
asNumber = parseInt(value, 10);
|
|
330
331
|
if (isNaN(asNumber)) {
|
|
331
|
-
throw new
|
|
332
|
+
throw new ZarroError(`${value} is not a valid numeric value for ${name}`);
|
|
332
333
|
}
|
|
333
334
|
logResolved(name, asNumber);
|
|
334
335
|
return asNumber;
|
|
@@ -347,7 +348,7 @@ function resolveFlag(name) {
|
|
|
347
348
|
logResolved(name, false);
|
|
348
349
|
return false;
|
|
349
350
|
}
|
|
350
|
-
throw new
|
|
351
|
+
throw new ZarroError(`environmental flag not set and no default: ${name}`);
|
|
351
352
|
}
|
|
352
353
|
|
|
353
354
|
function explode(str, delimiter) {
|
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
const
|
|
2
|
+
{ ZarroError } = requireModule("zarro-error"),
|
|
3
|
+
path = require("path"),
|
|
4
|
+
fs = requireModule("fs");
|
|
5
|
+
let cached;
|
|
6
|
+
|
|
7
|
+
function findClosestPackageJsonFolder() {
|
|
8
|
+
let current = __dirname;
|
|
9
|
+
while (inNodeModulesFolder(current) || !hasPackageJson(current)) {
|
|
10
|
+
const next = path.dirname(current);
|
|
11
|
+
if (next === current) {
|
|
12
|
+
throw new ZarroError(`Can't find a package.json, traversing up from ${__dirname}`);
|
|
13
|
+
}
|
|
14
|
+
current = next;
|
|
15
|
+
}
|
|
16
|
+
return current;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function inNodeModulesFolder(folder) {
|
|
20
|
+
return !!folder.match(/node_modules/);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function hasPackageJson(folder) {
|
|
24
|
+
const test = path.join(folder, "package.json");
|
|
25
|
+
if (!fs.existsSync(test)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const
|
|
30
|
+
contents = require(test),
|
|
31
|
+
repo = contents.repository || {},
|
|
32
|
+
url = repo.url || "",
|
|
33
|
+
isGulpTasks = url.match(/\/fluffynuts\/gulp-tasks$/);
|
|
34
|
+
return !isGulpTasks;
|
|
35
|
+
} catch (ignore) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = function() {
|
|
41
|
+
return cached || (cached = findClosestPackageJsonFolder());
|
|
42
|
+
};
|
package/gulp-tasks/modules/fs.js
CHANGED
|
@@ -1,78 +1,79 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
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
|
-
|
|
1
|
+
const
|
|
2
|
+
{ ZarroError } = requireModule("zarro-error"),
|
|
3
|
+
promisify = require("./promisify-function"),
|
|
4
|
+
path = require("path"),
|
|
5
|
+
fs = require("fs");
|
|
6
|
+
|
|
7
|
+
const
|
|
8
|
+
stat = promisify(fs.stat, fs),
|
|
9
|
+
readFile = promisify(fs.readFile, fs),
|
|
10
|
+
readdir = promisify(fs.readdir, fs),
|
|
11
|
+
mkdir = promisify(fs.mkdir, fs),
|
|
12
|
+
exists = promisify(fs.exists, fs, true);
|
|
13
|
+
|
|
14
|
+
function isFile(p) {
|
|
15
|
+
return runStat(p, st => st.isFile());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isFolder(p) {
|
|
19
|
+
return runStat(p, st => st.isDirectory());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function runStat(p, fn) {
|
|
23
|
+
return new Promise(resolve => {
|
|
24
|
+
fs.stat(p, (err, st) => {
|
|
25
|
+
if (err) {
|
|
26
|
+
return resolve(false);
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
resolve(st && fn(st));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
resolve(false);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const exported = {
|
|
38
|
+
...fs.promises, // if they exist
|
|
39
|
+
stat,
|
|
40
|
+
readFile,
|
|
41
|
+
readdir,
|
|
42
|
+
mkdir,
|
|
43
|
+
exists,
|
|
44
|
+
isFile,
|
|
45
|
+
isFolder,
|
|
46
|
+
fileExists: isFile,
|
|
47
|
+
folderExists: isFolder,
|
|
48
|
+
|
|
49
|
+
ensureDirectoryExists: async function(expectedPath) {
|
|
50
|
+
// forward-slashes can be valid (and mixed) on win32,
|
|
51
|
+
// so split on both \ and / to make \o/
|
|
52
|
+
const
|
|
53
|
+
parts = expectedPath.split(/\\|\//),
|
|
54
|
+
current = [];
|
|
55
|
+
for (const part of parts) {
|
|
56
|
+
if (!part) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
current.push(part);
|
|
60
|
+
const
|
|
61
|
+
test = current.join(path.sep),
|
|
62
|
+
pathExists = await exists(test);
|
|
63
|
+
if (pathExists) {
|
|
64
|
+
const st = await stat(test);
|
|
65
|
+
if (!st.isDirectory()) {
|
|
66
|
+
throw new ZarroError(`${test} exists but is not a directory`);
|
|
67
|
+
}
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
await mkdir(test);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
Object.keys(fs)
|
|
76
|
+
.filter(k => k.match(/Sync$/) && typeof fs[k] === "function")
|
|
77
|
+
.forEach(k => exported[k] = fs[k].bind(fs));
|
|
78
|
+
|
|
79
|
+
module.exports = exported;
|