zarro 1.92.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.
Files changed (201) hide show
  1. package/LICENSE +10 -0
  2. package/README.md +260 -0
  3. package/gulp-tasks/.editorconfig +8 -0
  4. package/gulp-tasks/.git +1 -0
  5. package/gulp-tasks/.gitignore +9 -0
  6. package/gulp-tasks/.gitmodules +0 -0
  7. package/gulp-tasks/LICENSE +24 -0
  8. package/gulp-tasks/README.md +144 -0
  9. package/gulp-tasks/build.js +135 -0
  10. package/gulp-tasks/clean.js +37 -0
  11. package/gulp-tasks/cover-dotnet.js +56 -0
  12. package/gulp-tasks/default-report-generator.js +51 -0
  13. package/gulp-tasks/default-tools-installer.js +33 -0
  14. package/gulp-tasks/default.js +17 -0
  15. package/gulp-tasks/dotnet-publish.js +23 -0
  16. package/gulp-tasks/generate-reports.js +7 -0
  17. package/gulp-tasks/get-local-nuget.js +16 -0
  18. package/gulp-tasks/git-submodules.js +83 -0
  19. package/gulp-tasks/increment-package-json-version.js +12 -0
  20. package/gulp-tasks/increment-package-json-version.ts +17 -0
  21. package/gulp-tasks/install-tools.js +24 -0
  22. package/gulp-tasks/modules/add-stream-on-any-handler.js +31 -0
  23. package/gulp-tasks/modules/alter-package-json-version.js +64 -0
  24. package/gulp-tasks/modules/alter-package-json-version.ts +113 -0
  25. package/gulp-tasks/modules/are-all-dotnet-core.js +96 -0
  26. package/gulp-tasks/modules/ask.js +31 -0
  27. package/gulp-tasks/modules/ask.ts +41 -0
  28. package/gulp-tasks/modules/collect-files.js +15 -0
  29. package/gulp-tasks/modules/collect-files.ts +16 -0
  30. package/gulp-tasks/modules/config-generator.js +10 -0
  31. package/gulp-tasks/modules/defaults.js +9 -0
  32. package/gulp-tasks/modules/download-nuget.js +104 -0
  33. package/gulp-tasks/modules/ensure-folder-exists.js +21 -0
  34. package/gulp-tasks/modules/env-helpers.js +49 -0
  35. package/gulp-tasks/modules/env-helpers.ts +67 -0
  36. package/gulp-tasks/modules/env.js +364 -0
  37. package/gulp-tasks/modules/exec.js +257 -0
  38. package/gulp-tasks/modules/exec.ts +346 -0
  39. package/gulp-tasks/modules/fail-after.js +30 -0
  40. package/gulp-tasks/modules/fail-after.ts +34 -0
  41. package/gulp-tasks/modules/fallback.js +6 -0
  42. package/gulp-tasks/modules/find-dirs.js +39 -0
  43. package/gulp-tasks/modules/find-local-nuget.js +42 -0
  44. package/gulp-tasks/modules/find-npm-base.js +42 -0
  45. package/gulp-tasks/modules/fs.js +79 -0
  46. package/gulp-tasks/modules/gather-paths.js +23 -0
  47. package/gulp-tasks/modules/gather-paths.ts +29 -0
  48. package/gulp-tasks/modules/generate-env-help-for.js +30 -0
  49. package/gulp-tasks/modules/get-tools-folder.js +12 -0
  50. package/gulp-tasks/modules/git-push-tags.js +33 -0
  51. package/gulp-tasks/modules/git-push-tags.ts +42 -0
  52. package/gulp-tasks/modules/git-push.js +51 -0
  53. package/gulp-tasks/modules/git-tag.js +36 -0
  54. package/gulp-tasks/modules/gulp-dotnetcover.js +537 -0
  55. package/gulp-tasks/modules/gulp-git-tag-from-csproj.js +50 -0
  56. package/gulp-tasks/modules/gulp-git-tag-from-csproj.ts +71 -0
  57. package/gulp-tasks/modules/gulp-git-tag-from-package-nuspec.js +55 -0
  58. package/gulp-tasks/modules/gulp-increment-nuget-package-dependency-version.js +40 -0
  59. package/gulp-tasks/modules/gulp-increment-nuget-package-version.js +87 -0
  60. package/gulp-tasks/modules/gulp-increment-nuget-package-version.ts +122 -0
  61. package/gulp-tasks/modules/gulp-msbuild.js +1 -0
  62. package/gulp-tasks/modules/gulp-npm-run.js +40 -0
  63. package/gulp-tasks/modules/gulp-npm-run.ts +52 -0
  64. package/gulp-tasks/modules/gulp-nuget-pack.js +168 -0
  65. package/gulp-tasks/modules/gulp-nuget-restore.js +106 -0
  66. package/gulp-tasks/modules/gulp-nunit-runner/.jshintrc +5 -0
  67. package/gulp-tasks/modules/gulp-nunit-runner/.npmignore +16 -0
  68. package/gulp-tasks/modules/gulp-nunit-runner/LICENSE +21 -0
  69. package/gulp-tasks/modules/gulp-nunit-runner/README.md +300 -0
  70. package/gulp-tasks/modules/gulp-nunit-runner/index.js +1 -0
  71. package/gulp-tasks/modules/gulp-nunit-runner/lib/index.js +205 -0
  72. package/gulp-tasks/modules/gulp-nunit-runner/lib/teamcity.js +86 -0
  73. package/gulp-tasks/modules/gulp-purge.js +88 -0
  74. package/gulp-tasks/modules/gulp-util.js +5 -0
  75. package/gulp-tasks/modules/gulp-version.js +8 -0
  76. package/gulp-tasks/modules/gulp-with-help.js +1 -0
  77. package/gulp-tasks/modules/gulp-xbuild.js +62 -0
  78. package/gulp-tasks/modules/gulp.js +92 -0
  79. package/gulp-tasks/modules/http-downloader.js +113 -0
  80. package/gulp-tasks/modules/import-npm-tasks.js +33 -0
  81. package/gulp-tasks/modules/increment-version-string.js +18 -0
  82. package/gulp-tasks/modules/increment-version.js +30 -0
  83. package/gulp-tasks/modules/increment-version.ts +41 -0
  84. package/gulp-tasks/modules/install-local-tools.js +122 -0
  85. package/gulp-tasks/modules/load-xml-file.js +12 -0
  86. package/gulp-tasks/modules/load-xml-file.ts +15 -0
  87. package/gulp-tasks/modules/log-config.js +31 -0
  88. package/gulp-tasks/modules/log.js +142 -0
  89. package/gulp-tasks/modules/longest-string-length.js +13 -0
  90. package/gulp-tasks/modules/looks-like-a-promise.js +11 -0
  91. package/gulp-tasks/modules/ls-r.js +52 -0
  92. package/gulp-tasks/modules/multi-split.js +29 -0
  93. package/gulp-tasks/modules/net-framework-test-assembly-filter.js +45 -0
  94. package/gulp-tasks/modules/nuget-push.js +66 -0
  95. package/gulp-tasks/modules/nuget-update-self.js +9 -0
  96. package/gulp-tasks/modules/nuget.js +8 -0
  97. package/gulp-tasks/modules/nuget.ts +14 -0
  98. package/gulp-tasks/modules/pad-left.js +4 -0
  99. package/gulp-tasks/modules/pad-right.js +4 -0
  100. package/gulp-tasks/modules/pad.js +25 -0
  101. package/gulp-tasks/modules/parse-xml-string.js +5 -0
  102. package/gulp-tasks/modules/parse-xml-string.ts +6 -0
  103. package/gulp-tasks/modules/parse-xml.js +14 -0
  104. package/gulp-tasks/modules/parse-xml.ts +15 -0
  105. package/gulp-tasks/modules/path-unquote.js +6 -0
  106. package/gulp-tasks/modules/promisify-function.js +19 -0
  107. package/gulp-tasks/modules/promisify-function.ts +18 -0
  108. package/gulp-tasks/modules/promisify-stream.js +73 -0
  109. package/gulp-tasks/modules/promisify.js +1 -0
  110. package/gulp-tasks/modules/quote-if-required.js +14 -0
  111. package/gulp-tasks/modules/read-all-git-branches.js +10 -0
  112. package/gulp-tasks/modules/read-all-git-branches.ts +13 -0
  113. package/gulp-tasks/modules/read-all-git-remotes.js +36 -0
  114. package/gulp-tasks/modules/read-all-git-remotes.ts +44 -0
  115. package/gulp-tasks/modules/read-csproj-package-version.js +16 -0
  116. package/gulp-tasks/modules/read-csproj-package-version.ts +26 -0
  117. package/gulp-tasks/modules/read-csproj-version.js +16 -0
  118. package/gulp-tasks/modules/read-csproj-version.ts +26 -0
  119. package/gulp-tasks/modules/read-current-git-branch.js +12 -0
  120. package/gulp-tasks/modules/read-current-git-branch.ts +16 -0
  121. package/gulp-tasks/modules/read-git-commit-delta-count.js +21 -0
  122. package/gulp-tasks/modules/read-git-commit-delta-count.ts +33 -0
  123. package/gulp-tasks/modules/read-git-info.js +28 -0
  124. package/gulp-tasks/modules/read-git-info.ts +31 -0
  125. package/gulp-tasks/modules/read-git-remote.js +17 -0
  126. package/gulp-tasks/modules/read-git-remote.ts +23 -0
  127. package/gulp-tasks/modules/read-last-fetch-time.js +21 -0
  128. package/gulp-tasks/modules/read-last-fetch-time.ts +17 -0
  129. package/gulp-tasks/modules/read-main-branch-name.js +48 -0
  130. package/gulp-tasks/modules/read-main-branch-name.ts +76 -0
  131. package/gulp-tasks/modules/read-nuspec-version.js +14 -0
  132. package/gulp-tasks/modules/read-nuspec-version.ts +22 -0
  133. package/gulp-tasks/modules/read-package-json.js +16 -0
  134. package/gulp-tasks/modules/read-package-json.ts +22 -0
  135. package/gulp-tasks/modules/read-package-version.js +8 -0
  136. package/gulp-tasks/modules/read-package-version.ts +10 -0
  137. package/gulp-tasks/modules/read-text-file.js +14 -0
  138. package/gulp-tasks/modules/read-text-file.ts +14 -0
  139. package/gulp-tasks/modules/reduce-gulp-noise.js +34 -0
  140. package/gulp-tasks/modules/register-environment-variables.js +526 -0
  141. package/gulp-tasks/modules/require-module.js +28 -0
  142. package/gulp-tasks/modules/resolve-git-branch.js +11 -0
  143. package/gulp-tasks/modules/resolve-git-branch.ts +13 -0
  144. package/gulp-tasks/modules/resolve-git-remote.js +11 -0
  145. package/gulp-tasks/modules/resolve-git-remote.ts +13 -0
  146. package/gulp-tasks/modules/resolve-masks.js +47 -0
  147. package/gulp-tasks/modules/resolve-nuget.js +135 -0
  148. package/gulp-tasks/modules/resolve-test-masks.js +10 -0
  149. package/gulp-tasks/modules/rewrite-file.js +26 -0
  150. package/gulp-tasks/modules/rewrite-file.ts +34 -0
  151. package/gulp-tasks/modules/rimraf.js +21 -0
  152. package/gulp-tasks/modules/rimraf.ts +31 -0
  153. package/gulp-tasks/modules/run-sequence.js +16 -0
  154. package/gulp-tasks/modules/safe-git.js +23 -0
  155. package/gulp-tasks/modules/safe-git.ts +23 -0
  156. package/gulp-tasks/modules/seed.js +12 -0
  157. package/gulp-tasks/modules/set-task-name.js +9 -0
  158. package/gulp-tasks/modules/sleep.js +5 -0
  159. package/gulp-tasks/modules/spawn-nuget.js +13 -0
  160. package/gulp-tasks/modules/spawn.js +103 -0
  161. package/gulp-tasks/modules/split-path.js +3 -0
  162. package/gulp-tasks/modules/stat.js +8 -0
  163. package/gulp-tasks/modules/status.js +57 -0
  164. package/gulp-tasks/modules/status.ts +71 -0
  165. package/gulp-tasks/modules/test-path.js +3 -0
  166. package/gulp-tasks/modules/testutil-finder.js +176 -0
  167. package/gulp-tasks/modules/throw-if-no-files.js +15 -0
  168. package/gulp-tasks/modules/uniq.js +6 -0
  169. package/gulp-tasks/modules/uniq.ts +5 -0
  170. package/gulp-tasks/modules/verify-exe.js +17 -0
  171. package/gulp-tasks/modules/version-reading-shared.js +12 -0
  172. package/gulp-tasks/modules/version-reading-shared.ts +16 -0
  173. package/gulp-tasks/modules/write-text-file.js +10 -0
  174. package/gulp-tasks/modules/zarro-error.js +6 -0
  175. package/gulp-tasks/nuget-restore.js +57 -0
  176. package/gulp-tasks/pack.js +118 -0
  177. package/gulp-tasks/purge.js +94 -0
  178. package/gulp-tasks/release-npm.js +58 -0
  179. package/gulp-tasks/release-npm.ts +81 -0
  180. package/gulp-tasks/start/_package.json +39 -0
  181. package/gulp-tasks/start/gulpfile.js +204 -0
  182. package/gulp-tasks/start/update-starter-packages.js +63 -0
  183. package/gulp-tasks/test-dotnet.js +195 -0
  184. package/gulp-tasks/update-git-submodules.js +11 -0
  185. package/gulp-tasks/update-git-submodules.ts +29 -0
  186. package/gulp-tasks/update-self.js +65 -0
  187. package/gulp-tasks/update-self.ts +88 -0
  188. package/gulp-tasks/verify-up-to-date.js +77 -0
  189. package/gulp-tasks/verify-up-to-date.ts +119 -0
  190. package/index-modules/contains-any.js +31 -0
  191. package/index-modules/gather-args.js +21 -0
  192. package/index-modules/handlers/help.js +17 -0
  193. package/index-modules/handlers/init.js +57 -0
  194. package/index-modules/handlers/invoke-gulp.js +111 -0
  195. package/index-modules/handlers/show-env.js +46 -0
  196. package/index-modules/is-dir.js +6 -0
  197. package/index-modules/is-file.js +6 -0
  198. package/index.js +53 -0
  199. package/package.json +96 -0
  200. package/tsconfig.json +66 -0
  201. package/types.d.ts +753 -0
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ (function () {
3
+ const gulp = requireModule("gulp"), status = requireModule("status"), Git = require("simple-git/promise"), env = requireModule("env");
4
+ env.associate("UPDATE_SUBMODULES_TO_LATEST", "update-git-submodules");
5
+ gulp.task("update-git-submodules", "Updates all git submodules to latest commit on master branch", async () => {
6
+ const git = new Git(".");
7
+ await status.run("Ensure submodules are initialized...", async () => await git.subModule(["update", "--init"]));
8
+ await status.run("Check out master on all submodules...", async () => await git.subModule(["foreach", "git", "checkout", "master"]));
9
+ await status.run("Update to latest commit on each submodule...", async () => await git.subModule(["foreach", "git", "pull", "--rebase"]));
10
+ });
11
+ })();
@@ -0,0 +1,29 @@
1
+ (function() {
2
+ const gulp = requireModule<Gulp>("gulp"),
3
+ status = requireModule<Status>("status"),
4
+ Git = require("simple-git/promise"),
5
+ env = requireModule<Env>("env");
6
+
7
+ env.associate("UPDATE_SUBMODULES_TO_LATEST", "update-git-submodules");
8
+
9
+ gulp.task(
10
+ "update-git-submodules",
11
+ "Updates all git submodules to latest commit on master branch",
12
+ async () => {
13
+ const git = new Git(".");
14
+ await status.run(
15
+ "Ensure submodules are initialized...",
16
+ async () => await git.subModule(["update", "--init"])
17
+ );
18
+ await status.run(
19
+ "Check out master on all submodules...",
20
+ async () => await git.subModule(["foreach", "git", "checkout", "master"])
21
+ );
22
+ await status.run(
23
+ "Update to latest commit on each submodule...",
24
+ async () => await git.subModule(["foreach", "git", "pull", "--rebase"])
25
+ );
26
+ }
27
+ );
28
+ })();
29
+
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const spawn = requireModule("spawn"), gulp = requireModule("gulp"), env = requireModule("env"), chalk = require("ansi-colors"), resolveMasks = requireModule("resolve-masks"), debug = require("debug")("update-self"), es = require("event-stream");
4
+ env.associate([
5
+ env.DRY_RUN,
6
+ env.INCLUDE_PACKAGE_JSON,
7
+ env.EXCLUDE_PACKAGE_JSON
8
+ ], "update-self");
9
+ gulp.task("update-self", "Updates zarro throughout your current project", () => {
10
+ const glob = resolveMasks(env.INCLUDE_PACKAGE_JSON, env.EXCLUDE_PACKAGE_JSON);
11
+ debug({
12
+ glob
13
+ });
14
+ return gulp.src(glob)
15
+ .pipe(updateZarroPipe(env.resolveFlag(env.BETA)));
16
+ });
17
+ function updateZarroPipe(beta) {
18
+ const promises = [];
19
+ const stream = es.through(function input(file) {
20
+ let save = false, saveDev = false;
21
+ const json = file.contents.toString();
22
+ try {
23
+ const search = "zarro", packageIndex = JSON.parse(json), deps = packageIndex.dependencies || {}, devDeps = packageIndex.devDependencies || {};
24
+ save = Object.keys(deps).includes(search);
25
+ saveDev = Object.keys(devDeps).includes(search);
26
+ if (!save && !saveDev) {
27
+ debug(`${search} not installed in ${file.path}`);
28
+ return;
29
+ }
30
+ }
31
+ catch (e) {
32
+ debug(`${file.path} is not valid JSON`);
33
+ return;
34
+ }
35
+ console.log(chalk.yellow(`update zarro in: ${file.dirname}`));
36
+ const proc = "npm", tag = beta ? "beta" : "latest", args = ["install", save ? "--save" : "--save-dev", `zarro@${tag}`, "--no-progress", "--silent"], opts = {
37
+ cwd: file.dirname
38
+ };
39
+ if (env.resolveFlag(env.DRY_RUN)) {
40
+ console.log({
41
+ label: "would run spawn with",
42
+ proc,
43
+ args,
44
+ opts
45
+ });
46
+ }
47
+ else {
48
+ promises.push(spawn.call(null, proc, args, opts));
49
+ }
50
+ }, async function end() {
51
+ try {
52
+ await Promise.all(promises);
53
+ stream.emit("end");
54
+ }
55
+ catch (err) {
56
+ console.error(chalk.redBright(`
57
+ ==================================================
58
+ | WARNING: Unable to update zarro, error(s) follow |
59
+ ==================================================
60
+ `));
61
+ stream.emit("error", err);
62
+ }
63
+ });
64
+ return stream;
65
+ }
@@ -0,0 +1,88 @@
1
+ export {}
2
+ import * as vinyl from "vinyl";
3
+
4
+ const
5
+ spawn = requireModule<Spawn>("spawn"),
6
+ gulp = requireModule<GulpWithHelp>("gulp"),
7
+ env = requireModule<Env>("env"),
8
+ chalk = require("ansi-colors"),
9
+ resolveMasks = requireModule<ResolveMasks>("resolve-masks"),
10
+ debug = require("debug")("update-self"),
11
+ es = require("event-stream");
12
+
13
+ env.associate([
14
+ env.DRY_RUN,
15
+ env.INCLUDE_PACKAGE_JSON,
16
+ env.EXCLUDE_PACKAGE_JSON
17
+ ], "update-self");
18
+
19
+ gulp.task(
20
+ "update-self",
21
+ "Updates zarro throughout your current project",
22
+ () => {
23
+ const
24
+ glob = resolveMasks(env.INCLUDE_PACKAGE_JSON, env.EXCLUDE_PACKAGE_JSON);
25
+ debug({
26
+ glob
27
+ });
28
+ return gulp.src(glob)
29
+ .pipe(updateZarroPipe(env.resolveFlag(env.BETA)));
30
+ });
31
+
32
+ function updateZarroPipe(beta: boolean) {
33
+ const
34
+ promises: Promise<any>[] = [];
35
+ const stream = es.through(function input(file: vinyl.BufferFile) {
36
+ let
37
+ save = false,
38
+ saveDev = false;
39
+ const json = file.contents.toString();
40
+ try {
41
+ const
42
+ search = "zarro",
43
+ packageIndex = JSON.parse(json) as PackageIndex,
44
+ deps = packageIndex.dependencies || {},
45
+ devDeps = packageIndex.devDependencies || {};
46
+ save = Object.keys(deps).includes(search);
47
+ saveDev = Object.keys(devDeps).includes(search);
48
+ if (!save && !saveDev) {
49
+ debug(`${ search } not installed in ${ file.path }`);
50
+ return;
51
+ }
52
+ } catch (e) {
53
+ debug(`${ file.path } is not valid JSON`);
54
+ return;
55
+ }
56
+ console.log(chalk.yellow(`update zarro in: ${ file.dirname }`));
57
+ const
58
+ proc = "npm",
59
+ tag = beta ? "beta" : "latest",
60
+ args = ["install", save ? "--save" : "--save-dev", `zarro@${tag}`, "--no-progress", "--silent"],
61
+ opts = {
62
+ cwd: file.dirname
63
+ }
64
+ if (env.resolveFlag(env.DRY_RUN)) {
65
+ console.log({
66
+ label: "would run spawn with",
67
+ proc,
68
+ args,
69
+ opts
70
+ });
71
+ } else {
72
+ promises.push(spawn.call(null, proc, args, opts))
73
+ }
74
+ }, async function end() {
75
+ try {
76
+ await Promise.all(promises)
77
+ stream.emit("end");
78
+ } catch (err) {
79
+ console.error(chalk.redBright(`
80
+ ==================================================
81
+ | WARNING: Unable to update zarro, error(s) follow |
82
+ ==================================================
83
+ `));
84
+ stream.emit("error", err);
85
+ }
86
+ });
87
+ return stream;
88
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ (function () {
3
+ const os = require("os"), chalk = require("ansi-colors"), log = requireModule("log"), env = requireModule("env"), Git = require("simple-git/promise"), failAfter = requireModule("fail-after"), readMainBranchName = requireModule("read-main-branch-name"), readAllGitRemotes = requireModule("read-all-git-remotes"), readCurrentBranch = requireModule("read-current-git-branch"), readGitCommitDeltaCount = requireModule("read-git-commit-delta-count"), readLastFetchTime = requireModule("read-last-fetch-time"), gulp = requireModule("gulp"), { ZarroError } = requireModule("zarro-error"), taskName = "verify-up-to-date";
4
+ env.associate([
5
+ "SKIP_FETCH_ON_VERIFY",
6
+ "ENFORCE_VERIFICATION",
7
+ "INTERACTIVE"
8
+ ], taskName);
9
+ gulp.task(taskName, async () => {
10
+ // git on OSX is still inserting a pager somewhere, breaking this, so temporarily
11
+ // disable this test
12
+ if (os.platform() === "darwin") {
13
+ console.warn(chalk.redBright(`up-to-date verification is experimental on OSX! Please report errors to davydm@gmail.com`));
14
+ }
15
+ const remoteInfos = (await readAllGitRemotes()) || [], remotes = remoteInfos.map(r => r.name), mainBranch = env.resolve("GIT_MAIN_BRANCH") || await resolveDefaultVerifyTarget(remotes), verifyBranch = env.resolve("GIT_VERIFY_BRANCH") || await readCurrentBranch();
16
+ if (!mainBranch) {
17
+ throw new ZarroError(`Can't determine main branch (try setting env: GIT_MAIN_BRANCH)`);
18
+ }
19
+ if (!verifyBranch) {
20
+ throw new ZarroError(`Can't determine branch to verify (try setting env: GIT_VERIFY_BRANCH)`);
21
+ }
22
+ if (remotes.length && !env.resolveFlag("SKIP_FETCH_ON_VERIFY")) {
23
+ const lastFetch = await readLastFetchTime(), fetchRecentPeriod = env.resolveNumber("FETCH_RECENT_TIME") * 1000, now = Date.now();
24
+ let recentEnough = false;
25
+ if (lastFetch) {
26
+ recentEnough = (now - fetchRecentPeriod) < lastFetch.getTime();
27
+ }
28
+ if (!recentEnough) {
29
+ log.info(`${taskName} :: fetching all remotes...`);
30
+ const git = new Git(), timeout = env.resolveNumber("GIT_FETCH_TIMEOUT");
31
+ try {
32
+ const fail = failAfter(timeout);
33
+ await Promise.race([
34
+ git.fetch(["--all"]),
35
+ fail.promise
36
+ ]);
37
+ fail.cancel();
38
+ }
39
+ catch (e) {
40
+ const msg = e.message || e;
41
+ if (msg === "operation timed out") {
42
+ log.error(chalk.redBright(`fetch operation timed out:
43
+ - check that the current account can fetch from all remotes
44
+ - optionally disable fetch with SKIP_FETCH_ON_VERIFY=1
45
+ - optionally increase GIT_FETCH_TIMEOUT from current value: ${timeout}`));
46
+ }
47
+ }
48
+ }
49
+ else {
50
+ log.info(`${taskName} :: skipping fetch: was last done at ${lastFetch}`);
51
+ }
52
+ }
53
+ const verifyResult = await readGitCommitDeltaCount(mainBranch || "master", verifyBranch);
54
+ // TODO: get the delta count & chuck if behind
55
+ const aheadS = verifyResult.ahead === 1 ? "" : "s", behindS = verifyResult.behind === 1 ? "" : "s", message = `${chalk.yellow(verifyBranch)} is ${chalk.green(verifyResult.ahead)} commit${aheadS} ahead and ${chalk.red(verifyResult.behind)} commit${behindS} behind ${chalk.cyanBright(mainBranch)}`;
56
+ log.info(`${taskName} :: ${message}`);
57
+ if (verifyResult.behind > 0) {
58
+ if (env.resolveFlag("ENFORCE_VERIFICATION")) {
59
+ throw new ZarroError(message);
60
+ }
61
+ if (env.resolveFlag("INTERACTIVE")) {
62
+ console.error(`interactive mode for verify-up-to-date is not yet implemented`);
63
+ // TODO: ask if the user would like to merge in master & proceed if ok
64
+ }
65
+ }
66
+ });
67
+ async function resolveDefaultVerifyTarget(remotes) {
68
+ remotes = remotes !== null && remotes !== void 0 ? remotes : [];
69
+ const mainBranchName = await readMainBranchName(), remote = remotes[0];
70
+ if (mainBranchName === null || mainBranchName === void 0 ? void 0 : mainBranchName.startsWith(`${remote}/`)) {
71
+ return mainBranchName;
72
+ }
73
+ return remote
74
+ ? `${remote}/${mainBranchName}`
75
+ : mainBranchName;
76
+ }
77
+ })();
@@ -0,0 +1,119 @@
1
+ (function() {
2
+ const
3
+ os = require("os"),
4
+ chalk = require("ansi-colors"),
5
+ log = requireModule<Log>("log"),
6
+ env = requireModule<Env>("env"),
7
+ Git = require("simple-git/promise"),
8
+ failAfter = requireModule<FailAfter>("fail-after"),
9
+ readMainBranchName = requireModule<ReadMainBranchName>("read-main-branch-name"),
10
+ readAllGitRemotes = requireModule<ReadAllGitRemotes>("read-all-git-remotes"),
11
+ readCurrentBranch = requireModule<ReadCurrentGitBranch>("read-current-git-branch"),
12
+ readGitCommitDeltaCount = requireModule<ReadGitCommitDeltaCount>("read-git-commit-delta-count"),
13
+ readLastFetchTime = requireModule<ReadLastFetchTime>("read-last-fetch-time"),
14
+ gulp = requireModule<GulpWithHelp>("gulp"),
15
+ { ZarroError } = requireModule("zarro-error"),
16
+ taskName = "verify-up-to-date";
17
+
18
+ env.associate([
19
+ "SKIP_FETCH_ON_VERIFY",
20
+ "ENFORCE_VERIFICATION",
21
+ "INTERACTIVE"
22
+ ], taskName);
23
+
24
+ gulp.task(taskName, async () => {
25
+ // git on OSX is still inserting a pager somewhere, breaking this, so temporarily
26
+ // disable this test
27
+ if (os.platform() === "darwin") {
28
+ console.warn(
29
+ chalk.redBright(
30
+ `up-to-date verification is experimental on OSX! Please report errors to davydm@gmail.com`
31
+ )
32
+ );
33
+ }
34
+ const
35
+ remoteInfos = (await readAllGitRemotes()) || [],
36
+ remotes = remoteInfos.map(r => r.name),
37
+ mainBranch = env.resolve("GIT_MAIN_BRANCH") || await resolveDefaultVerifyTarget(remotes),
38
+ verifyBranch = env.resolve("GIT_VERIFY_BRANCH") || await readCurrentBranch();
39
+ if (!mainBranch) {
40
+ throw new ZarroError(`Can't determine main branch (try setting env: GIT_MAIN_BRANCH)`);
41
+ }
42
+ if (!verifyBranch) {
43
+ throw new ZarroError(`Can't determine branch to verify (try setting env: GIT_VERIFY_BRANCH)`);
44
+ }
45
+ if (remotes.length && !env.resolveFlag("SKIP_FETCH_ON_VERIFY")) {
46
+ const
47
+ lastFetch = await readLastFetchTime(),
48
+ fetchRecentPeriod = env.resolveNumber("FETCH_RECENT_TIME") * 1000,
49
+ now = Date.now();
50
+ let recentEnough = false;
51
+ if (lastFetch) {
52
+ recentEnough = (now - fetchRecentPeriod) < lastFetch.getTime();
53
+ }
54
+ if (!recentEnough) {
55
+ log.info(`${ taskName } :: fetching all remotes...`);
56
+ const
57
+ git = new Git(),
58
+ timeout = env.resolveNumber("GIT_FETCH_TIMEOUT");
59
+ try {
60
+ const fail = failAfter(timeout);
61
+ await Promise.race([
62
+ git.fetch(["--all"]),
63
+ fail.promise
64
+ ]);
65
+ fail.cancel();
66
+ } catch (e) {
67
+ const msg = e.message || e;
68
+ if (msg === "operation timed out") {
69
+ log.error(chalk.redBright(`fetch operation timed out:
70
+ - check that the current account can fetch from all remotes
71
+ - optionally disable fetch with SKIP_FETCH_ON_VERIFY=1
72
+ - optionally increase GIT_FETCH_TIMEOUT from current value: ${timeout}`))
73
+ }
74
+ }
75
+ } else {
76
+ log.info(`${ taskName } :: skipping fetch: was last done at ${ lastFetch }`);
77
+ }
78
+ }
79
+ const verifyResult = await readGitCommitDeltaCount(
80
+ mainBranch || "master", verifyBranch);
81
+ // TODO: get the delta count & chuck if behind
82
+ const
83
+ aheadS = verifyResult.ahead === 1 ? "" : "s",
84
+ behindS = verifyResult.behind === 1 ? "" : "s",
85
+ message = `${
86
+ chalk.yellow(verifyBranch)
87
+ } is ${
88
+ chalk.green(verifyResult.ahead)
89
+ } commit${ aheadS } ahead and ${
90
+ chalk.red(verifyResult.behind)
91
+ } commit${ behindS } behind ${
92
+ chalk.cyanBright(mainBranch)
93
+ }`;
94
+ log.info(`${ taskName } :: ${ message }`);
95
+
96
+ if (verifyResult.behind > 0) {
97
+ if (env.resolveFlag("ENFORCE_VERIFICATION")) {
98
+ throw new ZarroError(message);
99
+ }
100
+ if (env.resolveFlag("INTERACTIVE")) {
101
+ console.error(`interactive mode for verify-up-to-date is not yet implemented`);
102
+ // TODO: ask if the user would like to merge in master & proceed if ok
103
+ }
104
+ }
105
+ });
106
+
107
+ async function resolveDefaultVerifyTarget(remotes?: string[]) {
108
+ remotes = remotes ?? [];
109
+ const
110
+ mainBranchName = await readMainBranchName(),
111
+ remote = remotes[0];
112
+ if (mainBranchName?.startsWith(`${ remote }/`)) {
113
+ return mainBranchName;
114
+ }
115
+ return remote
116
+ ? `${ remote }/${ mainBranchName }`
117
+ : mainBranchName
118
+ }
119
+ })();
@@ -0,0 +1,31 @@
1
+ (function () {
2
+ module.exports = function containsAny() {
3
+ // should be invoked with an args array followed by a list of things to look for
4
+ let
5
+ args = Array.from(arguments),
6
+ array = args[0] || [];
7
+ if (!Array.isArray(array)) {
8
+ array = [ array ]
9
+ }
10
+ if (array.length === 0) {
11
+ return false;
12
+ }
13
+
14
+ const values = args.slice(1);
15
+ if (values.length === 0) {
16
+ return true;
17
+ }
18
+
19
+ return array.reduce(
20
+ (acc, cur) => {
21
+ if (acc) {
22
+ return acc;
23
+ }
24
+ if (cur === values[0]) {
25
+ return true;
26
+ }
27
+ return containsAny(values.slice(1), cur);
28
+ },
29
+ false);
30
+ };
31
+ })();
@@ -0,0 +1,21 @@
1
+ module.exports = async function gatherArgs(
2
+ potentialEntryPoints,
3
+ overrideArgv // for testing only
4
+ ) {
5
+ const argv = overrideArgv || process.argv;
6
+ if (!Array.isArray(potentialEntryPoints)) {
7
+ potentialEntryPoints = [potentialEntryPoints];
8
+ }
9
+ for (let entryPoint of potentialEntryPoints) {
10
+ const entryPointIndex = argv.indexOf(entryPoint);
11
+ if (entryPointIndex > -1) {
12
+ return argv.slice(entryPointIndex + 1);
13
+ }
14
+ continue;
15
+ }
16
+ throw new Error(`Can't figure out args: unable to find entry point in args list:\n${JSON.stringify({
17
+ potentialEntryPoints,
18
+ overrideArgv,
19
+ argv: process.argv
20
+ }, null, 2)}`);
21
+ };