@raisenow/tamaro-cli 1.7.0-dev.0 → 1.7.0-dev.1
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.
- package/.eslintignore +7 -0
- package/.eslintrc.cjs +148 -0
- package/.history/.eslintignore_20220609190420 +4 -0
- package/.history/.eslintignore_20230911190227 +6 -0
- package/.history/.eslintignore_20230911211247 +7 -0
- package/.history/.eslintignore_20230911211250 +7 -0
- package/.history/.eslintrc_20230911201601.js +49 -0
- package/.history/.eslintrc_20230911201643.js +49 -0
- package/.history/.eslintrc_20230911201735.js +49 -0
- package/.history/.eslintrc_20230911201913.js +64 -0
- package/.history/.eslintrc_20230911202002.js +62 -0
- package/.history/.eslintrc_20230911202138.js +133 -0
- package/.history/.eslintrc_20230911202140.js +133 -0
- package/.history/.eslintrc_20230911202145.js +133 -0
- package/.history/.eslintrc_20230911202147.js +133 -0
- package/.history/.eslintrc_20230911202406.js +133 -0
- package/.history/.eslintrc_20230911202447.js +133 -0
- package/.history/.eslintrc_20230911202453.js +133 -0
- package/.history/.eslintrc_20230911202511.js +133 -0
- package/.history/.eslintrc_20230911202527.js +133 -0
- package/.history/.eslintrc_20230911202639.js +125 -0
- package/.history/.eslintrc_20230911202721.js +149 -0
- package/.history/.eslintrc_20230911202746.js +149 -0
- package/.history/.eslintrc_20240423125702.cjs +148 -0
- package/.history/.gitignore_20220609190420 +14 -0
- package/.history/.gitignore_20230911185959 +4 -0
- package/.history/.gitignore_20230911190006 +4 -0
- package/.history/.gitignore_20230911190007 +4 -0
- package/.history/.nmprc_20241004144025 +0 -0
- package/.history/.nmprc_20241004144041 +1 -0
- package/.history/.npmrc_20241004144040 +1 -0
- package/.history/.npmrc_20241004144152 +1 -0
- package/.history/.npmrc_20241004145639 +2 -0
- package/.history/.npmrc_20241004145649 +1 -0
- package/.history/.nvmrc_20250729181039 +1 -0
- package/.history/.prettierignore_20220609190420 +5 -0
- package/.history/.prettierignore_20230911190242 +7 -0
- package/.history/.prettierignore_20230911190245 +7 -0
- package/.history/.prettierignore_20230911211301 +8 -0
- package/.history/CHANGELOG_20250729195139.md +28 -0
- package/.history/CHANGELOG_20250729195148.md +29 -0
- package/.history/CHANGELOG_20250729195156.md +28 -0
- package/.history/CHANGELOG_20250729195218.md +29 -0
- package/.history/CHANGELOG_20250729195223.md +27 -0
- package/.history/CHANGELOG_20250729195506.md +29 -0
- package/.history/CHANGELOG_20250729224404.md +30 -0
- package/.history/CHANGELOG_20250729224411.md +30 -0
- package/.history/CHANGELOG_20250730124538.md +41 -0
- package/.history/CHANGELOG_20250730124603.md +38 -0
- package/.history/CHANGELOG_20250730124627.md +36 -0
- package/.history/CHANGELOG_20250730124638.md +36 -0
- package/.history/CHANGELOG_20250730124640.md +36 -0
- package/.history/README_20230911145033.md +245 -0
- package/.history/README_20230911151749.md +245 -0
- package/.history/README_20230911151844.md +245 -0
- package/.history/README_20230911153040.md +245 -0
- package/.history/README_20230911202959.md +245 -0
- package/.history/bitbucket-pipelines_20250729111540.yml +46 -0
- package/.history/bitbucket-pipelines_20250729210338.yml +46 -0
- package/.history/bitbucket-pipelines_20250729210340.yml +46 -0
- package/.history/bitbucket-pipelines_20250729210342.yml +46 -0
- package/.history/bitbucket-pipelines_20250729222234.yml +47 -0
- package/.history/bitbucket-pipelines_20250729222554.yml +47 -0
- package/.history/bitbucket-pipelines_20250729222555.yml +47 -0
- package/.history/bitbucket-pipelines_20250729223022.yml +46 -0
- package/.history/bitbucket-pipelines_20250729223024.yml +46 -0
- package/.history/cli_20241005014539 +3 -0
- package/.history/cli_20241005014542 +3 -0
- package/.history/cli_20241005014848 +3 -0
- package/.history/dist/chunk-FICM3HUI_20230912183408.js +302 -0
- package/{dist/chunk-ALQDGTID.js → .history/dist/chunk-FICM3HUI_20230912201610.js} +45 -150
- package/.history/package_20250729182417.json +111 -0
- package/.history/package_20250729182419.json +111 -0
- package/.history/package_20250729182618.json +110 -0
- package/.history/package_20250729182834.json +110 -0
- package/.history/package_20250729183032.json +110 -0
- package/.history/package_20250729183033.json +110 -0
- package/.history/package_20250729185750.json +110 -0
- package/.history/package_20250729185815.json +110 -0
- package/.history/package_20250729185846.json +110 -0
- package/.history/package_20250729185854.json +110 -0
- package/.history/package_20250729185943.json +110 -0
- package/.history/package_20250729190645.json +110 -0
- package/.history/package_20250729195934.json +110 -0
- package/.history/package_20250729200013.json +110 -0
- package/.history/package_20250729200056.json +110 -0
- package/.history/package_20250729200434.json +110 -0
- package/.history/package_20250729200808.json +110 -0
- package/.history/package_20250729200944.json +110 -0
- package/.history/package_20250729214420.json +114 -0
- package/.history/package_20250729223112.json +110 -0
- package/.history/package_20250729223127.json +110 -0
- package/.history/package_20250729223134.json +110 -0
- package/.history/package_20250730124647.json +114 -0
- package/.history/tsconfig_20241005001442.json +34 -0
- package/.history/tsconfig_20241005001500.json +34 -0
- package/.history/tsconfig_20241005001540.json +34 -0
- package/.history/tsconfig_20241005014429.json +42 -0
- package/.history/tsconfig_20241005014436.json +42 -0
- package/.history/tsconfig_20241005014439.json +38 -0
- package/.history/tsconfig_20241005014455.json +38 -0
- package/.history/tsconfig_20241005014521.json +38 -0
- package/.history/vitest.config_20250729214539.ts +0 -0
- package/.history/vitest.config_20250729214659.ts +24 -0
- package/.history/vitest.config_20250729214748.ts +21 -0
- package/.history/vitest.config_20250729214825.ts +21 -0
- package/.history/vitest.config_20250729214902.ts +21 -0
- package/.history/vitest.config_20250729222125.ts +20 -0
- package/.history/vitest.config_20250729222213.ts +20 -0
- package/.idea/codeStyles/Project.xml +131 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +17 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/tamaro-cli.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.nvmrc +1 -0
- package/.prettierignore +8 -0
- package/.prettierrc.cjs +19 -0
- package/bitbucket-pipelines.yml +47 -0
- package/dist/cli.js +754 -1428
- package/dist/env-C_Jkayak.js +261 -0
- package/dist/webpack.config.js +310 -441
- package/package.json +19 -30
- package/renovate.json +3 -0
- package/tsdown.config.ts +11 -0
- package/vitest.config.ts +20 -0
package/dist/cli.js
CHANGED
|
@@ -1,709 +1,361 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
AWS_CLOUDFRONT_DISTRIBUTION_ID,
|
|
4
|
-
AWS_S3_BUCKET_TAMARO,
|
|
5
|
-
AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD,
|
|
6
|
-
AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE,
|
|
7
|
-
CACHE_DIR,
|
|
8
|
-
CORE_CONFIG_NAME,
|
|
9
|
-
DEFAULT_PORT,
|
|
10
|
-
DEFAULT_TAG,
|
|
11
|
-
EPMS_API_BASE_URL_PROD,
|
|
12
|
-
EPMS_API_BASE_URL_STAGE,
|
|
13
|
-
HTTPS_CRT_FILE,
|
|
14
|
-
HTTPS_KEY_FILE,
|
|
15
|
-
applyEnv,
|
|
16
|
-
assertEnvValid,
|
|
17
|
-
getIfCoreFns,
|
|
18
|
-
getPaths,
|
|
19
|
-
getWidgetUuid,
|
|
20
|
-
halt,
|
|
21
|
-
logCommand,
|
|
22
|
-
logDataTable,
|
|
23
|
-
logError,
|
|
24
|
-
logSuccess,
|
|
25
|
-
logTitle,
|
|
26
|
-
promptConfirmation,
|
|
27
|
-
resolveAccountUuidFromConfig,
|
|
28
|
-
resolveBin,
|
|
29
|
-
resolveCoreVersion,
|
|
30
|
-
resolveOwn,
|
|
31
|
-
runCommandSync
|
|
32
|
-
} from "./chunk-ALQDGTID.js";
|
|
33
|
-
|
|
34
|
-
// src/cli.ts
|
|
2
|
+
import { C as promptConfirmation, D as logError, E as logDataTable, O as logSuccess, S as halt, T as logCommand, _ as getWidgetUuid, a as AWS_S3_BUCKET_TAMARO, c as CORE_CONFIG_NAME, d as HTTPS_CRT_FILE, f as HTTPS_KEY_FILE, h as getPaths, i as AWS_CLOUDFRONT_DISTRIBUTION_ID, k as logTitle, l as DEFAULT_PORT, m as getIfCoreFns, n as assertEnvValid, o as AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD, s as AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE, t as applyEnv, u as DEFAULT_TAG, w as runCommandSync, x as resolveOwn, y as resolveBin } from "./env-C_Jkayak.js";
|
|
35
3
|
import { createCommand } from "commander";
|
|
36
|
-
|
|
37
|
-
// src/commands/archive.ts
|
|
38
4
|
import { existsSync, mkdirSync, renameSync } from "fs";
|
|
39
5
|
import { basename, dirname, resolve } from "path";
|
|
40
|
-
|
|
41
|
-
// src/lib/aws.ts
|
|
42
6
|
import { execaCommandSync } from "execa";
|
|
43
7
|
import prompts from "prompts";
|
|
44
8
|
import stripIndent from "strip-indent";
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
9
|
+
import notifier from "node-notifier";
|
|
10
|
+
import { globSync } from "glob";
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
import Handlebars from "handlebars";
|
|
13
|
+
import helpers from "handlebars-helpers";
|
|
14
|
+
import { getPortPromise } from "portfinder";
|
|
15
|
+
|
|
16
|
+
//#region src/lib/aws.ts
|
|
17
|
+
const awsAuthenticate = (options) => {
|
|
18
|
+
if (options.ci)
|
|
19
|
+
/**
|
|
20
|
+
* Don't try to authenticate the user.
|
|
21
|
+
* This is done when CLI is running within an automated system like pipeline,
|
|
22
|
+
* In this case "AWS_ACCESS_KEY_ID" and "AWS_SECRET_ACCESS_KEY" are used instead of "AWS_PROFILE".
|
|
23
|
+
*/
|
|
24
|
+
return;
|
|
25
|
+
try {
|
|
26
|
+
checkIdentity(options);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
login(options);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const assertProfilesPresent = () => {
|
|
32
|
+
if (getAvailableProfiles().length === 0) halt(stripIndent(`
|
|
60
33
|
No AWS profiles found.
|
|
61
34
|
Run "aws configure sso" to set up SSO-enabled profile.
|
|
62
35
|
Check the wiki for more information:
|
|
63
36
|
https://raisenow.atlassian.net/wiki/x/lIrWvg
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
37
|
+
`));
|
|
38
|
+
};
|
|
39
|
+
const getAvailableProfiles = () => {
|
|
40
|
+
const { stdout } = execaCommandSync("aws configure list-profiles");
|
|
41
|
+
return stdout.split("\n");
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Returns caller identity data (output is ignored here).
|
|
45
|
+
* Fails in case of expired SSO session.
|
|
46
|
+
*/
|
|
47
|
+
const checkIdentity = (options) => {
|
|
48
|
+
execaCommandSync(`aws sts get-caller-identity ${prepareFlags$3(options)}`);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Opens SSO authentication page in the browser.
|
|
52
|
+
* Fails if user canceled authentication process.
|
|
53
|
+
*/
|
|
54
|
+
const login = (options) => {
|
|
55
|
+
const flags = prepareFlags$3(options);
|
|
56
|
+
try {
|
|
57
|
+
execaCommandSync(`aws sso login ${flags}`, { stdio: "inherit" });
|
|
58
|
+
console.log("");
|
|
59
|
+
} catch (error) {
|
|
60
|
+
halt("Login failed.");
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const prepareFlags$3 = (options) => {
|
|
64
|
+
const flags = [];
|
|
65
|
+
const { profile } = options;
|
|
66
|
+
if (profile) flags.push(`--profile ${profile}`);
|
|
67
|
+
return flags.join(" ");
|
|
68
|
+
};
|
|
69
|
+
const assertProfileValid = (profile) => {
|
|
70
|
+
const profiles = getAvailableProfiles();
|
|
71
|
+
if (!profiles.includes(profile)) halt(stripIndent(`
|
|
98
72
|
AWS profile "${profile}" is not found.
|
|
99
73
|
Available profiles are: ${profiles.map((v) => `"${v}"`).join(", ")}.
|
|
100
|
-
`)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
],
|
|
115
|
-
{
|
|
116
|
-
onCancel: () => halt()
|
|
117
|
-
}
|
|
118
|
-
);
|
|
119
|
-
return profile;
|
|
74
|
+
`));
|
|
75
|
+
};
|
|
76
|
+
const promptProfile = async () => {
|
|
77
|
+
const { profile } = await prompts([{
|
|
78
|
+
type: "select",
|
|
79
|
+
name: "profile",
|
|
80
|
+
message: "Select AWS profile",
|
|
81
|
+
choices: getAvailableProfiles().filter((v) => !!v).map((v) => ({
|
|
82
|
+
title: v,
|
|
83
|
+
value: v
|
|
84
|
+
}))
|
|
85
|
+
}], { onCancel: () => halt() });
|
|
86
|
+
return profile;
|
|
120
87
|
};
|
|
121
88
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
});
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/lib/notifier.ts
|
|
91
|
+
const notify = (args) => {
|
|
92
|
+
const { title, message = "" } = args;
|
|
93
|
+
notifier.notify({
|
|
94
|
+
title,
|
|
95
|
+
message: stripIndent(message).trim(),
|
|
96
|
+
contentImage: "https://assets.raisenow.io/favicon.png",
|
|
97
|
+
sound: "Funk"
|
|
98
|
+
});
|
|
133
99
|
};
|
|
134
100
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
};
|
|
173
|
-
var assertIsNotCore = (ifCore) => {
|
|
174
|
-
if (ifCore()) {
|
|
175
|
-
halt("You cannot archive Tamaro Core.");
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
var assertIsNotArchived = () => {
|
|
179
|
-
const parentDirName = basename(dirname(process.cwd()));
|
|
180
|
-
if (parentDirName === "_archived") {
|
|
181
|
-
halt("This configuration is already archived.");
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
var assertArchiveTargetDoesNotExist = (archiveTarget) => {
|
|
185
|
-
if (existsSync(archiveTarget)) {
|
|
186
|
-
halt(
|
|
187
|
-
`Archive target already exists: ${archiveTarget}. Please remove it first.`
|
|
188
|
-
);
|
|
189
|
-
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/commands/archive.ts
|
|
103
|
+
const archive = (options) => {
|
|
104
|
+
const { ifCore } = getIfCoreFns();
|
|
105
|
+
assertIsNotCore$3(ifCore);
|
|
106
|
+
assertIsNotArchived();
|
|
107
|
+
const configName = getWidgetUuid();
|
|
108
|
+
const cwd = process.cwd();
|
|
109
|
+
const archiveDir = resolve(dirname(cwd), "_archived");
|
|
110
|
+
const archiveTarget = resolve(archiveDir, configName);
|
|
111
|
+
assertArchiveTargetDoesNotExist(archiveTarget);
|
|
112
|
+
assertOptionsValid$9(options);
|
|
113
|
+
if (options.dryrun) logTitle("🧪 DRY RUN MODE - No actual changes will be made 🧪");
|
|
114
|
+
if (!options.dryrun) {
|
|
115
|
+
if (!existsSync(archiveDir)) mkdirSync(archiveDir, { recursive: true });
|
|
116
|
+
renameSync(cwd, archiveTarget);
|
|
117
|
+
} else logTitle(`Would move ${cwd} → ${archiveTarget}`);
|
|
118
|
+
logSuccess(`\n✅ "${configName}" has been archived and moved to ${archiveTarget}`);
|
|
119
|
+
process.on("exit", () => {
|
|
120
|
+
notify({
|
|
121
|
+
title: "archive",
|
|
122
|
+
message: `"${configName}" has been archived.`
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
const assertOptionsValid$9 = (options) => {
|
|
127
|
+
const { profile } = options;
|
|
128
|
+
if (profile) assertProfileValid(profile);
|
|
129
|
+
};
|
|
130
|
+
const assertIsNotCore$3 = (ifCore) => {
|
|
131
|
+
if (ifCore()) halt("You cannot archive Tamaro Core.");
|
|
132
|
+
};
|
|
133
|
+
const assertIsNotArchived = () => {
|
|
134
|
+
if (basename(dirname(process.cwd())) === "_archived") halt("This configuration is already archived.");
|
|
135
|
+
};
|
|
136
|
+
const assertArchiveTargetDoesNotExist = (archiveTarget) => {
|
|
137
|
+
if (existsSync(archiveTarget)) halt(`Archive target already exists: ${archiveTarget}. Please remove it first.`);
|
|
190
138
|
};
|
|
191
139
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
var compileEmailTemplate = (template) => {
|
|
298
|
-
const compiled = Handlebars.compile(template);
|
|
299
|
-
compiled({});
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/lib/validators/validateEmailTemplates.ts
|
|
142
|
+
/**
|
|
143
|
+
* Register custom Handlebars helpers - the same, which are used in the Email Service.
|
|
144
|
+
* Make sure to update it if new helpers are added in the Email Service.
|
|
145
|
+
*/
|
|
146
|
+
helpers.comparison({ handlebars: Handlebars });
|
|
147
|
+
/**
|
|
148
|
+
* Recurse through the expected email templates folder and attempt to parse
|
|
149
|
+
* handlebars template to validate their syntax.
|
|
150
|
+
*/
|
|
151
|
+
const validateEmailTemplates = (templatePaths) => {
|
|
152
|
+
const errors = [];
|
|
153
|
+
for (const templatePath of templatePaths) try {
|
|
154
|
+
const template = fs.readFileSync(templatePath, "utf-8");
|
|
155
|
+
assureOnlySupportedHelpers(template);
|
|
156
|
+
compileEmailTemplate(template);
|
|
157
|
+
console.log(`${templatePath} is a valid email template`);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
errors.push(`${templatePath} is invalid`);
|
|
160
|
+
errors.push(e);
|
|
161
|
+
}
|
|
162
|
+
return errors;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Validate that only supported Handlebars helpers are used in the template.
|
|
166
|
+
* This function extracts helpers from the template AST and checks them
|
|
167
|
+
* against a predefined set of supported helpers.
|
|
168
|
+
*/
|
|
169
|
+
const assureOnlySupportedHelpers = (template) => {
|
|
170
|
+
/**
|
|
171
|
+
* Recursively extract helpers from the AST
|
|
172
|
+
*/
|
|
173
|
+
const extractHelpers = (ast) => {
|
|
174
|
+
const usedHelpers = /* @__PURE__ */ new Set();
|
|
175
|
+
const extractHelperName = (node) => {
|
|
176
|
+
if (node.path?.type === "PathExpression" && (node.params?.length > 0 || node.hash?.pairs?.length > 0)) return node.path?.original;
|
|
177
|
+
};
|
|
178
|
+
const visit = (node) => {
|
|
179
|
+
if (!node) return;
|
|
180
|
+
switch (node.type) {
|
|
181
|
+
case "MustacheStatement":
|
|
182
|
+
case "BlockStatement": {
|
|
183
|
+
const name = extractHelperName(node);
|
|
184
|
+
if (name) usedHelpers.add(name);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Recursively visit children of the AST node.
|
|
190
|
+
*/
|
|
191
|
+
for (const key in node) {
|
|
192
|
+
const value = node[key];
|
|
193
|
+
if (Array.isArray(value)) value.forEach(visit);
|
|
194
|
+
else if (value && typeof value === "object" && value.type) visit(value);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
visit(ast);
|
|
198
|
+
return usedHelpers;
|
|
199
|
+
};
|
|
200
|
+
const usedHelpers = extractHelpers(Handlebars.parse(template));
|
|
201
|
+
const supportedHelpers = new Set([
|
|
202
|
+
"if",
|
|
203
|
+
"unless",
|
|
204
|
+
"each",
|
|
205
|
+
"with",
|
|
206
|
+
"log",
|
|
207
|
+
"lookup",
|
|
208
|
+
"and",
|
|
209
|
+
"compare",
|
|
210
|
+
"contains",
|
|
211
|
+
"default",
|
|
212
|
+
"eq",
|
|
213
|
+
"gt",
|
|
214
|
+
"gte",
|
|
215
|
+
"has",
|
|
216
|
+
"isFalsey",
|
|
217
|
+
"isTruthy",
|
|
218
|
+
"ifEven",
|
|
219
|
+
"ifNth",
|
|
220
|
+
"ifOdd",
|
|
221
|
+
"is",
|
|
222
|
+
"isnt",
|
|
223
|
+
"lt",
|
|
224
|
+
"lte",
|
|
225
|
+
"neither",
|
|
226
|
+
"not",
|
|
227
|
+
"or",
|
|
228
|
+
"unlessEq",
|
|
229
|
+
"unlessGt",
|
|
230
|
+
"unlessLt",
|
|
231
|
+
"unlessGteq",
|
|
232
|
+
"unlessLteq"
|
|
233
|
+
]);
|
|
234
|
+
const unsupportedHelpers = Array.from(usedHelpers).filter((h) => !supportedHelpers.has(h));
|
|
235
|
+
if (unsupportedHelpers.length > 0) throw new Error(`Email template uses unsupported Handlebars helpers: ${unsupportedHelpers.join(", ")}`);
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Compile Email template and pass an empty context to validate syntax.
|
|
239
|
+
*/
|
|
240
|
+
const compileEmailTemplate = (template) => {
|
|
241
|
+
Handlebars.compile(template)({});
|
|
300
242
|
};
|
|
301
243
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/commands/validate.ts
|
|
246
|
+
/**
|
|
247
|
+
* Validates the current Tamaro configuration to avoid common errors.
|
|
248
|
+
*
|
|
249
|
+
* The command description is kept generic on purpose. We check for a number
|
|
250
|
+
* of mistakes observed when tamaro configurations are manually edited and
|
|
251
|
+
* deployed.
|
|
252
|
+
*/
|
|
253
|
+
const validate = async () => {
|
|
254
|
+
const errors = validateEmailTemplates(globSync("email-config/templates/**/*.hbs").sort());
|
|
255
|
+
if (errors.length) halt(errors.map((el) => el.toString()).join("\n"));
|
|
256
|
+
logTitle("Validated successfully");
|
|
311
257
|
};
|
|
312
258
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if (existsSync2(certFile) && existsSync2(keyFile)) {
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
halt(
|
|
326
|
-
stripIndent3(`
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/lib/https.ts
|
|
261
|
+
const assertCrtExists = () => {
|
|
262
|
+
const { ifCore } = getIfCoreFns();
|
|
263
|
+
const paths = getPaths(ifCore);
|
|
264
|
+
const certFile = resolve(paths.root, HTTPS_CRT_FILE);
|
|
265
|
+
const keyFile = resolve(paths.root, HTTPS_KEY_FILE);
|
|
266
|
+
if (existsSync(certFile) && existsSync(keyFile)) return;
|
|
267
|
+
halt(stripIndent(`
|
|
327
268
|
Flag "--https" is used, but "${HTTPS_CRT_FILE}" and/or "${HTTPS_KEY_FILE}" files are not found.
|
|
328
269
|
You need to generate certificate first.
|
|
329
270
|
Check docs: https://unpkg.com/@raisenow/tamaro-cli/readme.html#/?id=use-transport-level-security-https
|
|
330
|
-
`)
|
|
331
|
-
);
|
|
271
|
+
`));
|
|
332
272
|
};
|
|
333
273
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const wpConfig = resolveOwn("dist/webpack.config.js");
|
|
354
|
-
const cmd = `
|
|
355
|
-
${wpBin}
|
|
356
|
-
--config ${wpConfig}
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/commands/build.ts
|
|
276
|
+
const build = async (options) => {
|
|
277
|
+
const { env } = options;
|
|
278
|
+
applyEnv(env);
|
|
279
|
+
if (options.deploy && !options.profile && !options.ci) {
|
|
280
|
+
assertProfilesPresent();
|
|
281
|
+
options.profile = await promptProfile();
|
|
282
|
+
}
|
|
283
|
+
assertOptionsValid$8(options);
|
|
284
|
+
await validate();
|
|
285
|
+
const flags = prepareFlags$2(options);
|
|
286
|
+
const { ifCore } = getIfCoreFns();
|
|
287
|
+
const paths = getPaths(ifCore);
|
|
288
|
+
const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid());
|
|
289
|
+
const title = ifCore("Building optimised (minified) bundle of Tamaro Core …", `Building optimised (minified) bundle of "${configName}" customer configuration …`);
|
|
290
|
+
const cmd = `
|
|
291
|
+
${resolveBin("webpack")}
|
|
292
|
+
--config ${resolveOwn("dist/webpack.config.js")}
|
|
357
293
|
--env min
|
|
358
294
|
${flags}
|
|
359
295
|
`;
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
};
|
|
391
|
-
var prepareFlags2 = (options) => {
|
|
392
|
-
const flags = [];
|
|
393
|
-
const { localCore, analyze, https, nolint } = options;
|
|
394
|
-
if (localCore) {
|
|
395
|
-
flags.push("--env localCore");
|
|
396
|
-
}
|
|
397
|
-
if (analyze) {
|
|
398
|
-
flags.push("--env analyze");
|
|
399
|
-
}
|
|
400
|
-
if (https) {
|
|
401
|
-
flags.push("--env https");
|
|
402
|
-
}
|
|
403
|
-
if (nolint) {
|
|
404
|
-
flags.push("--env nolint");
|
|
405
|
-
}
|
|
406
|
-
return flags.join(" ");
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// src/commands/deploy.ts
|
|
410
|
-
import { existsSync as existsSync5 } from "fs";
|
|
411
|
-
import stripIndent5 from "strip-indent";
|
|
412
|
-
|
|
413
|
-
// src/lib/validators/assertTagValid.ts
|
|
414
|
-
var assertTagValid = (tag) => {
|
|
415
|
-
const regex = /^[a-zA-Z0-9-_.]+$/;
|
|
416
|
-
if (!regex.test(tag)) {
|
|
417
|
-
halt(
|
|
418
|
-
`Flag "--tag" has forbidden format. Allowed format: ${regex.toString()}.`
|
|
419
|
-
);
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
// src/commands/update-epms.ts
|
|
424
|
-
import { readFileSync as readFileSync3 } from "fs";
|
|
425
|
-
import { basename as basename2 } from "path";
|
|
426
|
-
import { config as dotenvConfig } from "dotenv";
|
|
427
|
-
import { globSync as globSync2 } from "glob";
|
|
428
|
-
import yaml2 from "js-yaml";
|
|
429
|
-
|
|
430
|
-
// src/lib/epms/assert.ts
|
|
431
|
-
import { existsSync as existsSync3, readFileSync } from "fs";
|
|
432
|
-
import yaml from "js-yaml";
|
|
433
|
-
import stripIndent4 from "strip-indent";
|
|
434
|
-
var assertEpmsCredentials = (configPath) => {
|
|
435
|
-
if (!existsSync3(configPath)) {
|
|
436
|
-
throw new Error(`Config file not found at path: ${configPath}`);
|
|
437
|
-
}
|
|
438
|
-
try {
|
|
439
|
-
const configContent = yaml.load(readFileSync(configPath, "utf8"));
|
|
440
|
-
assertEpmsCredentialsPresentStage(configContent);
|
|
441
|
-
assertEpmsCredentialsPresentProd(configContent);
|
|
442
|
-
} catch (e) {
|
|
443
|
-
throw new Error(
|
|
444
|
-
`Error parsing config file at path: ${configPath}. Details: ${e}`
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
var assertEpmsCredentialsPresentStage = (rawConfig) => {
|
|
449
|
-
const accountsUuidsStage = resolveAccountUuidFromConfig(
|
|
450
|
-
rawConfig,
|
|
451
|
-
"epms_stage"
|
|
452
|
-
);
|
|
453
|
-
if (!accountsUuidsStage) {
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
if (!process.env.EPMS_CLIENT_ID_STAGE || !process.env.EPMS_CLIENT_SECRET_STAGE) {
|
|
457
|
-
halt(
|
|
458
|
-
stripIndent4(
|
|
459
|
-
`EPMS credentials for stage environment are missing.
|
|
460
|
-
- Please set EPMS_CLIENT_ID_STAGE and EPMS_CLIENT_SECRET_STAGE in your environment variables.
|
|
461
|
-
- Alternatively, remove the "epms_stage" fields from your config.yml
|
|
462
|
-
`
|
|
463
|
-
)
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
var assertEpmsCredentialsPresentProd = (rawConfig) => {
|
|
468
|
-
const accountsUuidsProd = resolveAccountUuidFromConfig(rawConfig, "epms");
|
|
469
|
-
if (!accountsUuidsProd) {
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
if (!process.env.EPMS_CLIENT_ID || !process.env.EPMS_CLIENT_SECRET) {
|
|
473
|
-
halt(
|
|
474
|
-
stripIndent4(
|
|
475
|
-
`EPMS credentials for prod environment are missing.
|
|
476
|
-
- Please set EPMS_CLIENT_ID and EPMS_CLIENT_SECRET in your environment variables.
|
|
477
|
-
- Alternatively, remove the "epms" fields from your config.yml
|
|
478
|
-
`
|
|
479
|
-
)
|
|
480
|
-
);
|
|
481
|
-
}
|
|
296
|
+
logTitle(title);
|
|
297
|
+
logCommand(cmd);
|
|
298
|
+
runCommandSync(cmd, { stdio: "inherit" });
|
|
299
|
+
logTitle(`\nBundle for "${configName}" customer configuration is done.`);
|
|
300
|
+
console.log(`Path: ${paths.appDist}\n`);
|
|
301
|
+
process.on("exit", () => {
|
|
302
|
+
notify({
|
|
303
|
+
title: "build",
|
|
304
|
+
message: `Bundle for "${configName}" customer configuration is done.`
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
const assertOptionsValid$8 = (options) => {
|
|
309
|
+
const { localCore, https, deploy, env, profile } = options;
|
|
310
|
+
const { ifCore } = getIfCoreFns();
|
|
311
|
+
if (ifCore() && localCore) halt("Flag \"--local-core\" is redundant if running in Tamaro Core context.");
|
|
312
|
+
if (localCore && deploy) halt("Flags \"--local-core\" and \"--deploy\" must not be used together.");
|
|
313
|
+
if (https) assertCrtExists();
|
|
314
|
+
if (profile) assertProfileValid(profile);
|
|
315
|
+
assertEnvValid(env);
|
|
316
|
+
};
|
|
317
|
+
const prepareFlags$2 = (options) => {
|
|
318
|
+
const flags = [];
|
|
319
|
+
const { localCore, analyze, https, nolint, debug } = options;
|
|
320
|
+
if (localCore) flags.push("--env localCore");
|
|
321
|
+
if (analyze) flags.push("--env analyze");
|
|
322
|
+
if (https) flags.push("--env https");
|
|
323
|
+
if (nolint) flags.push("--env nolint");
|
|
324
|
+
if (debug) flags.push("--env debug");
|
|
325
|
+
return flags.join(" ");
|
|
482
326
|
};
|
|
483
327
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
function getCacheFilePath() {
|
|
490
|
-
return join(CACHE_DIR, "token.json");
|
|
491
|
-
}
|
|
492
|
-
function readCachedToken() {
|
|
493
|
-
try {
|
|
494
|
-
const filePath = getCacheFilePath();
|
|
495
|
-
if (!existsSync4(filePath)) {
|
|
496
|
-
return void 0;
|
|
497
|
-
}
|
|
498
|
-
const data = JSON.parse(readFileSync2(filePath, "utf-8"));
|
|
499
|
-
if (typeof data.token === "string" && typeof data.expirationTime === "number") {
|
|
500
|
-
return data;
|
|
501
|
-
}
|
|
502
|
-
} catch {
|
|
503
|
-
}
|
|
504
|
-
return void 0;
|
|
505
|
-
}
|
|
506
|
-
function writeCachedToken(cached) {
|
|
507
|
-
try {
|
|
508
|
-
const filePath = getCacheFilePath();
|
|
509
|
-
mkdirSync2(dirname2(filePath), { recursive: true });
|
|
510
|
-
writeFileSync(filePath, JSON.stringify(cached), { mode: 384 });
|
|
511
|
-
} catch {
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
var createAuthorizer = (baseUrl, clientId, clientSecret) => {
|
|
515
|
-
const apiUnauthorized = ky.extend({
|
|
516
|
-
headers: {
|
|
517
|
-
"Access-Control-Allow-Origin": "*"
|
|
518
|
-
},
|
|
519
|
-
prefixUrl: baseUrl,
|
|
520
|
-
timeout: DEFAULT_TIMEOUT
|
|
521
|
-
});
|
|
522
|
-
let expirationTime = void 0;
|
|
523
|
-
let token = void 0;
|
|
524
|
-
const cached = readCachedToken();
|
|
525
|
-
if (cached) {
|
|
526
|
-
token = cached.token;
|
|
527
|
-
expirationTime = cached.expirationTime;
|
|
528
|
-
}
|
|
529
|
-
const authorize = async () => {
|
|
530
|
-
const isExpired = (expirationTime ?? 0) - Date.now() < 5 * 60 * 1e3;
|
|
531
|
-
if (token && !isExpired) {
|
|
532
|
-
return token;
|
|
533
|
-
}
|
|
534
|
-
const data = await apiUnauthorized.post("oauth2/token", {
|
|
535
|
-
json: {
|
|
536
|
-
client_id: clientId,
|
|
537
|
-
client_secret: clientSecret,
|
|
538
|
-
grant_type: "client_credentials"
|
|
539
|
-
}
|
|
540
|
-
}).json();
|
|
541
|
-
token = `${data.token_type} ${data.access_token}`;
|
|
542
|
-
expirationTime = Date.now() + data.expires_in * 1e3;
|
|
543
|
-
writeCachedToken({ token, expirationTime });
|
|
544
|
-
return token;
|
|
545
|
-
};
|
|
546
|
-
return apiUnauthorized.extend({
|
|
547
|
-
hooks: {
|
|
548
|
-
beforeRequest: [
|
|
549
|
-
async (request) => {
|
|
550
|
-
request.headers.set("Authorization", await authorize());
|
|
551
|
-
}
|
|
552
|
-
]
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
};
|
|
556
|
-
|
|
557
|
-
// src/lib/epms/client.ts
|
|
558
|
-
var EpmsClient = class {
|
|
559
|
-
#epmsClient;
|
|
560
|
-
constructor(baseUrl, clientId, clientSecret) {
|
|
561
|
-
this.#epmsClient = createAuthorizer(baseUrl, clientId, clientSecret);
|
|
562
|
-
}
|
|
563
|
-
async getOrganisationIdByAccountUuid(accountUuid) {
|
|
564
|
-
const query = {
|
|
565
|
-
query: {
|
|
566
|
-
$and: [
|
|
567
|
-
{ $term: { object_uuid: accountUuid } },
|
|
568
|
-
{ $term: { object: "account" } }
|
|
569
|
-
]
|
|
570
|
-
},
|
|
571
|
-
size: 1,
|
|
572
|
-
from: 0
|
|
573
|
-
};
|
|
574
|
-
const response = await this.#epmsClient.post("search/events", {
|
|
575
|
-
json: query
|
|
576
|
-
}).json();
|
|
577
|
-
if (response.hits.length === 0) {
|
|
578
|
-
throw new Error(`No events found for account UUID: ${accountUuid}`);
|
|
579
|
-
}
|
|
580
|
-
const organisationId = response.hits[0].organisation_uuid;
|
|
581
|
-
if (!organisationId) {
|
|
582
|
-
throw new Error(
|
|
583
|
-
`Organisation UUID not found for account UUID: ${accountUuid}`
|
|
584
|
-
);
|
|
585
|
-
}
|
|
586
|
-
return organisationId;
|
|
587
|
-
}
|
|
588
|
-
async updateTamaro(configName, tag, json) {
|
|
589
|
-
return this.#epmsClient.put(`products/tamaro/${configName}/tags/${tag}`, {
|
|
590
|
-
json
|
|
591
|
-
}).json();
|
|
592
|
-
}
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
// src/commands/update-epms.ts
|
|
596
|
-
var updateEpms = async (options) => {
|
|
597
|
-
const { ifCore } = getIfCoreFns();
|
|
598
|
-
assertIsNotCore2(ifCore);
|
|
599
|
-
const paths = getPaths(ifCore);
|
|
600
|
-
const { tag, dryrun } = options;
|
|
601
|
-
const dryRunFlag = dryrun ? `--dryrun` : "";
|
|
602
|
-
const configName = getWidgetUuid();
|
|
603
|
-
const appEnvFiles = globSync2(paths.appEnv);
|
|
604
|
-
const filePath = appEnvFiles.find((file) => basename2(file) === ".env");
|
|
605
|
-
if (!filePath) {
|
|
606
|
-
halt(
|
|
607
|
-
'No ".env" file found. Please make sure to have a ".env" file with EPMS credentials in the root of your widget project.'
|
|
608
|
-
);
|
|
609
|
-
}
|
|
610
|
-
dotenvConfig({ path: filePath, quiet: true });
|
|
611
|
-
if (!("configYml" in paths)) {
|
|
612
|
-
halt("Fatal error, this should never happen");
|
|
613
|
-
throw new Error();
|
|
614
|
-
}
|
|
615
|
-
if (dryRunFlag) {
|
|
616
|
-
logTitle("\u{1F9EA} DRY RUN MODE - No actual changes will be made \u{1F9EA}");
|
|
617
|
-
}
|
|
618
|
-
assertTagValid(tag);
|
|
619
|
-
assertEpmsCredentials(paths.configYml);
|
|
620
|
-
const configContent = yaml2.load(readFileSync3(paths.configYml, "utf8"));
|
|
621
|
-
const accountUuidStage = resolveAccountUuidFromConfig(
|
|
622
|
-
configContent,
|
|
623
|
-
"epms_stage"
|
|
624
|
-
);
|
|
625
|
-
const accountUuidProd = resolveAccountUuidFromConfig(configContent, "epms");
|
|
626
|
-
if (dryrun) {
|
|
627
|
-
logTitle(
|
|
628
|
-
`[DRY RUN] Would update EPMS for "${configName}" with tag "${tag}"`
|
|
629
|
-
);
|
|
630
|
-
} else {
|
|
631
|
-
if (accountUuidStage) {
|
|
632
|
-
const epmsClient = new EpmsClient(
|
|
633
|
-
EPMS_API_BASE_URL_STAGE,
|
|
634
|
-
process.env.EPMS_CLIENT_ID_STAGE,
|
|
635
|
-
process.env.EPMS_CLIENT_SECRET_STAGE
|
|
636
|
-
);
|
|
637
|
-
const organisationUuid = await epmsClient.getOrganisationIdByAccountUuid(accountUuidStage);
|
|
638
|
-
logTitle("Updating EPMS Stage with the following details:");
|
|
639
|
-
const body = {
|
|
640
|
-
account_uuid: accountUuidStage,
|
|
641
|
-
organisation_uuid: organisationUuid,
|
|
642
|
-
configured_version: resolveCoreVersion() ?? "unknown",
|
|
643
|
-
read_only: false,
|
|
644
|
-
// Unix timestamp in seconds
|
|
645
|
-
last_deployment: Math.floor(Date.now() / 1e3)
|
|
646
|
-
};
|
|
647
|
-
logDataTable({
|
|
648
|
-
name: configName,
|
|
649
|
-
tag,
|
|
650
|
-
...body
|
|
651
|
-
});
|
|
652
|
-
await epmsClient.updateTamaro(configName, tag, body);
|
|
653
|
-
logSuccess("\u2705 EPMS Stage is updated.");
|
|
654
|
-
}
|
|
655
|
-
if (accountUuidProd) {
|
|
656
|
-
const epmsClient = new EpmsClient(
|
|
657
|
-
EPMS_API_BASE_URL_PROD,
|
|
658
|
-
process.env.EPMS_CLIENT_ID,
|
|
659
|
-
process.env.EPMS_CLIENT_SECRET
|
|
660
|
-
);
|
|
661
|
-
const organisationUuid = await epmsClient.getOrganisationIdByAccountUuid(accountUuidProd);
|
|
662
|
-
logTitle("Updating EPMS Prod with the following details:");
|
|
663
|
-
const body = {
|
|
664
|
-
account_uuid: accountUuidProd,
|
|
665
|
-
organisation_uuid: organisationUuid,
|
|
666
|
-
configured_version: resolveCoreVersion() ?? "unknown",
|
|
667
|
-
read_only: false
|
|
668
|
-
};
|
|
669
|
-
logDataTable({
|
|
670
|
-
name: configName,
|
|
671
|
-
tag,
|
|
672
|
-
...body
|
|
673
|
-
});
|
|
674
|
-
await epmsClient.updateTamaro(configName, tag, body);
|
|
675
|
-
logSuccess("\u2705 EPMS Prod is updated.");
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
};
|
|
679
|
-
var assertIsNotCore2 = (ifCore) => {
|
|
680
|
-
if (ifCore()) {
|
|
681
|
-
halt("You cannot update EPMS in the context of Tamaro Core.");
|
|
682
|
-
}
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/lib/validators/assertTagValid.ts
|
|
330
|
+
const assertTagValid = (tag) => {
|
|
331
|
+
const regex = /^[a-zA-Z0-9-_.]+$/;
|
|
332
|
+
if (!regex.test(tag)) halt(`Flag "--tag" has forbidden format. Allowed format: ${regex.toString()}.`);
|
|
683
333
|
};
|
|
684
334
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/commands/deploy.ts
|
|
337
|
+
const deploy = async (options) => {
|
|
338
|
+
const { ifCore } = getIfCoreFns();
|
|
339
|
+
const paths = getPaths(ifCore);
|
|
340
|
+
assertDistPathExists(paths.appDist);
|
|
341
|
+
if (!options.profile && !options.ci) {
|
|
342
|
+
assertProfilesPresent();
|
|
343
|
+
options.profile = await promptProfile();
|
|
344
|
+
}
|
|
345
|
+
assertOptionsValid$7(options);
|
|
346
|
+
await validate();
|
|
347
|
+
awsAuthenticate(options);
|
|
348
|
+
const flags = prepareFlags$3(options);
|
|
349
|
+
const { tag, dryrun } = options;
|
|
350
|
+
const dryRunFlag = dryrun ? `--dryrun` : "";
|
|
351
|
+
const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid());
|
|
352
|
+
const deployUrl = `s3://${AWS_S3_BUCKET_TAMARO}/${configName}/${tag}`;
|
|
353
|
+
const entryFilename = ifCore("index.js", "widget.js");
|
|
354
|
+
if (dryRunFlag) logTitle("🧪 DRY RUN MODE - No actual changes will be made 🧪");
|
|
355
|
+
/**
|
|
356
|
+
* Sync all files except entrypoint (without deleting old files)
|
|
357
|
+
*/
|
|
358
|
+
const cmdSyncAll = `
|
|
707
359
|
aws s3 sync ${paths.appDist} ${deployUrl}
|
|
708
360
|
--acl public-read
|
|
709
361
|
--exclude ${paths.appDist}/${entryFilename}
|
|
@@ -711,838 +363,512 @@ var deploy = async (options) => {
|
|
|
711
363
|
${flags}
|
|
712
364
|
${dryRunFlag}
|
|
713
365
|
`;
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
366
|
+
logTitle("Deploying to AWS S3 …");
|
|
367
|
+
logCommand(cmdSyncAll);
|
|
368
|
+
try {
|
|
369
|
+
runCommandSync(cmdSyncAll, { stdout: "inherit" });
|
|
370
|
+
} catch (error) {
|
|
371
|
+
halt(error.stderr);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Copy entrypoint
|
|
375
|
+
*/
|
|
376
|
+
const cmdCpEntry = `
|
|
722
377
|
aws s3 cp ${paths.appDist}/${entryFilename} ${deployUrl}/${entryFilename}
|
|
723
378
|
--acl public-read
|
|
724
379
|
--cache-control max-age=64800
|
|
725
380
|
${flags}
|
|
726
381
|
${dryRunFlag}
|
|
727
382
|
`;
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
383
|
+
logCommand(cmdCpEntry);
|
|
384
|
+
try {
|
|
385
|
+
runCommandSync(cmdCpEntry, { stdout: "inherit" });
|
|
386
|
+
} catch (error) {
|
|
387
|
+
halt(error.stderr);
|
|
388
|
+
}
|
|
389
|
+
if (!dryRunFlag) {
|
|
390
|
+
/**
|
|
391
|
+
* Invalidate cloudfront cache
|
|
392
|
+
*/
|
|
393
|
+
const cmdInvalidateCache = `
|
|
736
394
|
aws cloudfront create-invalidation
|
|
737
395
|
--distribution-id ${AWS_CLOUDFRONT_DISTRIBUTION_ID}
|
|
738
396
|
--paths /${configName}/${tag}/*
|
|
739
397
|
${flags}
|
|
740
398
|
`;
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
title: "deploy",
|
|
761
|
-
message: `
|
|
399
|
+
logTitle("\nInvalidating edge cache …");
|
|
400
|
+
logCommand(cmdInvalidateCache);
|
|
401
|
+
try {
|
|
402
|
+
runCommandSync(cmdInvalidateCache);
|
|
403
|
+
} catch (error) {
|
|
404
|
+
halt(error.stderr);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
const demoPage = `https://${AWS_S3_BUCKET_TAMARO}/${configName}/${tag}/index.html`;
|
|
408
|
+
const entryPoint = `https://${AWS_S3_BUCKET_TAMARO}/${configName}/${tag}/${entryFilename}`;
|
|
409
|
+
logTitle(`\nBundle for "${configName}" is deployed with tag "${tag}".`);
|
|
410
|
+
logDataTable({
|
|
411
|
+
"Demo page:": demoPage,
|
|
412
|
+
"Entry point:": entryPoint
|
|
413
|
+
});
|
|
414
|
+
process.on("exit", () => {
|
|
415
|
+
notify({
|
|
416
|
+
title: "deploy",
|
|
417
|
+
message: `
|
|
762
418
|
Bundle for "${configName}" is deployed with tag "${tag}".
|
|
763
419
|
Demo page: ${demoPage}
|
|
764
420
|
Entry point: ${entryPoint}
|
|
765
421
|
`
|
|
766
|
-
|
|
767
|
-
|
|
422
|
+
});
|
|
423
|
+
});
|
|
768
424
|
};
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
}
|
|
774
|
-
assertTagValid(tag);
|
|
425
|
+
const assertOptionsValid$7 = (options) => {
|
|
426
|
+
const { profile, tag } = options;
|
|
427
|
+
if (profile) assertProfileValid(profile);
|
|
428
|
+
assertTagValid(tag);
|
|
775
429
|
};
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
halt(
|
|
779
|
-
stripIndent5(`
|
|
430
|
+
const assertDistPathExists = (distPath) => {
|
|
431
|
+
if (!existsSync(distPath)) halt(stripIndent(`
|
|
780
432
|
Dist folder does not exists.
|
|
781
433
|
Make sure you have built the bundle before trying to deploy it.
|
|
782
|
-
`)
|
|
783
|
-
);
|
|
784
|
-
}
|
|
434
|
+
`));
|
|
785
435
|
};
|
|
786
436
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
const configName = getWidgetUuid();
|
|
809
|
-
const deployUrl = `s3://${options.bucket}/${configName}`;
|
|
810
|
-
if (dryRunFlag) {
|
|
811
|
-
logTitle("\u{1F9EA} DRY RUN MODE - No actual changes will be made \u{1F9EA}");
|
|
812
|
-
}
|
|
813
|
-
const cmd = `
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/commands/deploy-email-config.ts
|
|
439
|
+
const deployEmailConfig = async (options) => {
|
|
440
|
+
const { ifCore } = getIfCoreFns();
|
|
441
|
+
const emailConfigPath = `${getPaths(ifCore).app}/email-config`;
|
|
442
|
+
assertIsNotCore$2();
|
|
443
|
+
assertEmailConfigPathExists(emailConfigPath);
|
|
444
|
+
if (!options.profile && !options.ci) {
|
|
445
|
+
assertProfilesPresent();
|
|
446
|
+
options.profile = await promptProfile();
|
|
447
|
+
}
|
|
448
|
+
if (!options.bucket) options.bucket = options.ci ? AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD : await promptBucketTamaroEmailConfig$1();
|
|
449
|
+
assertOptionsValid$6(options);
|
|
450
|
+
await validate();
|
|
451
|
+
awsAuthenticate(options);
|
|
452
|
+
const flags = prepareFlags$3(options);
|
|
453
|
+
const dryRunFlag = options.dryrun ? `--dryrun` : "";
|
|
454
|
+
const configName = getWidgetUuid();
|
|
455
|
+
const deployUrl = `s3://${options.bucket}/${configName}`;
|
|
456
|
+
if (dryRunFlag) logTitle("🧪 DRY RUN MODE - No actual changes will be made 🧪");
|
|
457
|
+
const cmd = `
|
|
814
458
|
aws s3 sync ${emailConfigPath} ${deployUrl}
|
|
815
459
|
--delete
|
|
816
460
|
--exact-timestamps
|
|
817
461
|
${flags}
|
|
818
462
|
${dryRunFlag}
|
|
819
463
|
`;
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
if (!buckets.includes(bucket)) {
|
|
866
|
-
halt("Invalid bucket name.");
|
|
867
|
-
}
|
|
868
|
-
};
|
|
869
|
-
var promptBucketTamaroEmailConfig = async () => {
|
|
870
|
-
const buckets = [
|
|
871
|
-
{ title: "stage", value: AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE },
|
|
872
|
-
{ title: "prod", value: AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD }
|
|
873
|
-
];
|
|
874
|
-
const { bucket } = await prompts2(
|
|
875
|
-
[
|
|
876
|
-
{
|
|
877
|
-
type: "select",
|
|
878
|
-
name: "bucket",
|
|
879
|
-
message: "Select environment",
|
|
880
|
-
choices: buckets
|
|
881
|
-
}
|
|
882
|
-
],
|
|
883
|
-
{
|
|
884
|
-
onCancel: () => halt()
|
|
885
|
-
}
|
|
886
|
-
);
|
|
887
|
-
return bucket;
|
|
464
|
+
logTitle(`Deploying email configuration for "${configName}" customer configuration to AWS S3 …`);
|
|
465
|
+
logCommand(cmd);
|
|
466
|
+
try {
|
|
467
|
+
runCommandSync(cmd, { stdout: "inherit" });
|
|
468
|
+
} catch (error) {
|
|
469
|
+
halt(error.stderr);
|
|
470
|
+
}
|
|
471
|
+
logTitle(`Email configuration for "${configName}" customer configuration is deployed.`);
|
|
472
|
+
logDataTable({ "Deploy URL:": deployUrl });
|
|
473
|
+
process.on("exit", () => {
|
|
474
|
+
notify({
|
|
475
|
+
title: "deploy-email-config",
|
|
476
|
+
message: `Email configuration for "${configName}" customer configuration is deployed.`
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
};
|
|
480
|
+
const assertOptionsValid$6 = (options) => {
|
|
481
|
+
const { profile, bucket } = options;
|
|
482
|
+
if (profile) assertProfileValid(profile);
|
|
483
|
+
if (bucket) assertBucketValid$1(bucket);
|
|
484
|
+
};
|
|
485
|
+
const assertEmailConfigPathExists = (distPath) => {
|
|
486
|
+
if (!existsSync(distPath)) halt("Email config folder does not exists. Nothing to deploy.");
|
|
487
|
+
};
|
|
488
|
+
const assertIsNotCore$2 = () => {
|
|
489
|
+
const { ifCore } = getIfCoreFns();
|
|
490
|
+
if (ifCore()) halt("You cannot deploy widget email configuration for Tamaro Core.");
|
|
491
|
+
};
|
|
492
|
+
const assertBucketValid$1 = (bucket) => {
|
|
493
|
+
if (![AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE, AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD].includes(bucket)) halt("Invalid bucket name.");
|
|
494
|
+
};
|
|
495
|
+
const promptBucketTamaroEmailConfig$1 = async () => {
|
|
496
|
+
const { bucket } = await prompts([{
|
|
497
|
+
type: "select",
|
|
498
|
+
name: "bucket",
|
|
499
|
+
message: "Select environment",
|
|
500
|
+
choices: [{
|
|
501
|
+
title: "stage",
|
|
502
|
+
value: AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE
|
|
503
|
+
}, {
|
|
504
|
+
title: "prod",
|
|
505
|
+
value: AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD
|
|
506
|
+
}]
|
|
507
|
+
}], { onCancel: () => halt() });
|
|
508
|
+
return bucket;
|
|
888
509
|
};
|
|
889
510
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
"
|
|
901
|
-
|
|
902
|
-
const wpBin = resolveBin("webpack");
|
|
903
|
-
const wpConfig = resolveOwn("dist/webpack.config.js");
|
|
904
|
-
const cmd = `
|
|
905
|
-
${wpBin} serve
|
|
906
|
-
--config ${wpConfig}
|
|
511
|
+
//#endregion
|
|
512
|
+
//#region src/commands/dev.ts
|
|
513
|
+
const dev = async (options) => {
|
|
514
|
+
const { env } = options;
|
|
515
|
+
applyEnv(env);
|
|
516
|
+
assertOptionsValid$5(options);
|
|
517
|
+
const flags = await prepareFlags$1(options);
|
|
518
|
+
const { ifCore } = getIfCoreFns();
|
|
519
|
+
const title = ifCore("Running dev web-server for Tamaro Core …", "Running dev web-server for customer configuration …");
|
|
520
|
+
const cmd = `
|
|
521
|
+
${resolveBin("webpack")} serve
|
|
522
|
+
--config ${resolveOwn("dist/webpack.config.js")}
|
|
907
523
|
${flags}
|
|
908
524
|
`;
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
};
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
};
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
if (localCore) {
|
|
932
|
-
flags.push("--env localCore");
|
|
933
|
-
}
|
|
934
|
-
flags.push(`--port ${port}`);
|
|
935
|
-
if (https) {
|
|
936
|
-
flags.push("--env https");
|
|
937
|
-
}
|
|
938
|
-
if (nolint) {
|
|
939
|
-
flags.push("--env nolint");
|
|
940
|
-
}
|
|
941
|
-
return flags.join(" ");
|
|
525
|
+
logTitle(title);
|
|
526
|
+
logCommand(cmd);
|
|
527
|
+
runCommandSync(cmd, { stdio: "inherit" });
|
|
528
|
+
};
|
|
529
|
+
const assertOptionsValid$5 = (options) => {
|
|
530
|
+
const { localCore, https, port, env } = options;
|
|
531
|
+
const { ifCore } = getIfCoreFns();
|
|
532
|
+
if (ifCore() && localCore) halt("Flag \"--local-core\" is redundant if running in Tamaro Core context.");
|
|
533
|
+
if (isNaN(Number(port))) halt("Flag \"--port\" should be a number.");
|
|
534
|
+
if (https) assertCrtExists();
|
|
535
|
+
assertEnvValid(env);
|
|
536
|
+
};
|
|
537
|
+
const prepareFlags$1 = async (options) => {
|
|
538
|
+
const flags = [];
|
|
539
|
+
const { localCore, port: defaultPort, https, nolint, debug } = options;
|
|
540
|
+
const port = await getPortPromise({ port: Number(defaultPort) });
|
|
541
|
+
if (localCore) flags.push("--env localCore");
|
|
542
|
+
flags.push(`--port ${port}`);
|
|
543
|
+
if (https) flags.push("--env https");
|
|
544
|
+
if (nolint) flags.push("--env nolint");
|
|
545
|
+
if (debug) flags.push("--env debug");
|
|
546
|
+
return flags.join(" ");
|
|
942
547
|
};
|
|
943
548
|
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
}
|
|
990
|
-
};
|
|
991
|
-
var assertConfigValid = (config) => {
|
|
992
|
-
if (!config) {
|
|
993
|
-
return;
|
|
994
|
-
}
|
|
995
|
-
const regex = /^[a-zA-Z0-9-_]+$/;
|
|
996
|
-
if (!regex.test(config)) {
|
|
997
|
-
halt(
|
|
998
|
-
`Flag "--config" has forbidden format. Allowed format: ${regex.toString()}.`
|
|
999
|
-
);
|
|
1000
|
-
}
|
|
1001
|
-
};
|
|
1002
|
-
var parseTags = (lines) => {
|
|
1003
|
-
const regex = /^\s*PRE\s*/;
|
|
1004
|
-
return lines.filter((line) => regex.test(line)).map((line) => line.replace(regex, "").replace(/\/$/, ""));
|
|
549
|
+
//#endregion
|
|
550
|
+
//#region src/commands/list-deployed.ts
|
|
551
|
+
const listDeployed = async (options) => {
|
|
552
|
+
if (!options.profile && !options.ci) {
|
|
553
|
+
assertProfilesPresent();
|
|
554
|
+
options.profile = await promptProfile();
|
|
555
|
+
}
|
|
556
|
+
assertOptionsValid$4(options);
|
|
557
|
+
awsAuthenticate(options);
|
|
558
|
+
const flags = prepareFlags$3(options);
|
|
559
|
+
const { config } = options;
|
|
560
|
+
const { ifCore } = getIfCoreFns();
|
|
561
|
+
const configName = config ?? ifCore(CORE_CONFIG_NAME, getWidgetUuid());
|
|
562
|
+
const title = !config && ifCore() ? `Listing deployments of Tamaro Core …` : `Listing deployments of "${configName}" customer configuration …`;
|
|
563
|
+
const cmd = `aws s3 ls ${`s3://${AWS_S3_BUCKET_TAMARO}/${configName}/`} ${flags}`;
|
|
564
|
+
let out = "";
|
|
565
|
+
logTitle(title);
|
|
566
|
+
logCommand(cmd);
|
|
567
|
+
try {
|
|
568
|
+
out = runCommandSync(cmd).stdout;
|
|
569
|
+
} catch (error) {
|
|
570
|
+
out = error.stdout;
|
|
571
|
+
if (error.stderr) halt(error.stderr);
|
|
572
|
+
}
|
|
573
|
+
const tags = parseTags(out.split("\n"));
|
|
574
|
+
let text = "";
|
|
575
|
+
if (tags.length === 0) text = "No deployments found.";
|
|
576
|
+
else text = tags.map((tag, idx) => {
|
|
577
|
+
return `${idx + 1}. https://${AWS_S3_BUCKET_TAMARO}/${configName}/${tag}/index.html`;
|
|
578
|
+
}).join("\n");
|
|
579
|
+
console.log(`${text}\n`);
|
|
580
|
+
};
|
|
581
|
+
const assertOptionsValid$4 = (options) => {
|
|
582
|
+
const { config, profile } = options;
|
|
583
|
+
assertConfigValid(config);
|
|
584
|
+
if (profile) assertProfileValid(profile);
|
|
585
|
+
};
|
|
586
|
+
const assertConfigValid = (config) => {
|
|
587
|
+
if (!config) return;
|
|
588
|
+
const regex = /^[a-zA-Z0-9-_]+$/;
|
|
589
|
+
if (!regex.test(config)) halt(`Flag "--config" has forbidden format. Allowed format: ${regex.toString()}.`);
|
|
590
|
+
};
|
|
591
|
+
const parseTags = (lines) => {
|
|
592
|
+
const regex = /^\s*PRE\s*/;
|
|
593
|
+
return lines.filter((line) => regex.test(line)).map((line) => line.replace(regex, "").replace(/\/$/, ""));
|
|
1005
594
|
};
|
|
1006
595
|
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
const cmd = `
|
|
1016
|
-
npx -y serve ${paths.appDist}
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region src/commands/serve.ts
|
|
598
|
+
const serve = async (options) => {
|
|
599
|
+
assertOptionsValid$3(options);
|
|
600
|
+
const flags = await prepareFlags(options);
|
|
601
|
+
const { ifCore } = getIfCoreFns();
|
|
602
|
+
const cmd = `
|
|
603
|
+
npx -y serve ${getPaths(ifCore).appDist}
|
|
1017
604
|
--cors
|
|
1018
605
|
${flags}
|
|
1019
606
|
`;
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
};
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
};
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
flags.push(`--ssl-cert ${certFile}`);
|
|
1044
|
-
flags.push(`--ssl-key ${keyFile}`);
|
|
1045
|
-
}
|
|
1046
|
-
return flags.join(" ");
|
|
607
|
+
logTitle(`Running web-server for pre-built bundle …`);
|
|
608
|
+
logCommand(cmd);
|
|
609
|
+
runCommandSync(cmd, { stdio: "inherit" });
|
|
610
|
+
};
|
|
611
|
+
const assertOptionsValid$3 = (options) => {
|
|
612
|
+
const { port, https } = options;
|
|
613
|
+
if (isNaN(Number(port))) halt("Flag \"--port\" should be a number.");
|
|
614
|
+
if (https) assertCrtExists();
|
|
615
|
+
};
|
|
616
|
+
const prepareFlags = async (options) => {
|
|
617
|
+
const flags = [];
|
|
618
|
+
const { port: defaultPort, https } = options;
|
|
619
|
+
const port = await getPortPromise({ port: Number(defaultPort) });
|
|
620
|
+
flags.push(`-p ${port}`);
|
|
621
|
+
if (https) {
|
|
622
|
+
const { ifCore } = getIfCoreFns();
|
|
623
|
+
const paths = getPaths(ifCore);
|
|
624
|
+
const certFile = resolve(paths.root, HTTPS_CRT_FILE);
|
|
625
|
+
const keyFile = resolve(paths.root, HTTPS_KEY_FILE);
|
|
626
|
+
flags.push(`--ssl-cert ${certFile}`);
|
|
627
|
+
flags.push(`--ssl-key ${keyFile}`);
|
|
628
|
+
}
|
|
629
|
+
return flags.join(" ");
|
|
1047
630
|
};
|
|
1048
631
|
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
};
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
};
|
|
1086
|
-
var assertIsArchived = () => {
|
|
1087
|
-
const parentDirName = basename3(dirname3(process.cwd()));
|
|
1088
|
-
if (parentDirName !== "_archived") {
|
|
1089
|
-
halt(
|
|
1090
|
-
"This configuration is not archived. Only archived configurations can be unarchived."
|
|
1091
|
-
);
|
|
1092
|
-
}
|
|
1093
|
-
};
|
|
1094
|
-
var assertIsNotCore4 = (ifCore) => {
|
|
1095
|
-
if (ifCore()) {
|
|
1096
|
-
halt("You cannot unarchive Tamaro Core.");
|
|
1097
|
-
}
|
|
1098
|
-
};
|
|
1099
|
-
var assertRestoreTargetDoesNotExist = (restoreTarget) => {
|
|
1100
|
-
if (existsSync7(restoreTarget)) {
|
|
1101
|
-
halt(
|
|
1102
|
-
`Restore target already exists: ${restoreTarget}. Please remove it first.`
|
|
1103
|
-
);
|
|
1104
|
-
}
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region src/commands/unarchive.ts
|
|
634
|
+
const unarchive = (options) => {
|
|
635
|
+
const { ifCore } = getIfCoreFns({ allowArchived: true });
|
|
636
|
+
assertIsNotCore$1(ifCore);
|
|
637
|
+
assertIsArchived();
|
|
638
|
+
const configName = getWidgetUuid();
|
|
639
|
+
const cwd = process.cwd();
|
|
640
|
+
const restoreTarget = resolve(dirname(dirname(cwd)), configName);
|
|
641
|
+
assertRestoreTargetDoesNotExist(restoreTarget);
|
|
642
|
+
assertOptionsValid$2(options);
|
|
643
|
+
if (options.dryrun) logTitle("🧪 DRY RUN MODE - No actual changes will be made 🧪");
|
|
644
|
+
if (!options.dryrun) {
|
|
645
|
+
renameSync(cwd, restoreTarget);
|
|
646
|
+
process.chdir(restoreTarget);
|
|
647
|
+
} else logTitle(`Would move ${cwd} → ${restoreTarget}`);
|
|
648
|
+
logTitle(`✅ "${configName}" has been unarchived and moved to ${restoreTarget}`);
|
|
649
|
+
process.on("exit", () => {
|
|
650
|
+
notify({
|
|
651
|
+
title: "unarchive",
|
|
652
|
+
message: `"${configName}" has been unarchived.`
|
|
653
|
+
});
|
|
654
|
+
});
|
|
655
|
+
};
|
|
656
|
+
const assertOptionsValid$2 = (options) => {
|
|
657
|
+
const { profile } = options;
|
|
658
|
+
if (profile) assertProfileValid(profile);
|
|
659
|
+
};
|
|
660
|
+
const assertIsArchived = () => {
|
|
661
|
+
if (basename(dirname(process.cwd())) !== "_archived") halt("This configuration is not archived. Only archived configurations can be unarchived.");
|
|
662
|
+
};
|
|
663
|
+
const assertIsNotCore$1 = (ifCore) => {
|
|
664
|
+
if (ifCore()) halt("You cannot unarchive Tamaro Core.");
|
|
665
|
+
};
|
|
666
|
+
const assertRestoreTargetDoesNotExist = (restoreTarget) => {
|
|
667
|
+
if (existsSync(restoreTarget)) halt(`Restore target already exists: ${restoreTarget}. Please remove it first.`);
|
|
1105
668
|
};
|
|
1106
669
|
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
`Are you sure you want to undeploy ${description}?`,
|
|
1127
|
-
options.ci
|
|
1128
|
-
);
|
|
1129
|
-
const cmd = `
|
|
670
|
+
//#endregion
|
|
671
|
+
//#region src/commands/undeploy.ts
|
|
672
|
+
const undeploy = async (options) => {
|
|
673
|
+
const { ifCore } = getIfCoreFns();
|
|
674
|
+
const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid());
|
|
675
|
+
if (!options.profile && !options.ci) {
|
|
676
|
+
assertProfilesPresent();
|
|
677
|
+
options.profile = await promptProfile();
|
|
678
|
+
}
|
|
679
|
+
assertOptionsValid$1(options);
|
|
680
|
+
awsAuthenticate(options);
|
|
681
|
+
const flags = prepareFlags$3(options);
|
|
682
|
+
const { tag = DEFAULT_TAG, all, dryrun } = options;
|
|
683
|
+
const dryRunFlag = dryrun ? `--dryrun` : "";
|
|
684
|
+
const deployUrl = all ? `s3://${AWS_S3_BUCKET_TAMARO}/${configName}/` : `s3://${AWS_S3_BUCKET_TAMARO}/${configName}/${tag}/`;
|
|
685
|
+
const description = all ? `all tags of "${configName}"` : `tag "${tag}" of "${configName}"`;
|
|
686
|
+
if (dryRunFlag) logTitle("🧪 DRY RUN MODE - No actual changes will be made 🧪");
|
|
687
|
+
await promptConfirmation(`Are you sure you want to undeploy ${description}?`, options.yes);
|
|
688
|
+
const cmd = `
|
|
1130
689
|
aws s3 rm ${deployUrl}
|
|
1131
690
|
--recursive
|
|
1132
691
|
${flags}
|
|
1133
692
|
${dryRunFlag}
|
|
1134
693
|
`;
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
const cmdInvalidateCache = `
|
|
694
|
+
logTitle(`Undeploying ${description} from AWS S3 …`);
|
|
695
|
+
logCommand(cmd);
|
|
696
|
+
try {
|
|
697
|
+
runCommandSync(cmd, { stdout: "inherit" });
|
|
698
|
+
} catch (error) {
|
|
699
|
+
halt(error.stderr);
|
|
700
|
+
}
|
|
701
|
+
if (!dryRunFlag) {
|
|
702
|
+
const cmdInvalidateCache = `
|
|
1145
703
|
aws cloudfront create-invalidation
|
|
1146
704
|
--distribution-id ${AWS_CLOUDFRONT_DISTRIBUTION_ID}
|
|
1147
|
-
--paths ${
|
|
705
|
+
--paths ${all ? `/${configName}/*` : `/${configName}/${tag}/*`}
|
|
1148
706
|
${flags}
|
|
1149
707
|
`;
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
halt("You cannot undeploy the default tag for Tamaro Core.");
|
|
1176
|
-
}
|
|
1177
|
-
if (profile) {
|
|
1178
|
-
assertProfileValid(profile);
|
|
1179
|
-
}
|
|
1180
|
-
if (all && tag) {
|
|
1181
|
-
halt('Flags "--tag" and "--all" must not be used together.');
|
|
1182
|
-
}
|
|
1183
|
-
if (!all && tag) {
|
|
1184
|
-
assertTagValid(tag);
|
|
1185
|
-
}
|
|
708
|
+
logTitle("\nInvalidating edge cache …");
|
|
709
|
+
logCommand(cmdInvalidateCache);
|
|
710
|
+
try {
|
|
711
|
+
runCommandSync(cmdInvalidateCache);
|
|
712
|
+
} catch (error) {
|
|
713
|
+
halt(error.stderr);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
logTitle(`\n${description} has been undeployed.`);
|
|
717
|
+
logDataTable({ "Removed URL:": deployUrl });
|
|
718
|
+
process.on("exit", () => {
|
|
719
|
+
notify({
|
|
720
|
+
title: "undeploy",
|
|
721
|
+
message: `${description} has been undeployed.`
|
|
722
|
+
});
|
|
723
|
+
});
|
|
724
|
+
};
|
|
725
|
+
const assertOptionsValid$1 = (options) => {
|
|
726
|
+
const { profile, tag, all } = options;
|
|
727
|
+
const { ifCore } = getIfCoreFns();
|
|
728
|
+
if (ifCore() && all) halt("Flag \"--all\" must not be used in Tamaro Core context.");
|
|
729
|
+
if (ifCore() && tag === DEFAULT_TAG) halt("You cannot undeploy the default tag for Tamaro Core.");
|
|
730
|
+
if (profile) assertProfileValid(profile);
|
|
731
|
+
if (all && tag) halt("Flags \"--tag\" and \"--all\" must not be used together.");
|
|
732
|
+
if (!all && tag) assertTagValid(tag);
|
|
1186
733
|
};
|
|
1187
734
|
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
logTitle("\u{1F9EA} DRY RUN MODE - No actual changes will be made \u{1F9EA}");
|
|
1212
|
-
}
|
|
1213
|
-
const cmd = `
|
|
735
|
+
//#endregion
|
|
736
|
+
//#region src/commands/undeploy-email-config.ts
|
|
737
|
+
const undeployEmailConfig = async (options) => {
|
|
738
|
+
const { ifCore } = getIfCoreFns();
|
|
739
|
+
assertIsNotCore(ifCore);
|
|
740
|
+
if (!options.profile && !options.ci) {
|
|
741
|
+
assertProfilesPresent();
|
|
742
|
+
options.profile = await promptProfile();
|
|
743
|
+
}
|
|
744
|
+
if (options.ci) options.bucket = AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD;
|
|
745
|
+
if (!options.bucket) if (options.ci) options.bucket = AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD;
|
|
746
|
+
else if (options.prod) options.bucket = AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD;
|
|
747
|
+
else if (options.stage) options.bucket = AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE;
|
|
748
|
+
else options.bucket = await promptBucketTamaroEmailConfig();
|
|
749
|
+
assertOptionsValid(options);
|
|
750
|
+
awsAuthenticate(options);
|
|
751
|
+
const flags = prepareFlags$3(options);
|
|
752
|
+
const dryRunFlag = options.dryrun ? `--dryrun` : "";
|
|
753
|
+
const configName = getWidgetUuid();
|
|
754
|
+
const deployUrl = `s3://${options.bucket}/${configName}/`;
|
|
755
|
+
await promptConfirmation(`Are you sure you want to undeploy the email configuration for "${configName}" from "${options.bucket}"?`, options.ci);
|
|
756
|
+
if (dryRunFlag) logTitle("🧪 DRY RUN MODE - No actual changes will be made 🧪");
|
|
757
|
+
const cmd = `
|
|
1214
758
|
aws s3 rm ${deployUrl}
|
|
1215
759
|
--recursive
|
|
1216
760
|
${flags}
|
|
1217
761
|
${dryRunFlag}
|
|
1218
762
|
`;
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
};
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
};
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
var promptBucketTamaroEmailConfig2 = async () => {
|
|
1261
|
-
const buckets = [
|
|
1262
|
-
{ title: "stage", value: AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE },
|
|
1263
|
-
{ title: "prod", value: AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD }
|
|
1264
|
-
];
|
|
1265
|
-
const { bucket } = await prompts3(
|
|
1266
|
-
[
|
|
1267
|
-
{
|
|
1268
|
-
type: "select",
|
|
1269
|
-
name: "bucket",
|
|
1270
|
-
message: "Select environment",
|
|
1271
|
-
choices: buckets
|
|
1272
|
-
}
|
|
1273
|
-
],
|
|
1274
|
-
{
|
|
1275
|
-
onCancel: () => halt()
|
|
1276
|
-
}
|
|
1277
|
-
);
|
|
1278
|
-
return bucket;
|
|
763
|
+
logTitle(`Undeploying email configuration for "${configName}" from AWS S3 …`);
|
|
764
|
+
logCommand(cmd);
|
|
765
|
+
try {
|
|
766
|
+
runCommandSync(cmd, { stdout: "inherit" });
|
|
767
|
+
} catch (error) {
|
|
768
|
+
halt(error.stderr);
|
|
769
|
+
}
|
|
770
|
+
logTitle(`Email configuration for "${configName}" has been undeployed from "${options.bucket}".`);
|
|
771
|
+
logDataTable({ "Removed URL:": deployUrl });
|
|
772
|
+
process.on("exit", () => {
|
|
773
|
+
notify({
|
|
774
|
+
title: "undeploy-email-config",
|
|
775
|
+
message: `Email configuration for "${configName}" has been undeployed.`
|
|
776
|
+
});
|
|
777
|
+
});
|
|
778
|
+
};
|
|
779
|
+
const assertOptionsValid = (options) => {
|
|
780
|
+
const { profile, bucket } = options;
|
|
781
|
+
if (profile) assertProfileValid(profile);
|
|
782
|
+
if (bucket) assertBucketValid(bucket);
|
|
783
|
+
};
|
|
784
|
+
const assertIsNotCore = (ifCore) => {
|
|
785
|
+
if (ifCore()) halt("You cannot undeploy widget email configuration for Tamaro Core.");
|
|
786
|
+
};
|
|
787
|
+
const assertBucketValid = (bucket) => {
|
|
788
|
+
if (![AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE, AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD].includes(bucket)) halt("Invalid bucket name.");
|
|
789
|
+
};
|
|
790
|
+
const promptBucketTamaroEmailConfig = async () => {
|
|
791
|
+
const { bucket } = await prompts([{
|
|
792
|
+
type: "select",
|
|
793
|
+
name: "bucket",
|
|
794
|
+
message: "Select environment",
|
|
795
|
+
choices: [{
|
|
796
|
+
title: "stage",
|
|
797
|
+
value: AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE
|
|
798
|
+
}, {
|
|
799
|
+
title: "prod",
|
|
800
|
+
value: AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD
|
|
801
|
+
}]
|
|
802
|
+
}], { onCancel: () => halt() });
|
|
803
|
+
return bucket;
|
|
1279
804
|
};
|
|
1280
805
|
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
author: {
|
|
1286
|
-
name: "RaiseNow",
|
|
1287
|
-
email: "development@raisenow.com"
|
|
1288
|
-
},
|
|
1289
|
-
type: "module",
|
|
1290
|
-
bin: "dist/cli.js",
|
|
1291
|
-
packageManager: "pnpm@10.28.2",
|
|
1292
|
-
engines: {
|
|
1293
|
-
node: ">=22.22.0",
|
|
1294
|
-
pnpm: ">=10.28.2",
|
|
1295
|
-
npm: "please-use-pnpm",
|
|
1296
|
-
yarn: "please-use-pnpm"
|
|
1297
|
-
},
|
|
1298
|
-
scripts: {
|
|
1299
|
-
prepare: "pnpm build",
|
|
1300
|
-
typecheck: "tsc --noEmit",
|
|
1301
|
-
build: "tsup src/cli.ts src/webpack.config.ts --clean --shims --format esm",
|
|
1302
|
-
"build:watch": "pnpm build --watch --ignore-watch .history --ignore-watch .idea",
|
|
1303
|
-
dev: "pnpm build:watch",
|
|
1304
|
-
readme: "pnpx http-server . --cors -o /readme.html",
|
|
1305
|
-
lint: "DEBUG=eslint:cli-engine eslint .",
|
|
1306
|
-
"lint:fix": "DEBUG=eslint:cli-engine eslint --fix .",
|
|
1307
|
-
format: "prettier --write .",
|
|
1308
|
-
test: "vitest",
|
|
1309
|
-
"test:watch": "vitest --watch",
|
|
1310
|
-
"test:coverage": "vitest --coverage"
|
|
1311
|
-
},
|
|
1312
|
-
dependencies: {
|
|
1313
|
-
"@babel/cli": "^7.28.6",
|
|
1314
|
-
"@babel/core": "^7.29.0",
|
|
1315
|
-
"@babel/plugin-proposal-decorators": "^7.29.0",
|
|
1316
|
-
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
1317
|
-
"@babel/plugin-transform-runtime": "^7.29.0",
|
|
1318
|
-
"@babel/preset-env": "^7.29.0",
|
|
1319
|
-
"@babel/preset-react": "^7.28.5",
|
|
1320
|
-
"@babel/preset-typescript": "^7.28.5",
|
|
1321
|
-
"@babel/runtime-corejs3": "^7.29.0",
|
|
1322
|
-
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.2",
|
|
1323
|
-
"@statoscope/webpack-plugin": "^5.29.0",
|
|
1324
|
-
"@types/columnify": "^1.5.4",
|
|
1325
|
-
"@types/handlebars-helpers": "^0.5.6",
|
|
1326
|
-
"@types/lodash": "^4.17.23",
|
|
1327
|
-
"@types/node": "^22.19.8",
|
|
1328
|
-
"@types/node-notifier": "^8.0.5",
|
|
1329
|
-
"@types/prompts": "^2.4.9",
|
|
1330
|
-
"@types/resolve-bin": "^0.4.3",
|
|
1331
|
-
"@types/webpack-config-utils": "^2.3.4",
|
|
1332
|
-
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
1333
|
-
"@typescript-eslint/parser": "^7.18.0",
|
|
1334
|
-
autoprefixer: "^10.4.24",
|
|
1335
|
-
"babel-loader": "^10.0.0",
|
|
1336
|
-
"babel-plugin-istanbul": "^7.0.1",
|
|
1337
|
-
"babel-plugin-lodash": "^3.3.4",
|
|
1338
|
-
chalk: "^5.6.2",
|
|
1339
|
-
"clean-webpack-plugin": "^4.0.0",
|
|
1340
|
-
columnify: "^1.6.0",
|
|
1341
|
-
commander: "^14.0.3",
|
|
1342
|
-
"copy-webpack-plugin": "^13.0.1",
|
|
1343
|
-
"core-js": "^3.48.0",
|
|
1344
|
-
"css-loader": "^7.1.3",
|
|
1345
|
-
"css-minimizer-webpack-plugin": "^7.0.4",
|
|
1346
|
-
dotenv: "^17.2.3",
|
|
1347
|
-
"env-paths": "^4.0.0",
|
|
1348
|
-
"escape-string-regexp": "^5.0.0",
|
|
1349
|
-
eslint: "^8.57.1",
|
|
1350
|
-
"eslint-config-prettier": "^10.1.8",
|
|
1351
|
-
"eslint-import-resolver-typescript": "^3.10.1",
|
|
1352
|
-
"eslint-plugin-deprecation": "^3.0.0",
|
|
1353
|
-
"eslint-plugin-import": "^2.32.0",
|
|
1354
|
-
"eslint-plugin-markdownlint": "^0.9.0",
|
|
1355
|
-
"eslint-plugin-promise": "^7.2.1",
|
|
1356
|
-
"eslint-plugin-unused-imports": "^3.2.0",
|
|
1357
|
-
"eslint-plugin-yml": "^1.19.1",
|
|
1358
|
-
"eslint-webpack-plugin": "^5.0.2",
|
|
1359
|
-
execa: "^9.6.1",
|
|
1360
|
-
"file-loader": "^6.2.0",
|
|
1361
|
-
"fork-ts-checker-webpack-plugin": "^9.1.0",
|
|
1362
|
-
glob: "^13.0.1",
|
|
1363
|
-
handlebars: "^4.7.8",
|
|
1364
|
-
"handlebars-helpers": "^0.10.0",
|
|
1365
|
-
"html-loader": "^5.1.0",
|
|
1366
|
-
"html-webpack-plugin": "^5.6.6",
|
|
1367
|
-
"js-yaml": "^4.1.1",
|
|
1368
|
-
"json-loader": "^0.5.7",
|
|
1369
|
-
ky: "^1.14.3",
|
|
1370
|
-
lodash: "^4.17.23",
|
|
1371
|
-
"mini-css-extract-plugin": "^2.10.0",
|
|
1372
|
-
"node-notifier": "^10.0.1",
|
|
1373
|
-
portfinder: "^1.0.38",
|
|
1374
|
-
postcss: "^8.5.6",
|
|
1375
|
-
"postcss-custom-properties": "^14.0.6",
|
|
1376
|
-
"postcss-import": "^16.1.1",
|
|
1377
|
-
"postcss-loader": "^8.2.0",
|
|
1378
|
-
"postcss-nested": "^7.0.2",
|
|
1379
|
-
prettier: "^3.8.1",
|
|
1380
|
-
prompts: "^2.4.2",
|
|
1381
|
-
"react-refresh": "^0.18.0",
|
|
1382
|
-
"resolve-url-loader": "^5.0.0",
|
|
1383
|
-
sass: "^1.97.3",
|
|
1384
|
-
"sass-loader": "^16.0.6",
|
|
1385
|
-
"strip-indent": "^4.1.1",
|
|
1386
|
-
"style-loader": "^4.0.0",
|
|
1387
|
-
"terser-webpack-plugin": "^5.3.16",
|
|
1388
|
-
"tsconfig-paths-webpack-plugin": "^4.2.0",
|
|
1389
|
-
tsup: "^8.5.1",
|
|
1390
|
-
typescript: "^5.9.3",
|
|
1391
|
-
"url-loader": "^4.1.1",
|
|
1392
|
-
vitest: "^4.0.18",
|
|
1393
|
-
webpack: "^5.105.0",
|
|
1394
|
-
"webpack-cli": "^6.0.1",
|
|
1395
|
-
"webpack-config-utils": "^2.3.1",
|
|
1396
|
-
"webpack-dev-server": "^5.2.3",
|
|
1397
|
-
"yaml-loader": "^0.9.0",
|
|
1398
|
-
zod: "^4.3.6"
|
|
1399
|
-
},
|
|
1400
|
-
devDependencies: {
|
|
1401
|
-
"@types/js-yaml": "^4.0.9"
|
|
1402
|
-
}
|
|
1403
|
-
};
|
|
806
|
+
//#endregion
|
|
807
|
+
//#region package.json
|
|
808
|
+
var name = "@raisenow/tamaro-cli";
|
|
809
|
+
var version = "1.7.0-dev.1";
|
|
1404
810
|
|
|
1405
|
-
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region src/cli.ts
|
|
813
|
+
/**
|
|
814
|
+
* Makes the script crash on unhandled rejections instead of silently
|
|
815
|
+
* ignoring them. In the future, promise rejections that are not handled will
|
|
816
|
+
* terminate the Node.js process with a non-zero exit code.
|
|
817
|
+
*/
|
|
1406
818
|
process.on("unhandledRejection", (error) => {
|
|
1407
|
-
|
|
819
|
+
throw error;
|
|
1408
820
|
});
|
|
1409
821
|
process.on("SIGINT", () => {
|
|
1410
|
-
|
|
822
|
+
halt();
|
|
1411
823
|
});
|
|
1412
|
-
|
|
1413
|
-
cli.command("dev").description(
|
|
1414
|
-
|
|
1415
|
-
).option(
|
|
1416
|
-
"--local-core",
|
|
1417
|
-
"Load Tamaro Core from localhost:1234 instead of the CDN",
|
|
1418
|
-
false
|
|
1419
|
-
).option(
|
|
1420
|
-
"--https",
|
|
1421
|
-
"Let local web server serve Tamaro with SSL encryption",
|
|
1422
|
-
false
|
|
1423
|
-
).option("--port <port>", "Web server port", `${DEFAULT_PORT}`).option("--env <env>", "Environment (dev, stage, prod)").option("--nolint", "Disable ESLint", false).action(async (options) => {
|
|
1424
|
-
await dev(options);
|
|
824
|
+
const cli = createCommand().name(name).version(version, "-v, --version");
|
|
825
|
+
cli.command("dev").description("Run the local development server for Tamaro Core or a particular customer configuration").option("--local-core", "Load Tamaro Core from localhost:1234 instead of the CDN", false).option("--https", "Let local web server serve Tamaro with SSL encryption", false).option("--port <port>", "Web server port", `${DEFAULT_PORT}`).option("--env <env>", "Environment (dev, stage, prod)").option("--nolint", "Disable ESLint", false).option("--debug", "Enable debug mode", false).action(async (options) => {
|
|
826
|
+
await dev(options);
|
|
1425
827
|
});
|
|
1426
|
-
cli.command("build").description(
|
|
1427
|
-
|
|
1428
|
-
)
|
|
1429
|
-
|
|
1430
|
-
"Load Tamaro Core from localhost:1234 instead of the CDN",
|
|
1431
|
-
false
|
|
1432
|
-
).option("--analyze", 'Generate bundle statistics to "reports" folder', false).option("--serve", "Run the generated bundle with a local web server", false).option(
|
|
1433
|
-
"--https",
|
|
1434
|
-
"Let local web server serve Tamaro with SSL encryption",
|
|
1435
|
-
false
|
|
1436
|
-
).option("--port <port>", "Web server port", `${DEFAULT_PORT}`).option("--env <env>", "Environment (dev, stage, prod)").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option(
|
|
1437
|
-
"--deploy",
|
|
1438
|
-
"Deploy Tamaro Core or a customer configuration bundle to AWS S3",
|
|
1439
|
-
false
|
|
1440
|
-
).option(
|
|
1441
|
-
"--tag <tag>",
|
|
1442
|
-
"Tag which should be used for the deployment of the bundle",
|
|
1443
|
-
DEFAULT_TAG
|
|
1444
|
-
).option("--nolint", "Disable ESLint", false).action(async (options) => {
|
|
1445
|
-
await build(options);
|
|
1446
|
-
if (options.serve) {
|
|
1447
|
-
await serve(options);
|
|
1448
|
-
}
|
|
1449
|
-
if (options.deploy) {
|
|
1450
|
-
await deploy(options);
|
|
1451
|
-
}
|
|
828
|
+
cli.command("build").description("Build an optimised (minified) bundle of Tamaro Core or a customer configuration").option("--local-core", "Load Tamaro Core from localhost:1234 instead of the CDN", false).option("--analyze", "Generate bundle statistics to \"reports\" folder", false).option("--serve", "Run the generated bundle with a local web server", false).option("--https", "Let local web server serve Tamaro with SSL encryption", false).option("--port <port>", "Web server port", `${DEFAULT_PORT}`).option("--env <env>", "Environment (dev, stage, prod)").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--deploy", "Deploy Tamaro Core or a customer configuration bundle to AWS S3", false).option("--tag <tag>", "Tag which should be used for the deployment of the bundle", DEFAULT_TAG).option("--nolint", "Disable ESLint", false).option("--debug", "Enable debug mode", false).action(async (options) => {
|
|
829
|
+
await build(options);
|
|
830
|
+
if (options.serve) await serve(options);
|
|
831
|
+
if (options.deploy) await deploy(options);
|
|
1452
832
|
});
|
|
1453
|
-
cli.command("serve").description("Run a local web server for pre-built bundle").option("--port <port>", "Web server port", `${DEFAULT_PORT}`).option(
|
|
1454
|
-
|
|
1455
|
-
"Let local web server serve Tamaro with SSL encryption",
|
|
1456
|
-
false
|
|
1457
|
-
).action(async (options) => {
|
|
1458
|
-
await serve(options);
|
|
833
|
+
cli.command("serve").description("Run a local web server for pre-built bundle").option("--port <port>", "Web server port", `${DEFAULT_PORT}`).option("--https", "Let local web server serve Tamaro with SSL encryption", false).action(async (options) => {
|
|
834
|
+
await serve(options);
|
|
1459
835
|
});
|
|
1460
|
-
cli.command("deploy").description(
|
|
1461
|
-
|
|
1462
|
-
).option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option(
|
|
1463
|
-
"--tag <tag>",
|
|
1464
|
-
"Tag which should be used for the deployment of the bundle",
|
|
1465
|
-
DEFAULT_TAG
|
|
1466
|
-
).option(
|
|
1467
|
-
"--dryrun",
|
|
1468
|
-
"Displays the operations that would be performed without actually running them",
|
|
1469
|
-
false
|
|
1470
|
-
).action(async (options) => {
|
|
1471
|
-
await deploy(options);
|
|
836
|
+
cli.command("deploy").description("Deploy a pre-built Tamaro Core or customer configuration bundle to AWS S3").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--tag <tag>", "Tag which should be used for the deployment of the bundle", DEFAULT_TAG).option("--dryrun", "Displays the operations that would be performed without actually running them", false).action(async (options) => {
|
|
837
|
+
await deploy(options);
|
|
1472
838
|
});
|
|
1473
|
-
cli.command("list-deployed").description(
|
|
1474
|
-
|
|
1475
|
-
).option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option(
|
|
1476
|
-
"--config <config>",
|
|
1477
|
-
"Configuration name (default: current customer configuration)"
|
|
1478
|
-
).action(async (options) => {
|
|
1479
|
-
await listDeployed(options);
|
|
839
|
+
cli.command("list-deployed").description("List deployments of Tamaro Core or a particular customer configuration").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--config <config>", "Configuration name (default: current customer configuration)").action(async (options) => {
|
|
840
|
+
await listDeployed(options);
|
|
1480
841
|
});
|
|
1481
|
-
cli.command("deploy-email-config").description("Deploy a widget's email configuration to AWS S3").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--bucket <bucket>", "AWS bucket for email configs").option(
|
|
1482
|
-
|
|
1483
|
-
"Displays the operations that would be performed without actually running them",
|
|
1484
|
-
false
|
|
1485
|
-
).action(async (options) => {
|
|
1486
|
-
await deployEmailConfig(options);
|
|
842
|
+
cli.command("deploy-email-config").description("Deploy a widget's email configuration to AWS S3").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--bucket <bucket>", "AWS bucket for email configs").option("--dryrun", "Displays the operations that would be performed without actually running them", false).action(async (options) => {
|
|
843
|
+
await deployEmailConfig(options);
|
|
1487
844
|
});
|
|
1488
|
-
cli.command("undeploy").description(
|
|
1489
|
-
|
|
1490
|
-
).option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--tag <tag>", "Tag which should be undeployed", DEFAULT_TAG).option("--all", "Undeploy all tags", false).option(
|
|
1491
|
-
"--dryrun",
|
|
1492
|
-
"Displays the operations that would be performed without actually running them",
|
|
1493
|
-
false
|
|
1494
|
-
).action(async (options) => {
|
|
1495
|
-
await undeploy(options);
|
|
845
|
+
cli.command("undeploy").description("Undeploy a Tamaro Core or customer configuration bundle from AWS S3").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--tag <tag>", "Tag which should be undeployed").option("--all", "Undeploy all tags", false).option("--dryrun", "Displays the operations that would be performed without actually running them", false).action(async (options) => {
|
|
846
|
+
await undeploy(options);
|
|
1496
847
|
});
|
|
1497
|
-
cli.command("undeploy-email-config").description("Undeploy a widget's email configuration from AWS S3").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--bucket <bucket>", "AWS bucket for email configs").option(
|
|
1498
|
-
|
|
1499
|
-
"Displays the operations that would be performed without actually running them",
|
|
1500
|
-
false
|
|
1501
|
-
).action(async (options) => {
|
|
1502
|
-
await undeployEmailConfig(options);
|
|
848
|
+
cli.command("undeploy-email-config").description("Undeploy a widget's email configuration from AWS S3").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--bucket <bucket>", "AWS bucket for email configs").option("--stage", "Undeploy from stage environment (alternative to --bucket)").option("--prod", "Undeploy from prod environment (alternative to --bucket)").option("--dryrun", "Displays the operations that would be performed without actually running them", false).action(async (options) => {
|
|
849
|
+
await undeployEmailConfig(options);
|
|
1503
850
|
});
|
|
1504
|
-
cli.command("archive").description(
|
|
1505
|
-
|
|
1506
|
-
).option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option(
|
|
1507
|
-
"--dryrun",
|
|
1508
|
-
"Displays the operations that would be performed without actually running them",
|
|
1509
|
-
false
|
|
1510
|
-
).action((options) => {
|
|
1511
|
-
archive(options);
|
|
851
|
+
cli.command("archive").description("Archive a customer configuration by moving it to the _archived folder").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--dryrun", "Displays the operations that would be performed without actually running them", false).action((options) => {
|
|
852
|
+
archive(options);
|
|
1512
853
|
});
|
|
1513
|
-
cli.command("unarchive").description(
|
|
1514
|
-
|
|
1515
|
-
).option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option(
|
|
1516
|
-
"--dryrun",
|
|
1517
|
-
"Displays the operations that would be performed without actually running them",
|
|
1518
|
-
false
|
|
1519
|
-
).action((options) => {
|
|
1520
|
-
unarchive(options);
|
|
854
|
+
cli.command("unarchive").description("Unarchive a customer configuration by restoring it from the _archived folder").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--dryrun", "Displays the operations that would be performed without actually running them", false).action((options) => {
|
|
855
|
+
unarchive(options);
|
|
1521
856
|
});
|
|
1522
|
-
cli.command("
|
|
1523
|
-
|
|
1524
|
-
"Displays the operations that would be performed without actually running them",
|
|
1525
|
-
false
|
|
1526
|
-
).action(async (options) => {
|
|
1527
|
-
await updateEpms(options);
|
|
1528
|
-
});
|
|
1529
|
-
cli.command("validate").description(
|
|
1530
|
-
"Validate the current Tamaro configuration to avoid common errors"
|
|
1531
|
-
).action(async () => {
|
|
1532
|
-
await validate();
|
|
857
|
+
cli.command("validate").description("Validate the current Tamaro configuration to avoid common errors").action(async () => {
|
|
858
|
+
await validate();
|
|
1533
859
|
});
|
|
1534
860
|
(async () => {
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
logError(error.stack);
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
861
|
+
try {
|
|
862
|
+
logTitle(`${name} ${version}\n`);
|
|
863
|
+
await cli.parseAsync(process.argv);
|
|
864
|
+
} catch (error) {
|
|
865
|
+
if (error.signal === "SIGINT" && error.signalDescription) logError(`\n${error.signalDescription}`);
|
|
866
|
+
else {
|
|
867
|
+
console.log("");
|
|
868
|
+
logError(error.stack);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
1548
871
|
})();
|
|
872
|
+
|
|
873
|
+
//#endregion
|
|
874
|
+
export { };
|