@raisenow/tamaro-cli 1.4.2 → 1.6.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.
@@ -0,0 +1,245 @@
1
+ import { globSync } from "glob";
2
+ import { execaCommandSync } from "execa";
3
+ import chalk from "chalk";
4
+ import columnify from "columnify";
5
+ import stripIndent from "strip-indent";
6
+ import { createRequire } from "module";
7
+ import { basename, dirname, join, relative, resolve } from "path";
8
+ import { config } from "dotenv";
9
+ import path from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import { existsSync, realpathSync } from "fs";
12
+ import { getIfUtils } from "webpack-config-utils";
13
+
14
+ //#region src/lib/logging.ts
15
+ const logTitle = (title) => {
16
+ console.log(chalk.bold(title));
17
+ };
18
+ const logError = (message) => {
19
+ if (message) console.log(chalk.red(message));
20
+ };
21
+ const logCommand = (cmd) => {
22
+ console.log(`\n${chalk.dim(stripIndent(cmd).trim())}\n`);
23
+ };
24
+ const logDataTable = (data) => {
25
+ console.log(columnify(data, { showHeaders: false }));
26
+ console.log("");
27
+ };
28
+
29
+ //#endregion
30
+ //#region src/lib/command.ts
31
+ const halt = (message) => {
32
+ logError(message);
33
+ process.exit(1);
34
+ };
35
+ const prepareCommand = (cmd) => {
36
+ return cmd.replace(/\n/gm, " ").replace(/[ \t]{2,}/gm, " ").trim();
37
+ };
38
+ const runCommandSync = (cmd, options) => {
39
+ return execaCommandSync(prepareCommand(cmd), options);
40
+ };
41
+
42
+ //#endregion
43
+ //#region src/lib/constants.ts
44
+ const DEFAULT_TAG = "latest";
45
+ const DEFAULT_PORT = 1234;
46
+ const AWS_S3_BUCKET_TAMARO = "tamaro.raisenow.com";
47
+ const AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE = "rnw-stage-email-service";
48
+ const AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD = "rnw-email-service";
49
+ const CORE_CONFIG_NAME = "tamaro-core";
50
+ const AWS_CLOUDFRONT_DISTRIBUTION_ID = "EHJ1OM458YQ0I";
51
+ const HTTPS_CRT_FILE = "localhost.crt";
52
+ const HTTPS_KEY_FILE = "localhost.key";
53
+
54
+ //#endregion
55
+ //#region node_modules/.pnpm/tsdown@0.20.1_synckit@0.11.11_typescript@5.9.3/node_modules/tsdown/esm-shims.js
56
+ const getFilename = () => fileURLToPath(import.meta.url);
57
+ const getDirname = () => path.dirname(getFilename());
58
+ const __dirname = /* @__PURE__ */ getDirname();
59
+
60
+ //#endregion
61
+ //#region src/lib/resolve.ts
62
+ const require$1 = createRequire(import.meta.url);
63
+ const moduleFileExtensions = [
64
+ "ts",
65
+ "tsx",
66
+ "js",
67
+ "jsx"
68
+ ];
69
+ const extensions = moduleFileExtensions.map((v) => `.${v}`);
70
+ const TAMARO_CORE_PACKAGE_NAMES = ["@raisenow/tamaro-core"];
71
+ const TAMARO_CONFIGURATIONS_PACKAGE_NAMES = ["@raisenow/tamaro-configurations"];
72
+ const TAMARO_SELF_SERVICE_PACKAGE_NAMES = ["@raisenow/tamaro-self-service"];
73
+ const resolveApp = (relativePath) => resolve(realpathSync(process.cwd()), relativePath);
74
+ const resolveOwn = (relativePath) => resolve(__dirname, "..", relativePath);
75
+ const resolveModule = (resolveFn, filePath) => {
76
+ const extension = moduleFileExtensions.find((extension) => existsSync(resolveFn(`${filePath}.${extension}`)));
77
+ if (extension) return resolveFn(`${filePath}.${extension}`);
78
+ return resolveFn(`${filePath}.js`);
79
+ };
80
+ /**
81
+ * Since Tamaro CLI is used to build different packages
82
+ * (Tamaro Core, Tamaro Self Service, Tamaro Configurations)
83
+ * and they may use differnt ESLint versions and config formats,
84
+ * we need to correctly resolve it before passing into Webpack ESLint plugin.
85
+ */
86
+ const resolveEslintPluginConfig = (paths) => {
87
+ try {
88
+ const opts = { paths: [paths.appNodeModules] };
89
+ const eslintPath = require$1.resolve("eslint", opts);
90
+ const configType = require$1(require$1.resolve("eslint/package.json", opts)).version.startsWith("8.") ? "eslintrc" : "flat";
91
+ return {
92
+ extensions: moduleFileExtensions,
93
+ eslintPath,
94
+ cwd: paths.app,
95
+ configType
96
+ };
97
+ } catch (error) {
98
+ console.error(error);
99
+ return;
100
+ }
101
+ };
102
+ const resolveBin = (name) => {
103
+ const pkgPath = require$1.resolve(`${name}/package.json`);
104
+ const { bin } = require$1(pkgPath);
105
+ return join(dirname(pkgPath), typeof bin === "object" ? bin[name] : bin);
106
+ };
107
+ const getWidgetUuid = () => basename(resolveApp("."));
108
+ const getPaths = (ifCore) => {
109
+ return ifCore({
110
+ root: resolveApp("."),
111
+ app: resolveApp("."),
112
+ appEntry: resolveModule(resolveApp, "src/index"),
113
+ appDist: resolveApp("dist"),
114
+ appNodeModules: resolveApp("node_modules"),
115
+ appTsConfig: resolveApp("tsconfig.json"),
116
+ appHtml: resolveApp("src/*.html"),
117
+ appEnv: resolveApp(".env*"),
118
+ appTailwindConfig: resolveApp("tailwind.config.js")
119
+ }, {
120
+ root: resolveApp("../.."),
121
+ app: resolveApp("."),
122
+ appEntry: resolveModule(resolveApp, "widget"),
123
+ appDist: resolveApp(`../../dist/${getWidgetUuid()}`),
124
+ appNodeModules: resolveApp("../../node_modules"),
125
+ appTsConfig: resolveApp("tsconfig.json"),
126
+ appHtml: resolveApp("*.html"),
127
+ appEnv: resolveApp(".env*"),
128
+ appTailwindConfig: void 0
129
+ });
130
+ };
131
+ const getRelativePaths = (paths) => {
132
+ const relativePaths = {};
133
+ for (const [type, absPath] of Object.entries(paths)) if (absPath) relativePaths[type] = relative("./", absPath) || ".";
134
+ return relativePaths;
135
+ };
136
+ const getIfCoreFns = () => {
137
+ const corePkgPath = resolveApp("package.json");
138
+ const configsPkgPath = resolveApp("../../package.json");
139
+ let packageName;
140
+ if (existsSync(corePkgPath)) packageName = require$1(corePkgPath).name;
141
+ else if (existsSync(configsPkgPath)) packageName = require$1(configsPkgPath).name;
142
+ if (packageName) return getIfUtils({ core: TAMARO_CORE_PACKAGE_NAMES.includes(packageName) }, ["core"]);
143
+ logError(stripIndent(`\
144
+ You must run "npx @raisenow/tamaro-cli" commands from:
145
+ 1. Root of "${chalk.bold(TAMARO_CORE_PACKAGE_NAMES[0])}" package folder.
146
+ 2. Root of particular customer configuration folder of "${chalk.bold(TAMARO_CONFIGURATIONS_PACKAGE_NAMES[0])}" package.
147
+ 3. "src/self-service" folder of "${chalk.bold(TAMARO_SELF_SERVICE_PACKAGE_NAMES[0])}" package.
148
+ You are currently in "${chalk.bold(realpathSync(process.cwd()))}".
149
+ `));
150
+ process.exit(1);
151
+ };
152
+
153
+ //#endregion
154
+ //#region src/lib/env.ts
155
+ const require = createRequire(import.meta.url);
156
+ const getEnvVars = (files, ifMin, ifCore, ifLocalCore, ifHttps) => {
157
+ const filePath = files.find((file) => basename(file) === ".env");
158
+ if (filePath) config({ path: filePath });
159
+ process.env.NODE_ENV ??= ifMin("production", "development");
160
+ process.env.BABEL_ENV ??= ifMin("production", "development");
161
+ process.env.EXPOSE_VAR ??= ifCore("rnw.tamaroCore", "rnw.tamaro");
162
+ process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET ??= ifCore("rnw-tamaro-core", "rnw-tamaro");
163
+ process.env.WEBPACK_UNIQUE_NAME ??= ifCore("RnwTamaroCore", "RnwTamaro");
164
+ process.env.BUILD_DATE = (/* @__PURE__ */ new Date()).toISOString();
165
+ process.env.PUBLIC_URL ??= "";
166
+ process.env.HMR_ENABLED ??= ifMin("false", "true");
167
+ if (ifCore()) {
168
+ process.env.PRODUCT_NAME = "tamaro";
169
+ const { version } = require(resolveApp("package.json"));
170
+ process.env.PRODUCT_VERSION = version;
171
+ }
172
+ if (!ifCore()) {
173
+ process.env.WIDGET_UUID = getWidgetUuid();
174
+ if (ifLocalCore()) {
175
+ const protocol = ifHttps() ? "https" : "http";
176
+ process.env.CORE_URL = `${protocol}://localhost:1234/index.js`;
177
+ } else {
178
+ let version = process.env.CORE_VERSION;
179
+ version = version ? `@${version}` : "";
180
+ process.env.CORE_URL_PATTERN ??= "https://cdn.jsdelivr.net/npm/@raisenow/tamaro-core{{version}}/dist/index.js";
181
+ process.env.CORE_URL ??= process.env.CORE_URL_PATTERN.replace("{{version}}", version);
182
+ }
183
+ }
184
+ const varNames = [
185
+ "NODE_ENV",
186
+ "BABEL_ENV",
187
+ "EXPOSE_VAR",
188
+ "ELEMENT_ATTRIBUTE_DATA_WIDGET",
189
+ "WEBPACK_UNIQUE_NAME",
190
+ "BUILD_DATE",
191
+ "PUBLIC_URL",
192
+ "PRODUCT_NAME",
193
+ "PRODUCT_VERSION",
194
+ "WIDGET_UUID",
195
+ "CORE_URL",
196
+ "CORE_URL_PATTERN",
197
+ "CORE_VERSION",
198
+ "DISABLE_URL_VERSION_OVERRIDE",
199
+ "EPP_API_KEY_DEFAULT",
200
+ "EPP_API_URL_STAGE",
201
+ "EPP_API_URL_PROD",
202
+ "EPMS_API_URL_STAGE",
203
+ "EPMS_API_URL_PROD",
204
+ "EPP_PROXY_URL_STAGE",
205
+ "EPP_PROXY_URL_PROD",
206
+ "EPMS_PROXY_URL_STAGE",
207
+ "EPMS_PROXY_URL_PROD",
208
+ "EPMS_TWINT_CHECKOUT_URL_STAGE",
209
+ "EPMS_TWINT_CHECKOUT_URL_PROD"
210
+ ];
211
+ const raw = Object.keys(process.env).filter((key) => key.startsWith("PUBLIC_") || varNames.includes(key)).reduce((env, key) => {
212
+ env[key] = process.env[key];
213
+ return env;
214
+ }, {});
215
+ return {
216
+ raw,
217
+ stringified: { "process.env": Object.keys(raw).reduce((env, key) => {
218
+ env[key] = JSON.stringify(raw[key]);
219
+ return env;
220
+ }, {}) }
221
+ };
222
+ };
223
+ const assertEnvValid = (env) => {
224
+ const { ifCore } = getIfCoreFns();
225
+ const envs = globSync(getPaths(ifCore).appEnv).map((file) => basename(file).replace(/^\.env\./, "")).map((file) => basename(file).replace(/^\.env$/, "")).filter((v) => !!v);
226
+ if (envs.length === 0) {
227
+ if (env) console.log("Flag \"--env\" is ignored.");
228
+ }
229
+ if (envs.length !== 0) {
230
+ if (!env) halt("Flag \"--env\" is required.");
231
+ if (env && !envs.includes(env)) halt(stripIndent(`
232
+ Flag "--env" has wrong value.
233
+ Available values are: ${envs.map((v) => `"${v}"`).join(", ")}.
234
+ `));
235
+ }
236
+ };
237
+ const applyEnv = (env) => {
238
+ if (!env) return;
239
+ const { ifCore } = getIfCoreFns();
240
+ const filePath = globSync(getPaths(ifCore).appEnv).find((file) => basename(file) === `.env.${env}`);
241
+ if (filePath) config({ path: filePath });
242
+ };
243
+
244
+ //#endregion
245
+ export { runCommandSync as C, logTitle as D, logError as E, halt as S, logDataTable as T, CORE_CONFIG_NAME as _, getIfCoreFns as a, HTTPS_CRT_FILE as b, getWidgetUuid as c, resolveEslintPluginConfig as d, resolveOwn as f, AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE as g, AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD as h, extensions as i, resolveApp as l, AWS_S3_BUCKET_TAMARO as m, assertEnvValid as n, getPaths as o, AWS_CLOUDFRONT_DISTRIBUTION_ID as p, getEnvVars as r, getRelativePaths as s, applyEnv as t, resolveBin as u, DEFAULT_PORT as v, logCommand as w, HTTPS_KEY_FILE as x, DEFAULT_TAG as y };