@raisenow/tamaro-cli 1.0.10 → 1.0.13
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/{.eslintrc.js → .eslintrc.cjs} +2 -9
- package/.gitignore +3 -3
- package/.nvmrc +1 -1
- package/{.prettierrc.js → .prettierrc.cjs} +1 -0
- package/{readme.md → README.md} +36 -32
- package/dist/chunk-OXDXJ5B5.js +249 -0
- package/dist/cli.js +257 -324
- package/dist/webpack.config.js +108 -341
- package/package.json +35 -44
- package/readme.html +1 -1
- package/src/cli.ts +31 -19
- package/src/commands/build.ts +33 -28
- package/src/commands/deploy-email-config.ts +29 -21
- package/src/commands/deploy.ts +52 -39
- package/src/commands/dev.ts +29 -18
- package/src/commands/list-deployed.ts +23 -13
- package/src/commands/serve.ts +36 -12
- package/src/lib/InterpolateHtmlPlugin.ts +10 -8
- package/src/lib/aws.ts +43 -35
- package/src/lib/command.ts +27 -0
- package/src/lib/constants.ts +7 -0
- package/src/lib/env.ts +145 -0
- package/src/lib/logging.ts +32 -0
- package/src/lib/notifier.ts +22 -0
- package/src/lib/resolve.ts +144 -0
- package/src/webpack.config.ts +26 -77
- package/tsconfig.json +1 -1
- package/src/lib/helpers.ts +0 -356
- package/src/lib/polyfills.js +0 -8
package/src/lib/helpers.ts
DELETED
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
import {basename, relative, resolve} from 'path'
|
|
2
|
-
import {existsSync, realpathSync} from 'fs'
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import notifier from 'node-notifier'
|
|
5
|
-
import {getIfUtils, IfUtils, IfUtilsFn} from 'webpack-config-utils'
|
|
6
|
-
import columnify from 'columnify'
|
|
7
|
-
import boxen from 'boxen'
|
|
8
|
-
import {expand as dotenvExpand} from 'dotenv-expand'
|
|
9
|
-
import {config as dotenvConfig} from 'dotenv'
|
|
10
|
-
import open from 'open'
|
|
11
|
-
import stripIndent from 'strip-indent'
|
|
12
|
-
import {commandSync, ExecaSyncReturnValue, SyncOptions} from 'execa'
|
|
13
|
-
|
|
14
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
15
|
-
|
|
16
|
-
export type ResolveFn = (relativePath: string) => string
|
|
17
|
-
|
|
18
|
-
export type EnvVars = {
|
|
19
|
-
[key: string]: string | undefined
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
-
// Supported packages
|
|
24
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
25
|
-
|
|
26
|
-
const TAMARO_CORE_PACKAGE_NAMES = ['@raisenow/tamaro-core']
|
|
27
|
-
const TAMARO_CONFIGURATIONS_PACKAGE_NAMES = ['@raisenow/tamaro-configurations']
|
|
28
|
-
|
|
29
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
30
|
-
|
|
31
|
-
export const getIfCoreFns = (): IfUtils => {
|
|
32
|
-
const corePkgPath = resolveApp('package.json')
|
|
33
|
-
const configsPkgPath = resolveApp('../../package.json')
|
|
34
|
-
|
|
35
|
-
if (existsSync(corePkgPath)) {
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
37
|
-
const {name} = require(corePkgPath)
|
|
38
|
-
|
|
39
|
-
if (TAMARO_CORE_PACKAGE_NAMES.includes(name)) {
|
|
40
|
-
return getIfUtils({core: true}, ['core'])
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (existsSync(configsPkgPath)) {
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
46
|
-
const {name} = require(configsPkgPath)
|
|
47
|
-
|
|
48
|
-
if (TAMARO_CONFIGURATIONS_PACKAGE_NAMES.includes(name)) {
|
|
49
|
-
return getIfUtils({core: false}, ['core'])
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
logError(
|
|
54
|
-
stripIndent(`\
|
|
55
|
-
You must run "npx @raisenow/tamaro-cli" commands from:
|
|
56
|
-
1. Root of "${chalk.bold(TAMARO_CORE_PACKAGE_NAMES[0])}" package folder.
|
|
57
|
-
2. Root of particular customer configuration folder of "${chalk.bold(
|
|
58
|
-
TAMARO_CONFIGURATIONS_PACKAGE_NAMES[0],
|
|
59
|
-
)}" package.
|
|
60
|
-
You are currently in "${chalk.bold(realpathSync(process.cwd()))}".
|
|
61
|
-
`),
|
|
62
|
-
)
|
|
63
|
-
process.exit(1)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
67
|
-
// Extensions
|
|
68
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
69
|
-
|
|
70
|
-
export const moduleFileExtensions = ['ts', 'tsx', 'js', 'jsx']
|
|
71
|
-
export const extensions = moduleFileExtensions.map((v) => `.${v}`)
|
|
72
|
-
|
|
73
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
74
|
-
// Paths
|
|
75
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
76
|
-
|
|
77
|
-
export const resolveApp: ResolveFn = (relativePath) =>
|
|
78
|
-
resolve(realpathSync(process.cwd()), relativePath)
|
|
79
|
-
|
|
80
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
81
|
-
|
|
82
|
-
// __dirname is "dist" in runtime
|
|
83
|
-
export const resolveOwn: ResolveFn = (relativePath) =>
|
|
84
|
-
resolve(__dirname, '..', relativePath)
|
|
85
|
-
|
|
86
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
87
|
-
|
|
88
|
-
export const resolveModule = (resolveFn: ResolveFn, filePath: string) => {
|
|
89
|
-
const extension = moduleFileExtensions.find((extension) =>
|
|
90
|
-
existsSync(resolveFn(`${filePath}.${extension}`)),
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
if (extension) {
|
|
94
|
-
return resolveFn(`${filePath}.${extension}`)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return resolveFn(`${filePath}.js`)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
101
|
-
|
|
102
|
-
export const getWidgetUuid = () => basename(resolveApp('.'))
|
|
103
|
-
|
|
104
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
105
|
-
|
|
106
|
-
export const getPaths = (ifCore: IfUtilsFn) => {
|
|
107
|
-
return ifCore(
|
|
108
|
-
{
|
|
109
|
-
app: resolveApp('.'),
|
|
110
|
-
appEntry: resolveModule(resolveApp, 'src/index'),
|
|
111
|
-
appDist: resolveApp('dist'),
|
|
112
|
-
appNodeModules: resolveApp('node_modules'),
|
|
113
|
-
appTsConfig: resolveApp('tsconfig.json'),
|
|
114
|
-
appHtml: resolveApp('src/*.html'),
|
|
115
|
-
appEnv: resolveApp('.env'),
|
|
116
|
-
appTailwindConfig: resolveApp('tailwind.config.js'),
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
app: resolveApp('.'),
|
|
120
|
-
appEntry: resolveModule(resolveApp, 'widget'),
|
|
121
|
-
appDist: resolveApp(`../../dist/${getWidgetUuid()}`),
|
|
122
|
-
appNodeModules: resolveApp('../../node_modules'),
|
|
123
|
-
appTsConfig: resolveApp('tsconfig.json'),
|
|
124
|
-
appHtml: resolveApp('*.html'),
|
|
125
|
-
appEnv: resolveApp('.env'),
|
|
126
|
-
appTailwindConfig: undefined,
|
|
127
|
-
},
|
|
128
|
-
)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
132
|
-
|
|
133
|
-
type Paths = {
|
|
134
|
-
[key: string]: string | undefined
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export const getRelativePaths = (paths: Paths): Paths => {
|
|
138
|
-
const relativePaths: Paths = {}
|
|
139
|
-
|
|
140
|
-
for (const [type, absPath] of Object.entries(paths)) {
|
|
141
|
-
if (absPath) {
|
|
142
|
-
relativePaths[type] = relative('./', absPath) || '.'
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return relativePaths
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
150
|
-
// Env vars
|
|
151
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
152
|
-
|
|
153
|
-
export const getEnvVars = (
|
|
154
|
-
filePath: string,
|
|
155
|
-
ifMin: IfUtilsFn,
|
|
156
|
-
ifCore: IfUtilsFn,
|
|
157
|
-
ifLocalCore: IfUtilsFn,
|
|
158
|
-
) => {
|
|
159
|
-
dotenvExpand(dotenvConfig({path: filePath}))
|
|
160
|
-
|
|
161
|
-
process.env.NODE_ENV ??= ifMin('production', 'development')
|
|
162
|
-
process.env.BABEL_ENV ??= ifMin('production', 'development')
|
|
163
|
-
process.env.EXPOSE_VAR ??= ifCore('rnw.tamaroCore', 'rnw.tamaro')
|
|
164
|
-
process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET ??= ifCore(
|
|
165
|
-
'rnw-tamaro-core',
|
|
166
|
-
'rnw-tamaro',
|
|
167
|
-
)
|
|
168
|
-
process.env.WEBPACK_UNIQUE_NAME ??= ifCore('RnwTamaroCore', 'RnwTamaro')
|
|
169
|
-
|
|
170
|
-
// HMR doesn't work in ie11, it breaks everything.
|
|
171
|
-
// If you want to run dev-server and test in ie11, set HMR_ENABLED to 'false'
|
|
172
|
-
process.env.HMR_ENABLED ??= ifMin('false', 'true')
|
|
173
|
-
|
|
174
|
-
if (ifCore()) {
|
|
175
|
-
process.env.PRODUCT_NAME = 'tamaro'
|
|
176
|
-
|
|
177
|
-
const corePkgPath = resolveApp('package.json')
|
|
178
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
179
|
-
const {version} = require(corePkgPath)
|
|
180
|
-
|
|
181
|
-
process.env.PRODUCT_VERSION = version
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (!ifCore()) {
|
|
185
|
-
process.env.WIDGET_UUID = getWidgetUuid()
|
|
186
|
-
|
|
187
|
-
if (ifLocalCore()) {
|
|
188
|
-
process.env.CORE_URL = `http://0.0.0.0:1234/index.js`
|
|
189
|
-
} else {
|
|
190
|
-
let version = process.env.CORE_VERSION
|
|
191
|
-
version = version ? `@${version}` : ''
|
|
192
|
-
|
|
193
|
-
process.env.CORE_URL ??= `https://cdn.jsdelivr.net/npm/@raisenow/tamaro-core${version}/dist/index.js`
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// var names which will be exposed along with "PUBLIC_*" var names
|
|
198
|
-
const varNames = [
|
|
199
|
-
// common
|
|
200
|
-
'NODE_ENV',
|
|
201
|
-
'BABEL_ENV',
|
|
202
|
-
'EXPOSE_VAR',
|
|
203
|
-
'ELEMENT_ATTRIBUTE_DATA_WIDGET',
|
|
204
|
-
'WEBPACK_UNIQUE_NAME',
|
|
205
|
-
|
|
206
|
-
// core
|
|
207
|
-
'PRODUCT_NAME',
|
|
208
|
-
'PRODUCT_VERSION',
|
|
209
|
-
|
|
210
|
-
// config
|
|
211
|
-
'WIDGET_UUID',
|
|
212
|
-
'CORE_URL',
|
|
213
|
-
'CORE_VERSION', // must be explicitly specified in each config
|
|
214
|
-
'IS_CREDIT_CARD_IFRAME',
|
|
215
|
-
|
|
216
|
-
// // todo: Environment variables for twint-qr-base
|
|
217
|
-
// 'EPMS_ENV',
|
|
218
|
-
// 'SOLUTION_CONFIG_BASE_URL',
|
|
219
|
-
// 'SHORT_ID_RESOLUTION_URL',
|
|
220
|
-
// 'HANDSHAKE_RESOLUTION_URL',
|
|
221
|
-
// 'TWINT_CHECKOUT_PAGE',
|
|
222
|
-
]
|
|
223
|
-
|
|
224
|
-
// Collect all vars which names start from "PUBLIC_" or present in "varNames" array
|
|
225
|
-
const raw = Object.keys(process.env)
|
|
226
|
-
.filter((key) => /^PUBLIC_/.test(key) || varNames.includes(key))
|
|
227
|
-
.reduce<EnvVars>((env, key) => {
|
|
228
|
-
env[key] = process.env[key]
|
|
229
|
-
|
|
230
|
-
return env
|
|
231
|
-
}, {})
|
|
232
|
-
|
|
233
|
-
// Stringify all values so we can feed into webpack DefinePlugin
|
|
234
|
-
const stringified = {
|
|
235
|
-
'process.env': Object.keys(raw).reduce<EnvVars>((env, key) => {
|
|
236
|
-
env[key] = JSON.stringify(raw[key])
|
|
237
|
-
|
|
238
|
-
return env
|
|
239
|
-
}, {}),
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return {raw, stringified}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
246
|
-
// Other
|
|
247
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
248
|
-
|
|
249
|
-
export const delay = (ms: number) =>
|
|
250
|
-
new Promise((resolve) => setTimeout(resolve, ms))
|
|
251
|
-
|
|
252
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
253
|
-
|
|
254
|
-
export const logTitle = (title: string) => {
|
|
255
|
-
console.log(`\n${chalk.bold(title)}`)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
259
|
-
|
|
260
|
-
export const logError = (message?: string) => {
|
|
261
|
-
if (message) {
|
|
262
|
-
console.log(chalk.red(message))
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
267
|
-
|
|
268
|
-
export const fail = (message?: string) => {
|
|
269
|
-
logError(message)
|
|
270
|
-
process.exit(1)
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
274
|
-
|
|
275
|
-
export const logCommand = (command: string): void => {
|
|
276
|
-
console.log(chalk.dim(stripIndent(command)))
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
280
|
-
|
|
281
|
-
export const prepareCommand = (command: string): string => {
|
|
282
|
-
return command
|
|
283
|
-
.replace(/\n/gm, ' ')
|
|
284
|
-
.replace(/[ \t]{2,}/gm, ' ')
|
|
285
|
-
.trim()
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
289
|
-
|
|
290
|
-
export const runCommandSync = (
|
|
291
|
-
command: string,
|
|
292
|
-
options?: SyncOptions,
|
|
293
|
-
): ExecaSyncReturnValue => {
|
|
294
|
-
return commandSync(prepareCommand(command), options)
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
298
|
-
|
|
299
|
-
export const logDataTable = (
|
|
300
|
-
vars: {[key: string]: string | undefined},
|
|
301
|
-
title?: string,
|
|
302
|
-
): void => {
|
|
303
|
-
logTable(columnify(vars, {showHeaders: false}), title)
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
307
|
-
|
|
308
|
-
export const logTable = (text: string, title?: string): void => {
|
|
309
|
-
let out = ''
|
|
310
|
-
const boxTitle = title ? chalk.bold(`${title}`) : undefined
|
|
311
|
-
|
|
312
|
-
if (boxTitle) {
|
|
313
|
-
out += `${boxTitle}\n`
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
out += text
|
|
317
|
-
|
|
318
|
-
console.log(
|
|
319
|
-
boxen(out, {
|
|
320
|
-
margin: 0,
|
|
321
|
-
padding: {
|
|
322
|
-
top: 0,
|
|
323
|
-
right: 1,
|
|
324
|
-
bottom: 0,
|
|
325
|
-
left: 1,
|
|
326
|
-
},
|
|
327
|
-
borderColor: 'green',
|
|
328
|
-
}),
|
|
329
|
-
)
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
333
|
-
|
|
334
|
-
export type NotifyArgs = {
|
|
335
|
-
title: string
|
|
336
|
-
message: string
|
|
337
|
-
target?: string
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export const notify = (args: NotifyArgs): void => {
|
|
341
|
-
const {title, message, target} = args
|
|
342
|
-
|
|
343
|
-
notifier.notify({
|
|
344
|
-
title,
|
|
345
|
-
message,
|
|
346
|
-
contentImage: 'https://assets.raisenow.io/favicon.png',
|
|
347
|
-
sound: 'Funk',
|
|
348
|
-
timeout: 30,
|
|
349
|
-
})
|
|
350
|
-
|
|
351
|
-
if (target) {
|
|
352
|
-
notifier.on('click', () => {
|
|
353
|
-
open(target)
|
|
354
|
-
})
|
|
355
|
-
}
|
|
356
|
-
}
|
package/src/lib/polyfills.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import 'core-js/stable'
|
|
2
|
-
// import 'core-js/features/promise'
|
|
3
|
-
// import 'core-js/features/symbol'
|
|
4
|
-
// import 'core-js/features/object/assign'
|
|
5
|
-
// import 'core-js/features/string/match-all'
|
|
6
|
-
import 'element-closest/browser.js'
|
|
7
|
-
import 'unfetch/polyfill'
|
|
8
|
-
import 'current-script-polyfill'
|