Skip to content

Commit

Permalink
feat(cli): add "hook-stacks-info-apps" plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei199991 committed Jul 30, 2020
1 parent d79a418 commit b4f570b
Showing 1 changed file with 45 additions and 11 deletions.
56 changes: 45 additions & 11 deletions packages/cwp-template-full/hooks/apps.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
const { green } = require("chalk");
const fs = require("fs");

module.exports = (opts = {}) => ({
type: "hook-stack-after-deploy",
hook(params) {
const stackName = opts.stackName || "apps";
module.exports = (opts = {}) => (
{
type: "hook-stack-after-deploy",
hook(params) {
const stackName = opts.stackName || "apps";

if (params.stack !== stackName) {
return;
if (params.stack !== stackName) {
return;
}

if (params.isFirstDeploy) {
printFirstDeploySummary(params);
} else {
printDeploySummary(params);
}
}
},
{
name: "hook-stacks-info-apps",
type: "hook-stacks-info",
hook() {
const stackName = opts.stackName || "apps";

const info = [];
const stackEnvs = fs.readdirSync(`./.webiny/state/${stackName}`);
for (const stackEnv of stackEnvs) {
const webinyJson = JSON.parse(
fs.readFileSync(`./.webiny/state/apps/${stackEnv}/Webiny.json`).toString()
);
if (!webinyJson.outputs) {
// This env wasn't deployed succesfully
continue;
}
const url = webinyJson.outputs.cdn.url;

if (params.isFirstDeploy) {
printFirstDeploySummary(params);
} else {
printDeploySummary(params);
info.push({ stack: stackName, env: stackEnv, url });
}
if (info.length) {
console.log(` List of URLs for stack "${stackName}"`);
const prettyInfo = info
.map(stackInfo => `${stackInfo.url} [env = "${stackInfo.env}"]`)
.join("\n");
console.log(prettyInfo);
} else {
console.log(`There are no available URLs for stack ${stackName} yet.`);
}
}
}
});
);

function printFirstDeploySummary({ state }) {
if (!state.cdn) {
Expand Down

0 comments on commit b4f570b

Please sign in to comment.