This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate-self.js
67 lines (67 loc) · 2.67 KB
/
update-self.js
1
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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
(function () {
const spawn = requireModule("spawn"), gulp = requireModule("gulp"), env = requireModule("env"), chalk = requireModule("ansi-colors"), resolveMasks = requireModule("resolve-masks"), debug = requireModule("debug")(__filename), es = require("event-stream");
env.associate([
env.DRY_RUN,
env.INCLUDE_PACKAGE_JSON,
env.EXCLUDE_PACKAGE_JSON
], "update-self");
gulp.task("update-self", "Updates zarro throughout your current project", () => {
const glob = resolveMasks(env.INCLUDE_PACKAGE_JSON, env.EXCLUDE_PACKAGE_JSON);
debug({
glob
});
return gulp.src(glob)
.pipe(updateZarroPipe(env.resolveFlag(env.BETA)));
});
function updateZarroPipe(beta) {
const promises = [];
return es.through(function input(file) {
let save = false, saveDev = false;
const json = file.contents.toString();
try {
const search = "zarro", packageIndex = JSON.parse(json), deps = packageIndex.dependencies || {}, devDeps = packageIndex.devDependencies || {};
save = Object.keys(deps).includes(search);
saveDev = Object.keys(devDeps).includes(search);
if (!save && !saveDev) {
debug(`${search} not installed in ${file.path}`);
return;
}
}
catch (e) {
debug(`${file.path} is not valid JSON`);
return;
}
console.log(chalk.yellow(`update zarro in: ${file.dirname}`));
const proc = "npm", tag = beta ? "beta" : "latest", args = ["install", save ? "--save" : "--save-dev", `zarro@${tag}`, "--no-progress", "--silent"], opts = {
cwd: file.dirname,
interactive: true
};
if (env.resolveFlag(env.DRY_RUN)) {
console.log({
label: "would run spawn with",
proc,
args,
opts
});
}
else {
promises.push(spawn.call(null, proc, args, opts));
}
}, async function end() {
try {
await Promise.all(promises);
this.emit("end");
}
catch (err) {
console.error(chalk.redBright(`
==================================================
| WARNING: Unable to update zarro, error(s) follow |
==================================================
`));
this.emit("error", err);
}
});
}
})();