@raisenow/tamaro-cli 1.0.12 → 1.0.15

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.
@@ -1,7 +1,7 @@
1
1
  import {getPortPromise} from 'portfinder'
2
2
  import {getIfCoreFns, getPaths} from 'lib/resolve'
3
3
  import {logCommand, logTitle} from 'lib/logging'
4
- import {fail, runCommandSync} from 'lib/command'
4
+ import {halt, runCommandSync} from 'lib/command'
5
5
 
6
6
  ///////////////////////////////////////////////////////////////////////////////
7
7
 
@@ -34,7 +34,7 @@ const assertOptionsValid = (options: ServeOptions) => {
34
34
  const {port} = options
35
35
 
36
36
  if (isNaN(Number(port))) {
37
- fail('Flag "--port" should be a number.')
37
+ halt('Flag "--port" should be a number.')
38
38
  }
39
39
  }
40
40
 
@@ -24,7 +24,9 @@ export class InterpolateHtmlPlugin {
24
24
  const hooks = HtmlWebpackPlugin.getHooks(compilation)
25
25
 
26
26
  hooks.alterAssetTagGroups.tap(PLUGIN_NAME, (assets) => {
27
- this.replacements['ENTRY'] = assets.headTags[0].attributes['src']
27
+ const publicUrl = this.replacements['PUBLIC_URL'] ?? ''
28
+ const entry = assets.headTags[0].attributes['src']
29
+ this.replacements['ENTRY'] = `${publicUrl}${entry}`
28
30
 
29
31
  return assets
30
32
  })
package/src/lib/aws.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import {execaCommandSync} from 'execa'
2
2
  import stripIndent from 'strip-indent'
3
- import {fail} from 'lib/command'
3
+ import {halt} from 'lib/command'
4
4
 
5
5
  ///////////////////////////////////////////////////////////////////////////////
6
6
 
@@ -74,7 +74,7 @@ export const assertProfileValid = (profile: string) => {
74
74
  https://raisenow.atlassian.net/wiki/x/lIrWvg
75
75
  `)
76
76
 
77
- fail(message)
77
+ halt(message)
78
78
  }
79
79
  }
80
80
 
@@ -107,7 +107,7 @@ const login = (options: AwsOptions) => {
107
107
  execaCommandSync(`aws sso login ${flags}`, {stdio: 'inherit'})
108
108
  console.log('')
109
109
  } catch (error) {
110
- fail('Login failed.')
110
+ halt('Login failed.')
111
111
  }
112
112
  }
113
113
 
@@ -3,9 +3,9 @@ import {logError} from 'lib/logging'
3
3
 
4
4
  ///////////////////////////////////////////////////////////////////////////////
5
5
 
6
- export const fail = (message?: string) => {
6
+ export const halt = (message?: string, exitCode = 1) => {
7
7
  logError(message)
8
- process.exit(1)
8
+ process.exit(exitCode)
9
9
  }
10
10
 
11
11
  ///////////////////////////////////////////////////////////////////////////////
package/src/lib/env.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  import {createRequire} from 'module'
2
+ import {basename} from 'path'
3
+ import glob from 'glob'
2
4
  import type {IfUtilsFn} from 'webpack-config-utils'
3
5
  import {expand as dotenvExpand} from 'dotenv-expand'
4
6
  import {config as dotenvConfig} from 'dotenv'
5
- import {getWidgetUuid, resolveApp} from 'lib/resolve'
7
+ import stripIndent from 'strip-indent'
8
+ import {getIfCoreFns, getPaths, getWidgetUuid, resolveApp} from 'lib/resolve'
9
+ import {halt} from 'lib/command'
6
10
 
7
11
  ///////////////////////////////////////////////////////////////////////////////
8
12
 
@@ -17,11 +21,13 @@ const require = createRequire(import.meta.url)
17
21
  ///////////////////////////////////////////////////////////////////////////////
18
22
 
19
23
  export const getEnvVars = (
20
- filePath: string,
24
+ files: string[],
21
25
  ifMin: IfUtilsFn,
22
26
  ifCore: IfUtilsFn,
23
27
  ifLocalCore: IfUtilsFn,
24
28
  ) => {
29
+ const filePath = files.find((file) => basename(file) === '.env')
30
+
25
31
  dotenvExpand(dotenvConfig({path: filePath}))
26
32
 
27
33
  process.env.NODE_ENV ??= ifMin('production', 'development')
@@ -32,6 +38,8 @@ export const getEnvVars = (
32
38
  'rnw-tamaro',
33
39
  )
34
40
  process.env.WEBPACK_UNIQUE_NAME ??= ifCore('RnwTamaroCore', 'RnwTamaro')
41
+ process.env.BUILD_DATE = new Date().toISOString()
42
+ process.env.PUBLIC_URL ??= ''
35
43
 
36
44
  // HMR doesn't work in ie11, it breaks everything.
37
45
  // If you want to run dev-server and test in ie11, set HMR_ENABLED to 'false'
@@ -68,6 +76,8 @@ export const getEnvVars = (
68
76
  'EXPOSE_VAR',
69
77
  'ELEMENT_ATTRIBUTE_DATA_WIDGET',
70
78
  'WEBPACK_UNIQUE_NAME',
79
+ 'BUILD_DATE',
80
+ 'PUBLIC_URL',
71
81
 
72
82
  // core
73
83
  'PRODUCT_NAME',
@@ -100,3 +110,38 @@ export const getEnvVars = (
100
110
 
101
111
  return {raw, stringified}
102
112
  }
113
+
114
+ ///////////////////////////////////////////////////////////////////////////////
115
+
116
+ export const assertEnvValid = (env: string) => {
117
+ const {ifCore} = getIfCoreFns()
118
+ const paths = getPaths(ifCore)
119
+ const files = glob.sync(paths.appEnv)
120
+ const envs = files
121
+ .map((file) => basename(file).replace(/^\.env\.?/, ''))
122
+ .filter((v) => !!v)
123
+
124
+ if (envs.length === 0) {
125
+ if (env) {
126
+ console.log('Flag “--env” is ignored.')
127
+ }
128
+ }
129
+
130
+ if (envs.length !== 0) {
131
+ if (!env) {
132
+ halt('Flag “--env” is required.')
133
+ }
134
+
135
+ if (!envs.includes(env)) {
136
+ halt(
137
+ stripIndent(`
138
+ Flag “--env” has wrong value.
139
+ Available values are: ${envs.map((v) => `“${v}”`).join(', ')}.
140
+ `),
141
+ )
142
+ }
143
+
144
+ const filePath = files.find((file) => basename(file) === `.env.${env}`)
145
+ dotenvExpand(dotenvConfig({path: filePath}))
146
+ }
147
+ }
@@ -72,7 +72,7 @@ export const getPaths = (ifCore: IfUtilsFn) => {
72
72
  appNodeModules: resolveApp('node_modules'),
73
73
  appTsConfig: resolveApp('tsconfig.json'),
74
74
  appHtml: resolveApp('src/*.html'),
75
- appEnv: resolveApp('.env'),
75
+ appEnv: resolveApp('.env*'),
76
76
  appTailwindConfig: resolveApp('tailwind.config.js'),
77
77
  },
78
78
  {
@@ -82,7 +82,7 @@ export const getPaths = (ifCore: IfUtilsFn) => {
82
82
  appNodeModules: resolveApp('../../node_modules'),
83
83
  appTsConfig: resolveApp('tsconfig.json'),
84
84
  appHtml: resolveApp('*.html'),
85
- appEnv: resolveApp('.env'),
85
+ appEnv: resolveApp('.env*'),
86
86
  appTailwindConfig: undefined,
87
87
  },
88
88
  )
@@ -44,7 +44,8 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
44
44
  const {ifCore} = getIfCoreFns()
45
45
  const paths = getPaths(ifCore)
46
46
  const appHtmlFiles = glob.sync(paths.appHtml)
47
- const envVars = getEnvVars(paths.appEnv, ifMin, ifCore, ifLocalCore)
47
+ const appEnvFiles = glob.sync(paths.appEnv)
48
+ const envVars = getEnvVars(appEnvFiles, ifMin, ifCore, ifLocalCore)
48
49
  const {ifHmr} = getIfUtils({hmr: process.env.HMR_ENABLED === 'true'}, ['hmr'])
49
50
  const useTailwind =
50
51
  ifCore() && paths.appTailwindConfig && existsSync(paths.appTailwindConfig)
@@ -231,53 +232,9 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
231
232
  }),
232
233
  },
233
234
 
234
- // SVG (in HTML and styles)
235
- {
236
- test: /\.svg$/,
237
- issuer: [/\.html$/, /\.s?css$/],
238
- type: 'asset',
239
- parser: {
240
- dataUrlCondition: {
241
- maxSize: imageInlineSizeLimit,
242
- },
243
- },
244
- },
245
-
246
- // SVG (in components)
247
- {
248
- test: /\.svg$/,
249
- issuer: [/\.(ts|tsx|js|jsx|md|mdx)$/],
250
- use: [
251
- {
252
- loader: require.resolve('@svgr/webpack'),
253
- options: {
254
- svgoConfig: {
255
- plugins: [
256
- {
257
- removeHiddenElems: false,
258
- moveGroupAttrsToElems: false,
259
- collapseGroups: false,
260
- },
261
- ],
262
- },
263
- prettier: false,
264
- titleProp: true,
265
- ref: true,
266
- },
267
- },
268
- {
269
- loader: require.resolve('url-loader'),
270
- options: {
271
- name: 'assets/[name]-[contenthash:16].[ext]',
272
- limit: imageInlineSizeLimit,
273
- },
274
- },
275
- ],
276
- },
277
-
278
235
  // Images and fonts
279
236
  {
280
- test: /\.(png|jpe?g|webp|gif|ico|ttf|eot|woff2?)$/,
237
+ test: /\.(png|jpe?g|svg|webp|gif|ico|ttf|eot|woff2?)$/,
281
238
  type: 'asset',
282
239
  parser: {
283
240
  dataUrlCondition: {
@@ -291,7 +248,10 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
291
248
  test: /\.ya?ml$/,
292
249
  use: [
293
250
  {loader: require.resolve('json-loader')},
294
- {loader: require.resolve('yaml-loader')},
251
+ {
252
+ loader: require.resolve('yaml-loader'),
253
+ options: {asJSON: true},
254
+ },
295
255
  ],
296
256
  },
297
257