@raisenow/tamaro-cli 1.0.19 → 1.0.22
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/.nvmrc +1 -1
- package/README.md +22 -0
- package/dist/{chunk-6RQVBAWK.js → chunk-2HKMDCAH.js} +78 -31
- package/dist/cli.js +208 -74
- package/dist/webpack.config.js +64 -36
- package/package.json +30 -30
- package/src/cli.ts +15 -0
- package/src/commands/build.ts +12 -2
- package/src/commands/dev.ts +12 -2
- package/src/commands/serve.ts +20 -2
- package/src/lib/constants.ts +2 -0
- package/src/lib/env.ts +14 -2
- package/src/lib/https.ts +27 -0
- package/src/lib/resolve.ts +2 -0
- package/src/webpack.config.ts +12 -2
package/dist/webpack.config.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
+
HTTPS_CRT_FILE,
|
|
3
|
+
HTTPS_KEY_FILE,
|
|
2
4
|
extensions,
|
|
3
5
|
getEnvVars,
|
|
4
6
|
getIfCoreFns,
|
|
@@ -8,11 +10,11 @@ import {
|
|
|
8
10
|
logTitle,
|
|
9
11
|
moduleFileExtensions,
|
|
10
12
|
resolveApp
|
|
11
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-2HKMDCAH.js";
|
|
12
14
|
|
|
13
15
|
// src/webpack.config.ts
|
|
14
16
|
import { createRequire } from "module";
|
|
15
|
-
import { basename, dirname } from "path";
|
|
17
|
+
import { basename, dirname, resolve } from "path";
|
|
16
18
|
import { existsSync } from "fs";
|
|
17
19
|
import glob from "glob";
|
|
18
20
|
import { getIfUtils, removeEmpty } from "webpack-config-utils";
|
|
@@ -48,7 +50,10 @@ var InterpolateHtmlPlugin = class {
|
|
|
48
50
|
});
|
|
49
51
|
hooks.afterTemplateExecution.tap(PLUGIN_NAME, (data) => {
|
|
50
52
|
Object.entries(this.replacements).forEach(([key, value]) => {
|
|
51
|
-
data.html = data.html.replace(
|
|
53
|
+
data.html = data.html.replace(
|
|
54
|
+
new RegExp(`%${escapeStringRegexp(key)}%`, "g"),
|
|
55
|
+
value || ""
|
|
56
|
+
);
|
|
52
57
|
});
|
|
53
58
|
return data;
|
|
54
59
|
});
|
|
@@ -62,12 +67,13 @@ var imageInlineSizeLimit = 0;
|
|
|
62
67
|
var getWebpackConfig = async (env) => {
|
|
63
68
|
const { ifMin, ifNotMin } = getIfUtils(env, ["min"]);
|
|
64
69
|
const { ifAnalyze } = getIfUtils(env, ["analyze"]);
|
|
70
|
+
const { ifHttps } = getIfUtils(env, ["https"]);
|
|
65
71
|
const { ifLocalCore } = getIfUtils(env, ["localCore"]);
|
|
66
72
|
const { ifCore } = getIfCoreFns();
|
|
67
73
|
const paths = getPaths(ifCore);
|
|
68
74
|
const appHtmlFiles = glob.sync(paths.appHtml);
|
|
69
75
|
const appEnvFiles = glob.sync(paths.appEnv);
|
|
70
|
-
const envVars = getEnvVars(appEnvFiles, ifMin, ifCore, ifLocalCore);
|
|
76
|
+
const envVars = getEnvVars(appEnvFiles, ifMin, ifCore, ifLocalCore, ifHttps);
|
|
71
77
|
const { ifHmr } = getIfUtils({ hmr: process.env.HMR_ENABLED === "true" }, ["hmr"]);
|
|
72
78
|
const useTailwind = ifCore() && paths.appTailwindConfig && existsSync(paths.appTailwindConfig);
|
|
73
79
|
logTitle("Paths:");
|
|
@@ -144,16 +150,19 @@ var getWebpackConfig = async (env) => {
|
|
|
144
150
|
crossOriginLoading: "anonymous",
|
|
145
151
|
uniqueName: process.env.WEBPACK_UNIQUE_NAME
|
|
146
152
|
},
|
|
147
|
-
stats: ifAnalyze(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
stats: ifAnalyze(
|
|
154
|
+
{
|
|
155
|
+
all: void 0
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
modules: false,
|
|
159
|
+
children: false,
|
|
160
|
+
chunks: false,
|
|
161
|
+
env: true,
|
|
162
|
+
entrypoints: true,
|
|
163
|
+
errorDetails: true
|
|
164
|
+
}
|
|
165
|
+
),
|
|
157
166
|
module: {
|
|
158
167
|
rules: removeEmpty([
|
|
159
168
|
ifNotMin({
|
|
@@ -166,11 +175,14 @@ var getWebpackConfig = async (env) => {
|
|
|
166
175
|
oneOf: [
|
|
167
176
|
{
|
|
168
177
|
test: /\.(js|ts)x?$/,
|
|
169
|
-
include: ifCore(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
178
|
+
include: ifCore(
|
|
179
|
+
[
|
|
180
|
+
resolveApp("src"),
|
|
181
|
+
resolveApp("node_modules/micromark"),
|
|
182
|
+
resolveApp("node_modules/decode-named-character-reference")
|
|
183
|
+
],
|
|
184
|
+
[resolveApp("."), resolveApp("../../src")]
|
|
185
|
+
),
|
|
174
186
|
loader: require2.resolve("babel-loader"),
|
|
175
187
|
options: {
|
|
176
188
|
babelrc: false,
|
|
@@ -195,7 +207,9 @@ var getWebpackConfig = async (env) => {
|
|
|
195
207
|
version: 3,
|
|
196
208
|
proposals: true
|
|
197
209
|
},
|
|
198
|
-
absoluteRuntime: dirname(
|
|
210
|
+
absoluteRuntime: dirname(
|
|
211
|
+
require2.resolve("@babel/runtime-corejs3/package.json")
|
|
212
|
+
)
|
|
199
213
|
}
|
|
200
214
|
],
|
|
201
215
|
[
|
|
@@ -271,12 +285,20 @@ var getWebpackConfig = async (env) => {
|
|
|
271
285
|
headers: {
|
|
272
286
|
"Access-Control-Allow-Origin": "*"
|
|
273
287
|
},
|
|
288
|
+
allowedHosts: "all",
|
|
274
289
|
client: {
|
|
275
290
|
overlay: {
|
|
276
291
|
warnings: false,
|
|
277
292
|
errors: true
|
|
278
293
|
}
|
|
279
|
-
}
|
|
294
|
+
},
|
|
295
|
+
server: ifHttps({
|
|
296
|
+
type: "https",
|
|
297
|
+
options: {
|
|
298
|
+
cert: resolve(paths.root, HTTPS_CRT_FILE),
|
|
299
|
+
key: resolve(paths.root, HTTPS_KEY_FILE)
|
|
300
|
+
}
|
|
301
|
+
})
|
|
280
302
|
},
|
|
281
303
|
optimization: {
|
|
282
304
|
removeEmptyChunks: true,
|
|
@@ -290,13 +312,17 @@ var getWebpackConfig = async (env) => {
|
|
|
290
312
|
cwd: paths.app,
|
|
291
313
|
resolvePluginsRelativeTo: paths.app
|
|
292
314
|
}),
|
|
293
|
-
ifMin(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
315
|
+
ifMin(
|
|
316
|
+
new CleanWebpackPlugin({})
|
|
317
|
+
),
|
|
318
|
+
...appHtmlFiles.map(
|
|
319
|
+
(file) => new HtmlWebpackPlugin2({
|
|
320
|
+
template: file,
|
|
321
|
+
filename: basename(file),
|
|
322
|
+
inject: false,
|
|
323
|
+
minify: false
|
|
324
|
+
})
|
|
325
|
+
),
|
|
300
326
|
new InterpolateHtmlPlugin(envVars.raw),
|
|
301
327
|
new webpack.DefinePlugin(envVars.stringified),
|
|
302
328
|
new ForkTsCheckerWebpackPlugin({
|
|
@@ -315,14 +341,16 @@ var getWebpackConfig = async (env) => {
|
|
|
315
341
|
}
|
|
316
342
|
}),
|
|
317
343
|
ifHmr(new ReactRefreshWebpackPlugin()),
|
|
318
|
-
ifMin(
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
344
|
+
ifMin(
|
|
345
|
+
new MiniCssExtractPlugin({
|
|
346
|
+
filename: "[name]-[contenthash:16].css",
|
|
347
|
+
chunkFilename: "[name]-[contenthash:16].css",
|
|
348
|
+
ignoreOrder: true,
|
|
349
|
+
attributes: {
|
|
350
|
+
"data-widget": process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET
|
|
351
|
+
}
|
|
352
|
+
})
|
|
353
|
+
),
|
|
326
354
|
new webpack.IgnorePlugin({
|
|
327
355
|
resourceRegExp: /^\.\/locale$/,
|
|
328
356
|
contextRegExp: /moment$/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raisenow/tamaro-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "RaiseNow",
|
|
6
6
|
"email": "development@raisenow.com"
|
|
@@ -20,75 +20,75 @@
|
|
|
20
20
|
"npm": ">=8"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@babel/cli": "^7.18.
|
|
24
|
-
"@babel/core": "^7.
|
|
25
|
-
"@babel/plugin-proposal-decorators": "^7.
|
|
23
|
+
"@babel/cli": "^7.18.10",
|
|
24
|
+
"@babel/core": "^7.19.0",
|
|
25
|
+
"@babel/plugin-proposal-decorators": "^7.19.0",
|
|
26
26
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
27
|
-
"@babel/plugin-transform-runtime": "^7.18.
|
|
28
|
-
"@babel/preset-env": "^7.
|
|
27
|
+
"@babel/plugin-transform-runtime": "^7.18.10",
|
|
28
|
+
"@babel/preset-env": "^7.19.0",
|
|
29
29
|
"@babel/preset-react": "^7.18.6",
|
|
30
30
|
"@babel/preset-typescript": "^7.18.6",
|
|
31
|
-
"@babel/runtime-corejs3": "^7.
|
|
31
|
+
"@babel/runtime-corejs3": "^7.19.0",
|
|
32
32
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
|
|
33
|
-
"@statoscope/webpack-plugin": "^5.
|
|
33
|
+
"@statoscope/webpack-plugin": "^5.24.0",
|
|
34
34
|
"@types/columnify": "^1.5.1",
|
|
35
|
-
"@types/lodash": "^4.14.
|
|
36
|
-
"@types/node": "^18.
|
|
35
|
+
"@types/lodash": "^4.14.184",
|
|
36
|
+
"@types/node": "^18.7.15",
|
|
37
37
|
"@types/node-notifier": "^8.0.2",
|
|
38
38
|
"@types/resolve-bin": "^0.4.1",
|
|
39
39
|
"@types/webpack-config-utils": "^2.3.1",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
41
|
-
"@typescript-eslint/parser": "^5.
|
|
42
|
-
"autoprefixer": "^10.4.
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
41
|
+
"@typescript-eslint/parser": "^5.36.2",
|
|
42
|
+
"autoprefixer": "^10.4.8",
|
|
43
43
|
"babel-loader": "^8.2.5",
|
|
44
44
|
"babel-plugin-istanbul": "^6.1.1",
|
|
45
45
|
"babel-plugin-lodash": "^3.3.4",
|
|
46
46
|
"chalk": "^5.0.1",
|
|
47
47
|
"clean-webpack-plugin": "^4.0.0",
|
|
48
48
|
"columnify": "^1.6.0",
|
|
49
|
-
"commander": "^9.
|
|
49
|
+
"commander": "^9.4.0",
|
|
50
50
|
"copy-webpack-plugin": "^11.0.0",
|
|
51
|
-
"core-js": "^3.
|
|
51
|
+
"core-js": "^3.25.0",
|
|
52
52
|
"css-loader": "^6.7.1",
|
|
53
53
|
"css-minimizer-webpack-plugin": "^4.0.0",
|
|
54
|
-
"dotenv": "^16.0.
|
|
55
|
-
"dotenv-expand": "^
|
|
54
|
+
"dotenv": "^16.0.2",
|
|
55
|
+
"dotenv-expand": "^9.0.0",
|
|
56
56
|
"escape-string-regexp": "^5.0.0",
|
|
57
|
-
"eslint": "^8.
|
|
57
|
+
"eslint": "^8.23.0",
|
|
58
58
|
"eslint-config-prettier": "^8.5.0",
|
|
59
59
|
"eslint-plugin-node": "^11.1.0",
|
|
60
|
-
"eslint-plugin-promise": "^6.0.
|
|
60
|
+
"eslint-plugin-promise": "^6.0.1",
|
|
61
61
|
"eslint-webpack-plugin": "^3.2.0",
|
|
62
62
|
"execa": "^6.1.0",
|
|
63
63
|
"file-loader": "^6.2.0",
|
|
64
|
-
"fork-ts-checker-webpack-plugin": "^7.2.
|
|
64
|
+
"fork-ts-checker-webpack-plugin": "^7.2.13",
|
|
65
65
|
"glob": "^8.0.3",
|
|
66
|
-
"html-loader": "^
|
|
66
|
+
"html-loader": "^4.1.0",
|
|
67
67
|
"html-webpack-plugin": "^5.5.0",
|
|
68
68
|
"json-loader": "^0.5.7",
|
|
69
69
|
"lodash": "^4.17.21",
|
|
70
70
|
"mini-css-extract-plugin": "^2.6.1",
|
|
71
71
|
"node-notifier": "^10.0.1",
|
|
72
|
-
"portfinder": "^1.0.
|
|
73
|
-
"postcss": "^8.4.
|
|
72
|
+
"portfinder": "^1.0.32",
|
|
73
|
+
"postcss": "^8.4.16",
|
|
74
74
|
"postcss-custom-properties": "^12.1.7",
|
|
75
|
-
"postcss-loader": "^7.0.
|
|
75
|
+
"postcss-loader": "^7.0.1",
|
|
76
76
|
"prettier": "^2.7.1",
|
|
77
77
|
"react-refresh": "^0.14.0",
|
|
78
78
|
"resolve-url-loader": "^5.0.0",
|
|
79
|
-
"sass": "^1.
|
|
79
|
+
"sass": "^1.54.8",
|
|
80
80
|
"sass-loader": "^13.0.2",
|
|
81
81
|
"source-map-loader": "^4.0.0",
|
|
82
82
|
"strip-indent": "^4.0.0",
|
|
83
83
|
"style-loader": "^3.3.1",
|
|
84
|
-
"tsconfig-paths-webpack-plugin": "^
|
|
85
|
-
"tsup": "^6.
|
|
86
|
-
"typescript": "^4.
|
|
84
|
+
"tsconfig-paths-webpack-plugin": "^4.0.0",
|
|
85
|
+
"tsup": "^6.2.3",
|
|
86
|
+
"typescript": "^4.8.2",
|
|
87
87
|
"url-loader": "^4.1.1",
|
|
88
|
-
"webpack": "^5.
|
|
88
|
+
"webpack": "^5.74.0",
|
|
89
89
|
"webpack-cli": "^4.10.0",
|
|
90
90
|
"webpack-config-utils": "^2.3.1",
|
|
91
|
-
"webpack-dev-server": "^4.
|
|
91
|
+
"webpack-dev-server": "^4.10.1",
|
|
92
92
|
"yaml-loader": "^0.8.0"
|
|
93
93
|
}
|
|
94
94
|
}
|
package/src/cli.ts
CHANGED
|
@@ -49,6 +49,11 @@ cli
|
|
|
49
49
|
'Load Tamaro Core from localhost:1234 instead of the CDN',
|
|
50
50
|
false,
|
|
51
51
|
)
|
|
52
|
+
.option(
|
|
53
|
+
'--https',
|
|
54
|
+
'Let local web server serve Tamaro with SSL encryption',
|
|
55
|
+
false,
|
|
56
|
+
)
|
|
52
57
|
.option('--port <port>', 'Web server port', `${DEFAULT_PORT}`)
|
|
53
58
|
.option('--env <env>', 'Environment (dev, stage, prod)')
|
|
54
59
|
.action(async (options: DevOptions) => {
|
|
@@ -67,6 +72,11 @@ cli
|
|
|
67
72
|
)
|
|
68
73
|
.option('--analyze', 'Generate bundle statistics to "reports" folder', false)
|
|
69
74
|
.option('--serve', 'Run the generated bundle with a local web server', false)
|
|
75
|
+
.option(
|
|
76
|
+
'--https',
|
|
77
|
+
'Let local web server serve Tamaro with SSL encryption',
|
|
78
|
+
false,
|
|
79
|
+
)
|
|
70
80
|
.option('--port <port>', 'Web server port', `${DEFAULT_PORT}`)
|
|
71
81
|
.option('--env <env>', 'Environment (dev, stage, prod)')
|
|
72
82
|
.option(
|
|
@@ -100,6 +110,11 @@ cli
|
|
|
100
110
|
.command('serve')
|
|
101
111
|
.description('Run a local web server for pre-built bundle')
|
|
102
112
|
.option('--port <port>', 'Web server port', `${DEFAULT_PORT}`)
|
|
113
|
+
.option(
|
|
114
|
+
'--https',
|
|
115
|
+
'Let local web server serve Tamaro with SSL encryption',
|
|
116
|
+
false,
|
|
117
|
+
)
|
|
103
118
|
.action(async (options: ServeOptions) => {
|
|
104
119
|
await serve(options)
|
|
105
120
|
})
|
package/src/commands/build.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
resolveOwn,
|
|
9
9
|
} from 'lib/resolve'
|
|
10
10
|
import {assertEnvValid} from 'lib/env'
|
|
11
|
+
import {assertCrtExists} from 'lib/https'
|
|
11
12
|
import {logCommand, logTitle} from 'lib/logging'
|
|
12
13
|
import {notify} from 'lib/notifier'
|
|
13
14
|
import {halt, runCommandSync} from 'lib/command'
|
|
@@ -18,6 +19,7 @@ import {DeployOptions} from 'commands/deploy'
|
|
|
18
19
|
export type BuildOptions = {
|
|
19
20
|
localCore: boolean
|
|
20
21
|
analyze: boolean
|
|
22
|
+
https: boolean
|
|
21
23
|
serve: boolean
|
|
22
24
|
deploy: boolean
|
|
23
25
|
env: string
|
|
@@ -70,7 +72,7 @@ export const build = async (
|
|
|
70
72
|
///////////////////////////////////////////////////////////////////////////////
|
|
71
73
|
|
|
72
74
|
const assertOptionsValid = (options: BuildOptions & DeployOptions) => {
|
|
73
|
-
const {localCore, deploy, profile, env} = options
|
|
75
|
+
const {localCore, https, deploy, profile, env} = options
|
|
74
76
|
const {ifCore} = getIfCoreFns()
|
|
75
77
|
|
|
76
78
|
if (ifCore() && localCore) {
|
|
@@ -81,6 +83,10 @@ const assertOptionsValid = (options: BuildOptions & DeployOptions) => {
|
|
|
81
83
|
halt('Flags “--local-core” and “--deploy” must not be used together.')
|
|
82
84
|
}
|
|
83
85
|
|
|
86
|
+
if (https) {
|
|
87
|
+
assertCrtExists()
|
|
88
|
+
}
|
|
89
|
+
|
|
84
90
|
assertProfileValid(profile)
|
|
85
91
|
assertEnvValid(env)
|
|
86
92
|
}
|
|
@@ -88,7 +94,7 @@ const assertOptionsValid = (options: BuildOptions & DeployOptions) => {
|
|
|
88
94
|
///////////////////////////////////////////////////////////////////////////////
|
|
89
95
|
|
|
90
96
|
const prepareFlags = (flags: string[], options: BuildOptions): string[] => {
|
|
91
|
-
const {localCore, analyze} = options
|
|
97
|
+
const {localCore, analyze, https} = options
|
|
92
98
|
|
|
93
99
|
if (localCore) {
|
|
94
100
|
flags.push('--env localCore')
|
|
@@ -98,5 +104,9 @@ const prepareFlags = (flags: string[], options: BuildOptions): string[] => {
|
|
|
98
104
|
flags.push('--env analyze')
|
|
99
105
|
}
|
|
100
106
|
|
|
107
|
+
if (https) {
|
|
108
|
+
flags.push('--env https')
|
|
109
|
+
}
|
|
110
|
+
|
|
101
111
|
return flags
|
|
102
112
|
}
|
package/src/commands/dev.ts
CHANGED
|
@@ -3,11 +3,13 @@ import {getIfCoreFns, resolveBin, resolveOwn} from 'lib/resolve'
|
|
|
3
3
|
import {logCommand, logTitle} from 'lib/logging'
|
|
4
4
|
import {halt, runCommandSync} from 'lib/command'
|
|
5
5
|
import {assertEnvValid} from 'lib/env'
|
|
6
|
+
import {assertCrtExists} from 'lib/https'
|
|
6
7
|
|
|
7
8
|
///////////////////////////////////////////////////////////////////////////////
|
|
8
9
|
|
|
9
10
|
export type DevOptions = {
|
|
10
11
|
localCore: boolean
|
|
12
|
+
https: boolean
|
|
11
13
|
port: string
|
|
12
14
|
env: string
|
|
13
15
|
}
|
|
@@ -39,7 +41,7 @@ export const dev = async (options: DevOptions): Promise<void> => {
|
|
|
39
41
|
///////////////////////////////////////////////////////////////////////////////
|
|
40
42
|
|
|
41
43
|
const assertOptionsValid = (options: DevOptions) => {
|
|
42
|
-
const {localCore, port, env} = options
|
|
44
|
+
const {localCore, https, port, env} = options
|
|
43
45
|
const {ifCore} = getIfCoreFns()
|
|
44
46
|
|
|
45
47
|
if (ifCore() && localCore) {
|
|
@@ -50,6 +52,10 @@ const assertOptionsValid = (options: DevOptions) => {
|
|
|
50
52
|
halt('Flag “--port” should be a number.')
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
if (https) {
|
|
56
|
+
assertCrtExists()
|
|
57
|
+
}
|
|
58
|
+
|
|
53
59
|
assertEnvValid(env)
|
|
54
60
|
}
|
|
55
61
|
|
|
@@ -59,7 +65,7 @@ const prepareFlags = async (
|
|
|
59
65
|
flags: string[],
|
|
60
66
|
options: DevOptions,
|
|
61
67
|
): Promise<string[]> => {
|
|
62
|
-
const {localCore, port: defaultPort} = options
|
|
68
|
+
const {localCore, port: defaultPort, https} = options
|
|
63
69
|
const port = await getPortPromise({port: Number(defaultPort)})
|
|
64
70
|
|
|
65
71
|
if (localCore) {
|
|
@@ -68,5 +74,9 @@ const prepareFlags = async (
|
|
|
68
74
|
|
|
69
75
|
flags.push(`--port ${port}`)
|
|
70
76
|
|
|
77
|
+
if (https) {
|
|
78
|
+
flags.push('--env https')
|
|
79
|
+
}
|
|
80
|
+
|
|
71
81
|
return flags
|
|
72
82
|
}
|
package/src/commands/serve.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import {resolve} from 'path'
|
|
1
2
|
import {getPortPromise} from 'portfinder'
|
|
2
3
|
import {getIfCoreFns, getPaths} from 'lib/resolve'
|
|
3
4
|
import {logCommand, logTitle} from 'lib/logging'
|
|
4
5
|
import {halt, runCommandSync} from 'lib/command'
|
|
6
|
+
import {assertCrtExists} from 'lib/https'
|
|
7
|
+
import {HTTPS_CRT_FILE, HTTPS_KEY_FILE} from 'lib/constants'
|
|
5
8
|
|
|
6
9
|
///////////////////////////////////////////////////////////////////////////////
|
|
7
10
|
|
|
8
11
|
export type ServeOptions = {
|
|
9
12
|
port: string
|
|
13
|
+
https: boolean
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -31,11 +35,15 @@ export const serve = async (options: ServeOptions): Promise<void> => {
|
|
|
31
35
|
///////////////////////////////////////////////////////////////////////////////
|
|
32
36
|
|
|
33
37
|
const assertOptionsValid = (options: ServeOptions) => {
|
|
34
|
-
const {port} = options
|
|
38
|
+
const {port, https} = options
|
|
35
39
|
|
|
36
40
|
if (isNaN(Number(port))) {
|
|
37
41
|
halt('Flag "--port" should be a number.')
|
|
38
42
|
}
|
|
43
|
+
|
|
44
|
+
if (https) {
|
|
45
|
+
assertCrtExists()
|
|
46
|
+
}
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -44,10 +52,20 @@ const prepareFlags = async (
|
|
|
44
52
|
flags: string[],
|
|
45
53
|
options: ServeOptions,
|
|
46
54
|
): Promise<string[]> => {
|
|
47
|
-
const {port: defaultPort} = options
|
|
55
|
+
const {port: defaultPort, https} = options
|
|
48
56
|
const port = await getPortPromise({port: Number(defaultPort)})
|
|
49
57
|
|
|
50
58
|
flags.push(`-p ${port}`)
|
|
51
59
|
|
|
60
|
+
if (https) {
|
|
61
|
+
const {ifCore} = getIfCoreFns()
|
|
62
|
+
const paths = getPaths(ifCore)
|
|
63
|
+
const certFile = resolve(paths.root, HTTPS_CRT_FILE)
|
|
64
|
+
const keyFile = resolve(paths.root, HTTPS_KEY_FILE)
|
|
65
|
+
|
|
66
|
+
flags.push(`--ssl-cert ${certFile}`)
|
|
67
|
+
flags.push(`--ssl-key ${keyFile}`)
|
|
68
|
+
}
|
|
69
|
+
|
|
52
70
|
return flags
|
|
53
71
|
}
|
package/src/lib/constants.ts
CHANGED
|
@@ -5,3 +5,5 @@ export const DEFAULT_AWS_S3_EMAIL_CONFIG_BUCKET = 'rnw-email-service'
|
|
|
5
5
|
export const AWS_S3_BUCKET = 'tamaro.raisenow.com'
|
|
6
6
|
export const CORE_CONFIG_NAME = 'tamaro-core'
|
|
7
7
|
export const AWS_CLOUDFRONT_DISTRIBUTION_ID = 'EHJ1OM458YQ0I'
|
|
8
|
+
export const HTTPS_CRT_FILE = 'localhost.crt'
|
|
9
|
+
export const HTTPS_KEY_FILE = 'localhost.key'
|
package/src/lib/env.ts
CHANGED
|
@@ -25,6 +25,7 @@ export const getEnvVars = (
|
|
|
25
25
|
ifMin: IfUtilsFn,
|
|
26
26
|
ifCore: IfUtilsFn,
|
|
27
27
|
ifLocalCore: IfUtilsFn,
|
|
28
|
+
ifHttps: IfUtilsFn,
|
|
28
29
|
) => {
|
|
29
30
|
const filePath = files.find((file) => basename(file) === '.env')
|
|
30
31
|
|
|
@@ -59,7 +60,8 @@ export const getEnvVars = (
|
|
|
59
60
|
process.env.WIDGET_UUID = getWidgetUuid()
|
|
60
61
|
|
|
61
62
|
if (ifLocalCore()) {
|
|
62
|
-
|
|
63
|
+
const protocol = ifHttps() ? 'https' : 'http'
|
|
64
|
+
process.env.CORE_URL = `${protocol}://0.0.0.0:1234/index.js`
|
|
63
65
|
} else {
|
|
64
66
|
let version = process.env.CORE_VERSION
|
|
65
67
|
version = version ? `@${version}` : ''
|
|
@@ -83,11 +85,21 @@ export const getEnvVars = (
|
|
|
83
85
|
'PRODUCT_NAME',
|
|
84
86
|
'PRODUCT_VERSION',
|
|
85
87
|
|
|
88
|
+
// epik
|
|
89
|
+
'EPP_API_KEY_DEFAULT',
|
|
90
|
+
'EPP_API_URL_STAGE',
|
|
91
|
+
'EPP_API_URL_PROD',
|
|
92
|
+
'EPMS_API_URL_STAGE',
|
|
93
|
+
'EPMS_API_URL_PROD',
|
|
94
|
+
'EPP_PROXY_URL_STAGE',
|
|
95
|
+
'EPP_PROXY_URL_PROD',
|
|
96
|
+
'EPMS_PROXY_URL_STAGE',
|
|
97
|
+
'EPMS_PROXY_URL_PROD',
|
|
98
|
+
|
|
86
99
|
// config
|
|
87
100
|
'WIDGET_UUID',
|
|
88
101
|
'CORE_URL',
|
|
89
102
|
'CORE_VERSION', // must be explicitly specified in each config
|
|
90
|
-
'IS_CREDIT_CARD_IFRAME',
|
|
91
103
|
]
|
|
92
104
|
|
|
93
105
|
// Collect all vars which names start from "PUBLIC_" or present in "varNames" array
|
package/src/lib/https.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {existsSync} from 'fs'
|
|
2
|
+
import {resolve} from 'path'
|
|
3
|
+
import stripIndent from 'strip-indent'
|
|
4
|
+
import {halt} from 'lib/command'
|
|
5
|
+
import {getIfCoreFns, getPaths} from 'lib/resolve'
|
|
6
|
+
import {HTTPS_CRT_FILE, HTTPS_KEY_FILE} from 'lib/constants'
|
|
7
|
+
|
|
8
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
9
|
+
|
|
10
|
+
export const assertCrtExists = () => {
|
|
11
|
+
const {ifCore} = getIfCoreFns()
|
|
12
|
+
const paths = getPaths(ifCore)
|
|
13
|
+
const certFile = resolve(paths.root, HTTPS_CRT_FILE)
|
|
14
|
+
const keyFile = resolve(paths.root, HTTPS_KEY_FILE)
|
|
15
|
+
|
|
16
|
+
if (existsSync(certFile) && existsSync(keyFile)) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
halt(
|
|
21
|
+
stripIndent(`
|
|
22
|
+
Flag “--https” is used, but “${HTTPS_CRT_FILE}” and/or “${HTTPS_KEY_FILE}” files are not found.
|
|
23
|
+
You need to generate certificate first.
|
|
24
|
+
Check docs: https://unpkg.com/@raisenow/tamaro-cli/readme.html#/?id=use-transport-level-security-https
|
|
25
|
+
`),
|
|
26
|
+
)
|
|
27
|
+
}
|
package/src/lib/resolve.ts
CHANGED
|
@@ -67,6 +67,7 @@ export const getWidgetUuid = () => basename(resolveApp('.'))
|
|
|
67
67
|
export const getPaths = (ifCore: IfUtilsFn) => {
|
|
68
68
|
return ifCore(
|
|
69
69
|
{
|
|
70
|
+
root: resolveApp('.'),
|
|
70
71
|
app: resolveApp('.'),
|
|
71
72
|
appEntry: resolveModule(resolveApp, 'src/index'),
|
|
72
73
|
appDist: resolveApp('dist'),
|
|
@@ -77,6 +78,7 @@ export const getPaths = (ifCore: IfUtilsFn) => {
|
|
|
77
78
|
appTailwindConfig: resolveApp('tailwind.config.js'),
|
|
78
79
|
},
|
|
79
80
|
{
|
|
81
|
+
root: resolveApp('../..'),
|
|
80
82
|
app: resolveApp('.'),
|
|
81
83
|
appEntry: resolveModule(resolveApp, 'widget'),
|
|
82
84
|
appDist: resolveApp(`../../dist/${getWidgetUuid()}`),
|
package/src/webpack.config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {createRequire} from 'module'
|
|
2
|
-
import {basename, dirname} from 'path'
|
|
2
|
+
import {basename, dirname, resolve} from 'path'
|
|
3
3
|
import {existsSync} from 'fs'
|
|
4
4
|
import glob from 'glob'
|
|
5
5
|
import {getIfUtils, removeEmpty} from 'webpack-config-utils'
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
} from 'lib/resolve'
|
|
29
29
|
import {getEnvVars} from 'lib/env'
|
|
30
30
|
import {logDataTable, logTitle} from 'lib/logging'
|
|
31
|
+
import {HTTPS_CRT_FILE, HTTPS_KEY_FILE} from 'lib/constants'
|
|
31
32
|
|
|
32
33
|
///////////////////////////////////////////////////////////////////////////////
|
|
33
34
|
|
|
@@ -40,12 +41,13 @@ const imageInlineSizeLimit = 0
|
|
|
40
41
|
const getWebpackConfig = async (env: any): Promise<Configuration> => {
|
|
41
42
|
const {ifMin, ifNotMin} = getIfUtils(env, ['min'])
|
|
42
43
|
const {ifAnalyze} = getIfUtils(env, ['analyze'])
|
|
44
|
+
const {ifHttps} = getIfUtils(env, ['https'])
|
|
43
45
|
const {ifLocalCore} = getIfUtils(env, ['localCore'])
|
|
44
46
|
const {ifCore} = getIfCoreFns()
|
|
45
47
|
const paths = getPaths(ifCore)
|
|
46
48
|
const appHtmlFiles = glob.sync(paths.appHtml)
|
|
47
49
|
const appEnvFiles = glob.sync(paths.appEnv)
|
|
48
|
-
const envVars = getEnvVars(appEnvFiles, ifMin, ifCore, ifLocalCore)
|
|
50
|
+
const envVars = getEnvVars(appEnvFiles, ifMin, ifCore, ifLocalCore, ifHttps)
|
|
49
51
|
const {ifHmr} = getIfUtils({hmr: process.env.HMR_ENABLED === 'true'}, ['hmr'])
|
|
50
52
|
const useTailwind =
|
|
51
53
|
ifCore() && paths.appTailwindConfig && existsSync(paths.appTailwindConfig)
|
|
@@ -287,12 +289,20 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
|
|
|
287
289
|
headers: {
|
|
288
290
|
'Access-Control-Allow-Origin': '*',
|
|
289
291
|
},
|
|
292
|
+
allowedHosts: 'all',
|
|
290
293
|
client: {
|
|
291
294
|
overlay: {
|
|
292
295
|
warnings: false,
|
|
293
296
|
errors: true,
|
|
294
297
|
},
|
|
295
298
|
},
|
|
299
|
+
server: ifHttps({
|
|
300
|
+
type: 'https',
|
|
301
|
+
options: {
|
|
302
|
+
cert: resolve(paths.root, HTTPS_CRT_FILE),
|
|
303
|
+
key: resolve(paths.root, HTTPS_KEY_FILE),
|
|
304
|
+
},
|
|
305
|
+
}),
|
|
296
306
|
},
|
|
297
307
|
|
|
298
308
|
optimization: {
|