@raisenow/tamaro-cli 1.0.6 → 1.0.10
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 +1 -0
- package/.eslintrc.js +0 -5
- package/.gitignore +2 -1
- package/.nvmrc +1 -1
- package/.prettierignore +1 -0
- package/dist/cli.js +474 -126
- package/dist/webpack.config.js +96 -57
- package/package.json +53 -55
- package/readme.html +55 -0
- package/readme.md +227 -0
- package/src/cli.ts +100 -17
- package/src/commands/build.ts +97 -0
- package/src/commands/deploy-email-config.ts +107 -0
- package/src/commands/deploy.ts +151 -0
- package/src/commands/dev.ts +61 -0
- package/src/commands/list-deployed.ts +102 -0
- package/src/commands/serve.ts +29 -0
- package/src/lib/aws.ts +119 -0
- package/src/lib/helpers.ts +104 -27
- package/src/webpack.config.ts +34 -5
- package/src/assets/rnw-logo.png +0 -0
- package/src/commands/build/index.ts +0 -43
- package/src/commands/deploy/index.ts +0 -25
- package/src/commands/dev/index.ts +0 -32
- package/src/commands/serve/index.ts +0 -12
package/src/lib/helpers.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {basename, resolve} from 'path'
|
|
1
|
+
import {basename, relative, resolve} from 'path'
|
|
2
2
|
import {existsSync, realpathSync} from 'fs'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
|
-
import
|
|
4
|
+
import notifier from 'node-notifier'
|
|
5
5
|
import {getIfUtils, IfUtils, IfUtilsFn} from 'webpack-config-utils'
|
|
6
6
|
import columnify from 'columnify'
|
|
7
7
|
import boxen from 'boxen'
|
|
8
|
-
import dotenvExpand from 'dotenv-expand'
|
|
9
|
-
import
|
|
8
|
+
import {expand as dotenvExpand} from 'dotenv-expand'
|
|
9
|
+
import {config as dotenvConfig} from 'dotenv'
|
|
10
|
+
import open from 'open'
|
|
10
11
|
import stripIndent from 'strip-indent'
|
|
12
|
+
import {commandSync, ExecaSyncReturnValue, SyncOptions} from 'execa'
|
|
11
13
|
|
|
12
14
|
///////////////////////////////////////////////////////////////////////////////
|
|
13
15
|
|
|
@@ -21,11 +23,8 @@ export type EnvVars = {
|
|
|
21
23
|
// Supported packages
|
|
22
24
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
25
|
|
|
24
|
-
const TAMARO_CORE_PACKAGE_NAMES = ['@raisenow/tamaro-core'
|
|
25
|
-
const TAMARO_CONFIGURATIONS_PACKAGE_NAMES = [
|
|
26
|
-
'@raisenow/tamaro-configurations',
|
|
27
|
-
'demo-tamaro-configurations',
|
|
28
|
-
]
|
|
26
|
+
const TAMARO_CORE_PACKAGE_NAMES = ['@raisenow/tamaro-core']
|
|
27
|
+
const TAMARO_CONFIGURATIONS_PACKAGE_NAMES = ['@raisenow/tamaro-configurations']
|
|
29
28
|
|
|
30
29
|
///////////////////////////////////////////////////////////////////////////////
|
|
31
30
|
|
|
@@ -51,9 +50,8 @@ export const getIfCoreFns = (): IfUtils => {
|
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
stripIndent(`\
|
|
53
|
+
logError(
|
|
54
|
+
stripIndent(`\
|
|
57
55
|
You must run "npx @raisenow/tamaro-cli" commands from:
|
|
58
56
|
1. Root of "${chalk.bold(TAMARO_CORE_PACKAGE_NAMES[0])}" package folder.
|
|
59
57
|
2. Root of particular customer configuration folder of "${chalk.bold(
|
|
@@ -61,9 +59,8 @@ export const getIfCoreFns = (): IfUtils => {
|
|
|
61
59
|
)}" package.
|
|
62
60
|
You are currently in "${chalk.bold(realpathSync(process.cwd()))}".
|
|
63
61
|
`),
|
|
64
|
-
),
|
|
65
62
|
)
|
|
66
|
-
process.exit(
|
|
63
|
+
process.exit(1)
|
|
67
64
|
}
|
|
68
65
|
|
|
69
66
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -131,6 +128,24 @@ export const getPaths = (ifCore: IfUtilsFn) => {
|
|
|
131
128
|
)
|
|
132
129
|
}
|
|
133
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
|
+
|
|
134
149
|
///////////////////////////////////////////////////////////////////////////////
|
|
135
150
|
// Env vars
|
|
136
151
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -141,7 +156,7 @@ export const getEnvVars = (
|
|
|
141
156
|
ifCore: IfUtilsFn,
|
|
142
157
|
ifLocalCore: IfUtilsFn,
|
|
143
158
|
) => {
|
|
144
|
-
dotenvExpand(
|
|
159
|
+
dotenvExpand(dotenvConfig({path: filePath}))
|
|
145
160
|
|
|
146
161
|
process.env.NODE_ENV ??= ifMin('production', 'development')
|
|
147
162
|
process.env.BABEL_ENV ??= ifMin('production', 'development')
|
|
@@ -170,7 +185,7 @@ export const getEnvVars = (
|
|
|
170
185
|
process.env.WIDGET_UUID = getWidgetUuid()
|
|
171
186
|
|
|
172
187
|
if (ifLocalCore()) {
|
|
173
|
-
process.env.CORE_URL = `http://0.0.0.0:
|
|
188
|
+
process.env.CORE_URL = `http://0.0.0.0:1234/index.js`
|
|
174
189
|
} else {
|
|
175
190
|
let version = process.env.CORE_VERSION
|
|
176
191
|
version = version ? `@${version}` : ''
|
|
@@ -231,23 +246,77 @@ export const getEnvVars = (
|
|
|
231
246
|
// Other
|
|
232
247
|
///////////////////////////////////////////////////////////////////////////////
|
|
233
248
|
|
|
234
|
-
export const
|
|
235
|
-
|
|
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)
|
|
236
295
|
}
|
|
237
296
|
|
|
238
297
|
///////////////////////////////////////////////////////////////////////////////
|
|
239
298
|
|
|
240
|
-
// Log data into console as a table
|
|
241
299
|
export const logDataTable = (
|
|
242
300
|
vars: {[key: string]: string | undefined},
|
|
243
|
-
title
|
|
301
|
+
title?: string,
|
|
244
302
|
): void => {
|
|
245
|
-
|
|
246
|
-
|
|
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
|
|
247
317
|
|
|
248
|
-
// eslint-disable-next-line no-console
|
|
249
318
|
console.log(
|
|
250
|
-
boxen(
|
|
319
|
+
boxen(out, {
|
|
251
320
|
margin: 0,
|
|
252
321
|
padding: {
|
|
253
322
|
top: 0,
|
|
@@ -265,15 +334,23 @@ export const logDataTable = (
|
|
|
265
334
|
export type NotifyArgs = {
|
|
266
335
|
title: string
|
|
267
336
|
message: string
|
|
337
|
+
target?: string
|
|
268
338
|
}
|
|
269
339
|
|
|
270
340
|
export const notify = (args: NotifyArgs): void => {
|
|
271
|
-
const {title, message} = args
|
|
341
|
+
const {title, message, target} = args
|
|
272
342
|
|
|
273
|
-
|
|
343
|
+
notifier.notify({
|
|
274
344
|
title,
|
|
275
345
|
message,
|
|
276
|
-
contentImage:
|
|
346
|
+
contentImage: 'https://assets.raisenow.io/favicon.png',
|
|
277
347
|
sound: 'Funk',
|
|
348
|
+
timeout: 30,
|
|
278
349
|
})
|
|
350
|
+
|
|
351
|
+
if (target) {
|
|
352
|
+
notifier.on('click', () => {
|
|
353
|
+
open(target)
|
|
354
|
+
})
|
|
355
|
+
}
|
|
279
356
|
}
|
package/src/webpack.config.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {basename, dirname} from 'path'
|
|
2
|
+
import {existsSync} from 'fs'
|
|
2
3
|
import glob from 'glob'
|
|
3
4
|
import {getIfUtils, removeEmpty} from 'webpack-config-utils'
|
|
4
5
|
import webpack, {
|
|
@@ -8,6 +9,7 @@ import webpack, {
|
|
|
8
9
|
ProgressPlugin,
|
|
9
10
|
RuleSetUseItem,
|
|
10
11
|
} from 'webpack'
|
|
12
|
+
import {getPortPromise} from 'portfinder'
|
|
11
13
|
import {TsconfigPathsPlugin} from 'tsconfig-paths-webpack-plugin'
|
|
12
14
|
import {CleanWebpackPlugin} from 'clean-webpack-plugin'
|
|
13
15
|
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
@@ -26,8 +28,10 @@ import {
|
|
|
26
28
|
getEnvVars,
|
|
27
29
|
getIfCoreFns,
|
|
28
30
|
getPaths,
|
|
31
|
+
getRelativePaths,
|
|
29
32
|
logDataTable,
|
|
30
33
|
moduleFileExtensions,
|
|
34
|
+
resolveApp,
|
|
31
35
|
resolveOwn,
|
|
32
36
|
} from 'lib/helpers'
|
|
33
37
|
|
|
@@ -47,8 +51,11 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
|
|
|
47
51
|
const appHtmlFiles = glob.sync(paths.appHtml)
|
|
48
52
|
const envVars = getEnvVars(paths.appEnv, ifMin, ifCore, ifLocalCore)
|
|
49
53
|
const {ifHmr} = getIfUtils({hmr: process.env.HMR_ENABLED === 'true'}, ['hmr'])
|
|
54
|
+
const port = await getPortPromise({port: 1234})
|
|
55
|
+
const useTailwind =
|
|
56
|
+
ifCore() && paths.appTailwindConfig && existsSync(paths.appTailwindConfig)
|
|
50
57
|
|
|
51
|
-
logDataTable(paths, 'Paths')
|
|
58
|
+
logDataTable(getRelativePaths(paths), 'Paths')
|
|
52
59
|
logDataTable(envVars.raw, 'Environment variables')
|
|
53
60
|
|
|
54
61
|
const getCssLoaders = (cssOptions: any = {}): RuleSetUseItem[] => {
|
|
@@ -75,7 +82,15 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
|
|
|
75
82
|
options: {
|
|
76
83
|
postcssOptions: {
|
|
77
84
|
plugins: removeEmpty([
|
|
78
|
-
|
|
85
|
+
useTailwind
|
|
86
|
+
? [
|
|
87
|
+
// eslint-disable-next-line node/no-missing-require
|
|
88
|
+
require.resolve('tailwindcss', {
|
|
89
|
+
paths: [paths.appNodeModules],
|
|
90
|
+
}),
|
|
91
|
+
paths.appTailwindConfig,
|
|
92
|
+
]
|
|
93
|
+
: undefined,
|
|
79
94
|
require.resolve('postcss-custom-properties'),
|
|
80
95
|
require.resolve('autoprefixer'),
|
|
81
96
|
]),
|
|
@@ -143,9 +158,18 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
|
|
|
143
158
|
{
|
|
144
159
|
oneOf: [
|
|
145
160
|
// App Javascript and Typescript (Babel)
|
|
161
|
+
// and some dependencies distributed in a non-es5 formats
|
|
146
162
|
{
|
|
147
163
|
test: /\.(js|ts)x?$/,
|
|
148
|
-
|
|
164
|
+
include: ifCore(
|
|
165
|
+
[
|
|
166
|
+
resolveApp('src'),
|
|
167
|
+
resolveApp('node_modules/micromark'),
|
|
168
|
+
resolveApp('node_modules/decode-named-character-reference'),
|
|
169
|
+
],
|
|
170
|
+
[resolveApp('.'), resolveApp('../../src')],
|
|
171
|
+
),
|
|
172
|
+
|
|
149
173
|
loader: require.resolve('babel-loader'),
|
|
150
174
|
options: {
|
|
151
175
|
babelrc: false,
|
|
@@ -297,6 +321,7 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
|
|
|
297
321
|
devtool: ifMin(false, 'cheap-module-source-map'),
|
|
298
322
|
|
|
299
323
|
devServer: {
|
|
324
|
+
port,
|
|
300
325
|
static: false,
|
|
301
326
|
historyApiFallback: {
|
|
302
327
|
disableDotRule: true,
|
|
@@ -401,8 +426,12 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
|
|
|
401
426
|
? new CopyPlugin({
|
|
402
427
|
patterns: [
|
|
403
428
|
{
|
|
404
|
-
from: '
|
|
405
|
-
to: '
|
|
429
|
+
from: 'readme.md',
|
|
430
|
+
to: 'readme.md',
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
from: 'readme.html',
|
|
434
|
+
to: 'readme.html',
|
|
406
435
|
},
|
|
407
436
|
],
|
|
408
437
|
})
|
package/src/assets/rnw-logo.png
DELETED
|
Binary file
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {commandSync} from 'execa'
|
|
2
|
-
import {logCommand, notify, resolveOwn} from 'lib/helpers'
|
|
3
|
-
import resolveBin from 'resolve-bin'
|
|
4
|
-
|
|
5
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
6
|
-
|
|
7
|
-
export type BuildOptions = {
|
|
8
|
-
localCore?: boolean
|
|
9
|
-
analyze?: boolean
|
|
10
|
-
deploy?: boolean
|
|
11
|
-
latest?: boolean
|
|
12
|
-
tag?: string
|
|
13
|
-
serve?: boolean
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
17
|
-
|
|
18
|
-
const prepareBuildFlags = (options: BuildOptions): string => {
|
|
19
|
-
const {localCore, analyze} = options
|
|
20
|
-
let flags: string[] = []
|
|
21
|
-
|
|
22
|
-
flags = localCore ? [...flags, '--env localCore'] : flags
|
|
23
|
-
flags = analyze ? [...flags, '--env analyze'] : flags
|
|
24
|
-
|
|
25
|
-
return flags.join(' ')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
29
|
-
|
|
30
|
-
export const build = async (options: BuildOptions): Promise<void> => {
|
|
31
|
-
const flags = prepareBuildFlags(options)
|
|
32
|
-
|
|
33
|
-
const wpBin = resolveBin.sync('webpack')
|
|
34
|
-
const wpConfig = resolveOwn('dist/webpack.config.js')
|
|
35
|
-
const cmd = `${wpBin} --config ${wpConfig} --env min ${flags}`
|
|
36
|
-
logCommand(cmd)
|
|
37
|
-
commandSync(cmd, {stdio: 'inherit'})
|
|
38
|
-
|
|
39
|
-
notify({
|
|
40
|
-
title: '"build" command',
|
|
41
|
-
message: 'Process is done',
|
|
42
|
-
})
|
|
43
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {commandSync} from 'execa'
|
|
2
|
-
import {getIfCoreFns, getPaths, logCommand} from 'lib/helpers'
|
|
3
|
-
|
|
4
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
|
|
6
|
-
export type DeployOptions = {
|
|
7
|
-
latest?: boolean
|
|
8
|
-
tag?: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
12
|
-
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
-
export const deploy = async (options: DeployOptions): Promise<void> => {
|
|
15
|
-
// todo: ensure build exists
|
|
16
|
-
// todo: handle "tag" and "latest" options
|
|
17
|
-
// todo: implement
|
|
18
|
-
const {ifCore} = getIfCoreFns()
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
-
const paths = getPaths(ifCore)
|
|
21
|
-
|
|
22
|
-
const cmd = `echo Deploying to AWS is not implemented yet`
|
|
23
|
-
logCommand(cmd)
|
|
24
|
-
commandSync(cmd, {stdio: 'inherit'})
|
|
25
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {commandSync} from 'execa'
|
|
2
|
-
import {logCommand, resolveOwn} from 'lib/helpers'
|
|
3
|
-
import resolveBin from 'resolve-bin'
|
|
4
|
-
|
|
5
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
6
|
-
|
|
7
|
-
export type DevOptions = {
|
|
8
|
-
localCore?: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
12
|
-
|
|
13
|
-
const prepareDevFlags = (options: DevOptions): string => {
|
|
14
|
-
const {localCore} = options
|
|
15
|
-
let flags: string[] = []
|
|
16
|
-
|
|
17
|
-
flags = localCore ? [...flags, '--env localCore'] : flags
|
|
18
|
-
|
|
19
|
-
return flags.join(' ')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
-
|
|
24
|
-
export const dev = async (options: DevOptions): Promise<void> => {
|
|
25
|
-
const flags = prepareDevFlags(options)
|
|
26
|
-
|
|
27
|
-
const wpBin = resolveBin.sync('webpack')
|
|
28
|
-
const wpConfig = resolveOwn('dist/webpack.config.js')
|
|
29
|
-
const cmd = `${wpBin} serve --config ${wpConfig} ${flags}`
|
|
30
|
-
logCommand(cmd)
|
|
31
|
-
commandSync(cmd, {stdio: 'inherit'})
|
|
32
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {commandSync} from 'execa'
|
|
2
|
-
import {getIfCoreFns, getPaths, logCommand} from 'lib/helpers'
|
|
3
|
-
|
|
4
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
|
|
6
|
-
export const serve = async (): Promise<void> => {
|
|
7
|
-
const {ifCore} = getIfCoreFns()
|
|
8
|
-
const paths = getPaths(ifCore)
|
|
9
|
-
const cmd = `npx -y http-server ${paths.appDist} --cors`
|
|
10
|
-
logCommand(cmd)
|
|
11
|
-
commandSync(cmd, {stdio: 'inherit'})
|
|
12
|
-
}
|