@bluealba/carryall
Advanced tools
Comparing version 1.0.5 to 1.0.7
38
index.js
@@ -9,15 +9,37 @@ #!/usr/bin/env node | ||
const parseConfig = (program, defaultReporter) => { | ||
const config = JSON.parse(fs.readFileSync(program.config || "./carryall.json", { "encoding": "UTF-8" })); | ||
config.reporter.mode = program.reporter || defaultReporter; | ||
config.control = { silent: !!program.silent, noRestart: !program.restart } | ||
return config; | ||
} | ||
program | ||
.version(ownVersion.version) | ||
.option("-c", "--config <path>", "Change the configuration file. Defaults to carryall.json") | ||
.option("-c", "--config <path>", "Change the configuration file. Defaults to carryall.json"); | ||
program | ||
.command("deploy") | ||
.description("Updates the environment installation to match versions in the descriptor") | ||
.option("--reporter <reporter>", "Which reporter to use [cli|slack|combined]. Defaults to combined") | ||
.option("-s, --silent", "Silent mode, will not prompt for any action") | ||
.option("-R, --no-restart", "Do not perform a service restart") | ||
.parse(process.argv); | ||
.action(program => { | ||
const config = parseConfig(program, "combined"); | ||
new Carryall().deploy(config) | ||
}); | ||
const config = JSON.parse(fs.readFileSync(program.config || "./carryall.json", { "encoding": "UTF-8" })); | ||
config.control = { | ||
silent: program.silent, | ||
noRestart: !program.restart, | ||
} | ||
program | ||
.command("list") | ||
.description("Query the current state of the environment") | ||
.option("--reporter <reporter>", "Which reporter to use [cli|slack|combined]. Defaults to cli") | ||
.action(program => { | ||
const config = parseConfig(program, "cli"); | ||
new Carryall().state(config) | ||
}); | ||
new Carryall().deploy(config) | ||
program.parse(process.argv) | ||
@@ -18,4 +18,18 @@ "use strict"; | ||
this.deploy = co.wrap(this.deploy.bind(this)); | ||
this.state = co.wrap(this.state.bind(this)); | ||
this.reportState = co.wrap(this.reportState.bind(this)); | ||
} | ||
* state(config) { | ||
const reporter = this.reporterFactory(config); | ||
const descriptor = yield this.descriptorFactory(config); | ||
this.reportState(reporter, descriptor, []); | ||
} | ||
* reportState(reporter, descriptor) { | ||
const newState = yield descriptor.inspectEnvironment(); | ||
const pendingActions = yield descriptor.requiredActions(); //should be empty | ||
reporter.reportCurrentState(newState, pendingActions); | ||
} | ||
* deploy(config) { | ||
@@ -22,0 +36,0 @@ const control = this.controlFactory(config); |
@@ -6,2 +6,3 @@ "use strict"; | ||
const co = require("co"); | ||
const crypto = require("crypto"); | ||
const inspectEnvironment = require("./util/inspectEnvironment"); | ||
@@ -59,4 +60,11 @@ const { keys, prop } = require("ramda"); | ||
git: co.wrap(function* (config) { | ||
const target = path.join(config.workdir, "" + Date.now()); | ||
yield git({ password: config.descriptor.password })("clone", "--depth 1", "--branch", config.descriptor.branch, "--", config.descriptor.repositoryUrl, target); | ||
const hash = crypto.createHash("md5").update(config.descriptor.repositoryUrl).digest("hex"); | ||
const target = path.join(config.workdir, hash); | ||
if (fs.existsSync(target)) { | ||
yield git({ password: config.descriptor.password, cwd: target })("checkout", config.descriptor.branch); | ||
yield git({ password: config.descriptor.password, cwd: target })("pull"); | ||
} else { | ||
yield git({ password: config.descriptor.password })("clone", "--depth 1", "--branch", config.descriptor.branch, "--", config.descriptor.repositoryUrl, target); | ||
} | ||
return new Promise((resolve, reject) => fs.readFile(path.join(target, "package.json"), (err, data) => { | ||
@@ -63,0 +71,0 @@ err ? reject(err) : resolve(new Descriptor(JSON.parse(data))); |
@@ -40,8 +40,19 @@ "use strict"; | ||
reportCurrentState(currentEnvironment, actionsNeeded) { | ||
this.print("Current state:") | ||
this.reportEnvironment(currentEnvironment, [], actionsNeeded, true); | ||
this.print() | ||
} | ||
reportActionsDone(currentEnvironment, actionsDone, actionsNeeded) { | ||
this.print(`Deploy finished on ${this.format.bold(this.environment)}. ${this.onlyUpgrades ? "Actions" : "Current state"}:`) | ||
this.print("Deploy finished. Actions done:"); | ||
this.reportEnvironment(currentEnvironment, actionsDone, actionsNeeded, false); | ||
this.print() | ||
} | ||
reportEnvironment(currentEnvironment, actionsDone, actionsNeeded, printAll) { | ||
toPairs(currentEnvironment).forEach(([artifact, current]) => { | ||
const actionDone = actionsDone.find(propEq("artifact", artifact)) | ||
const actionPending = actionsNeeded.find(propEq("artifact", artifact)) | ||
if (!this.onlyUpgrades || actionPending || actionDone) { | ||
if (printAll || actionPending || actionDone) { | ||
this.printPackageState({ | ||
@@ -56,3 +67,2 @@ artifact, | ||
}); | ||
this.print() | ||
} | ||
@@ -101,3 +111,2 @@ | ||
this.channel = config.reporter.slack.channel; | ||
this.onlyUpgrades = !!config.reporter.slack.onlyUpgrades; | ||
this.format = { | ||
@@ -140,2 +149,9 @@ bold: x => `*${x}*`, | ||
reportCurrentState(currentEnvironment, actionsNeeded) { | ||
this.clear(); | ||
super.reportCurrentState(currentEnvironment, actionsNeeded); | ||
this.flush(); | ||
} | ||
} | ||
@@ -165,4 +181,12 @@ | ||
const slackReporter = new SlackReporter(config); | ||
return new CompositeReporter(consoleReporter, slackReporter); | ||
const combinedReporter = new CompositeReporter(consoleReporter, slackReporter); | ||
if (config.reporter.mode === "cli") { | ||
return consoleReporter; | ||
} else if (config.reporter.mode === "slack") { | ||
return slackReporter; | ||
} else { | ||
return combinedReporter; | ||
} | ||
} | ||
} |
@@ -9,5 +9,5 @@ "use strict"; | ||
return new Promise((resolve, reject) => { | ||
const child = spawn(`git ${parameters.join(" ")}`, { | ||
const child = spawn("time git", parameters, { | ||
cwd, | ||
stdio: ["inherit", "pipe", "pipe"], | ||
stdio: ["ignore", "pipe", "pipe"], | ||
shell: true, | ||
@@ -14,0 +14,0 @@ env: { |
{ | ||
"name": "@bluealba/carryall", | ||
"version": "1.0.5", | ||
"version": "1.0.7", | ||
"description": "An easy way to keep your environments in sync", | ||
@@ -27,2 +27,3 @@ "main": "index.js", | ||
"promisify-fs": "^1.0.39", | ||
"promisify-git": "^1.1.22", | ||
"ramda": "^0.26.1", | ||
@@ -29,0 +30,0 @@ "semver": "^5.6.0", |
Sorry, the diff of this file is not supported yet
486
255434
12
+ Addedpromisify-git@^1.1.22
+ Addedpromisify-bash@1.0.0(transitive)
+ Addedpromisify-git@1.1.22(transitive)