forked from adobe/aem-site-template-standard
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathredeploy.js
94 lines (88 loc) · 3.28 KB
/
redeploy.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const fs = require("fs");
const startTime = Date.now();
const child_process = require("child_process");
const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
const AEM_URL = process.env.AEM_URL;
const SITE_NAME = process.env.AEM_SITE;
// Need to make a way for this to exist throughout the entire example content
const TMPL_NAME = packageJSON.name;
const CREDENTIALS = process.env.CREDENTIALS || "admin:admin";
let VERSION = packageJSON.version;
let [major, minor, patch] = packageJSON.version.split(".");
const deletePreviousZip = () => {
if (fs.existsSync(`./${TMPL_NAME}-${VERSION}.zip`))
runCmd(`rm ${TMPL_NAME}-${VERSION}.zip`);
else console.log(`Could not find or delete ${TMPL_NAME}-${VERSION}.zip`);
};
const updatePackageJSON = () => {
packageJSON.version = [major, minor, parseInt(patch) + 1]
.join(".")
.toString();
fs.writeFileSync("./package.json", JSON.stringify(packageJSON, null, 2));
console.log(
`Package.json updated to v${packageJSON.version} from v${VERSION}`
);
VERSION = packageJSON.version;
};
const runCmd = (cmd, log) => {
const resp = child_process.execSync(cmd);
const result = resp.toString("UTF8");
if (log) console.log(result);
return result;
};
const log = (msg) => {
console.log(`\n\n${"~".repeat(120)}`);
console.log(` ${msg}`);
console.log("~".repeat(120));
};
log(`Removing Site Configurations - /conf/${SITE_NAME}`);
runCmd(
`curl -u ${CREDENTIALS} -F ':operation=delete' ${AEM_URL}/conf/${SITE_NAME}`
);
log(`Removing DAM Content - /content/dam/${SITE_NAME}`);
runCmd(
`curl -u ${CREDENTIALS} -F ':operation=delete' ${AEM_URL}/content/dam/${SITE_NAME}`
);
log(
`Removing Experience Fragments - ${AEM_URL}/content/experience-fragments/${SITE_NAME}`
);
runCmd(
`curl -u ${CREDENTIALS} -F ':operation=delete' ${AEM_URL}/content/experience-fragments/${SITE_NAME}`
);
log(`Removing Content - /content/${SITE_NAME}`);
runCmd(
`curl -u ${CREDENTIALS} -F ':operation=delete' ${AEM_URL}/content/${SITE_NAME}`
);
log(
`Removing Site Template - /conf/global/site-templates/${TMPL_NAME}-${VERSION}`
);
runCmd(
`curl -u ${CREDENTIALS} -F ':operation=delete' ${AEM_URL}/conf/global/site-templates/${TMPL_NAME}-${VERSION}`
);
log(`Removing Previous Zip File ${TMPL_NAME}-${VERSION}.zip`);
deletePreviousZip();
log(`Updating package.json with new versioning`);
updatePackageJSON();
log(`Building Site Template v${VERSION}`);
runCmd(`npm run build`, true);
log(`Deploying ${TMPL_NAME}-${VERSION}.zip to ${AEM_URL}`);
runCmd(
`curl -u ${CREDENTIALS} -F file=@${TMPL_NAME}-${VERSION}.zip ${AEM_URL}/bin/wcm/site-template/import`
);
log(`Re-generatinig '${SITE_NAME}' site from template`);
runCmd(
`curl -u ${CREDENTIALS} -F 'cmd=createSiteFromSiteTemplate' -F 'operation=asyncCreateSiteFromSiteTemplate' -F '_charset_=utf-8' -F 'siteTemplate=/conf/global/site-templates/${TMPL_NAME}-${VERSION}' -F 'siteTitle=${SITE_NAME}' ${AEM_URL}/bin/asynccommand`
);
log(
`Successfully redeployed Site Template v${VERSION} in ${
(Date.now() - startTime) / 1000
}s`
);
// /bin/asynccommand
// cmd: createSiteFromSiteTemplate
// operation: asyncCreateSiteFromSiteTemplate
// _charset_: utf-8
// siteTitle: aem-site-template-tailwind
// siteName:
// path: aem-site-template-tailwind
// siteTemplatePath: /conf/global/site-templates/aem-site-template-tailwind-1.23.21