@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.
@@ -0,0 +1,144 @@
1
+ import {createRequire} from 'module'
2
+ import {basename, dirname, join, relative, resolve} from 'path'
3
+ import {existsSync, realpathSync} from 'fs'
4
+ import {getIfUtils, IfUtils, IfUtilsFn} from 'webpack-config-utils'
5
+ import {logError} from 'lib/logging'
6
+ import stripIndent from 'strip-indent'
7
+ import chalk from 'chalk'
8
+
9
+ ///////////////////////////////////////////////////////////////////////////////
10
+
11
+ export type ResolveFn = (relativePath: string) => string
12
+
13
+ ///////////////////////////////////////////////////////////////////////////////
14
+
15
+ const require = createRequire(import.meta.url)
16
+ export const moduleFileExtensions = ['ts', 'tsx', 'js', 'jsx']
17
+ export const extensions = moduleFileExtensions.map((v) => `.${v}`)
18
+
19
+ ///////////////////////////////////////////////////////////////////////////////
20
+
21
+ const TAMARO_CORE_PACKAGE_NAMES = ['@raisenow/tamaro-core']
22
+ const TAMARO_CONFIGURATIONS_PACKAGE_NAMES = ['@raisenow/tamaro-configurations']
23
+
24
+ ///////////////////////////////////////////////////////////////////////////////
25
+
26
+ export const resolveApp: ResolveFn = (relativePath) =>
27
+ resolve(realpathSync(process.cwd()), relativePath)
28
+
29
+ ///////////////////////////////////////////////////////////////////////////////
30
+
31
+ // __dirname is "dist" in runtime
32
+ export const resolveOwn: ResolveFn = (relativePath) =>
33
+ resolve(__dirname, '..', relativePath)
34
+
35
+ ///////////////////////////////////////////////////////////////////////////////
36
+
37
+ export const resolveModule = (resolveFn: ResolveFn, filePath: string) => {
38
+ const extension = moduleFileExtensions.find((extension) =>
39
+ existsSync(resolveFn(`${filePath}.${extension}`)),
40
+ )
41
+
42
+ if (extension) {
43
+ return resolveFn(`${filePath}.${extension}`)
44
+ }
45
+
46
+ return resolveFn(`${filePath}.js`)
47
+ }
48
+
49
+ ///////////////////////////////////////////////////////////////////////////////
50
+
51
+ export const resolveBin = (name: string) => {
52
+ const pkgPath = require.resolve(`${name}/package.json`)
53
+ const {bin} = require(pkgPath)
54
+ const dir = dirname(pkgPath)
55
+ const binPath = typeof bin === 'object' ? bin[name] : bin
56
+
57
+ return join(dir, binPath)
58
+ }
59
+
60
+ ///////////////////////////////////////////////////////////////////////////////
61
+
62
+ export const getWidgetUuid = () => basename(resolveApp('.'))
63
+
64
+ ///////////////////////////////////////////////////////////////////////////////
65
+
66
+ export const getPaths = (ifCore: IfUtilsFn) => {
67
+ return ifCore(
68
+ {
69
+ app: resolveApp('.'),
70
+ appEntry: resolveModule(resolveApp, 'src/index'),
71
+ appDist: resolveApp('dist'),
72
+ appNodeModules: resolveApp('node_modules'),
73
+ appTsConfig: resolveApp('tsconfig.json'),
74
+ appHtml: resolveApp('src/*.html'),
75
+ appEnv: resolveApp('.env*'),
76
+ appTailwindConfig: resolveApp('tailwind.config.js'),
77
+ },
78
+ {
79
+ app: resolveApp('.'),
80
+ appEntry: resolveModule(resolveApp, 'widget'),
81
+ appDist: resolveApp(`../../dist/${getWidgetUuid()}`),
82
+ appNodeModules: resolveApp('../../node_modules'),
83
+ appTsConfig: resolveApp('tsconfig.json'),
84
+ appHtml: resolveApp('*.html'),
85
+ appEnv: resolveApp('.env*'),
86
+ appTailwindConfig: undefined,
87
+ },
88
+ )
89
+ }
90
+
91
+ ///////////////////////////////////////////////////////////////////////////////
92
+
93
+ type Paths = {
94
+ [key: string]: string | undefined
95
+ }
96
+
97
+ export const getRelativePaths = (paths: Paths): Paths => {
98
+ const relativePaths: Paths = {}
99
+
100
+ for (const [type, absPath] of Object.entries(paths)) {
101
+ if (absPath) {
102
+ relativePaths[type] = relative('./', absPath) || '.'
103
+ }
104
+ }
105
+
106
+ return relativePaths
107
+ }
108
+
109
+ ///////////////////////////////////////////////////////////////////////////////
110
+
111
+ export const getIfCoreFns = (): IfUtils => {
112
+ const corePkgPath = resolveApp('package.json')
113
+ const configsPkgPath = resolveApp('../../package.json')
114
+
115
+ if (existsSync(corePkgPath)) {
116
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
117
+ const {name} = require(corePkgPath)
118
+
119
+ if (TAMARO_CORE_PACKAGE_NAMES.includes(name)) {
120
+ return getIfUtils({core: true}, ['core'])
121
+ }
122
+ }
123
+
124
+ if (existsSync(configsPkgPath)) {
125
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
126
+ const {name} = require(configsPkgPath)
127
+
128
+ if (TAMARO_CONFIGURATIONS_PACKAGE_NAMES.includes(name)) {
129
+ return getIfUtils({core: false}, ['core'])
130
+ }
131
+ }
132
+
133
+ logError(
134
+ stripIndent(`\
135
+ You must run "npx @raisenow/tamaro-cli" commands from:
136
+ 1. Root of "${chalk.bold(TAMARO_CORE_PACKAGE_NAMES[0])}" package folder.
137
+ 2. Root of particular customer configuration folder of "${chalk.bold(
138
+ TAMARO_CONFIGURATIONS_PACKAGE_NAMES[0],
139
+ )}" package.
140
+ You are currently in "${chalk.bold(realpathSync(process.cwd()))}".
141
+ `),
142
+ )
143
+ process.exit(1)
144
+ }
@@ -1,15 +1,10 @@
1
+ import {createRequire} from 'module'
1
2
  import {basename, dirname} from 'path'
2
3
  import {existsSync} from 'fs'
3
4
  import glob from 'glob'
4
5
  import {getIfUtils, removeEmpty} from 'webpack-config-utils'
5
- import webpack, {
6
- Configuration,
7
- DefinePlugin,
8
- IgnorePlugin,
9
- ProgressPlugin,
10
- RuleSetUseItem,
11
- } from 'webpack'
12
- import {getPortPromise} from 'portfinder'
6
+ import webpack from 'webpack'
7
+ import type {Configuration, RuleSetUseItem} from 'webpack'
13
8
  import {TsconfigPathsPlugin} from 'tsconfig-paths-webpack-plugin'
14
9
  import {CleanWebpackPlugin} from 'clean-webpack-plugin'
15
10
  import HtmlWebpackPlugin from 'html-webpack-plugin'
@@ -22,21 +17,21 @@ import {} from 'webpack-dev-server'
22
17
  import ESLintPlugin from 'eslint-webpack-plugin'
23
18
  import CopyPlugin from 'copy-webpack-plugin'
24
19
  import StatoscopeWebpackPlugin from '@statoscope/webpack-plugin'
25
- import InterpolateHtmlPlugin from 'lib/InterpolateHtmlPlugin'
20
+ import {InterpolateHtmlPlugin} from 'lib/InterpolateHtmlPlugin'
26
21
  import {
27
22
  extensions,
28
- getEnvVars,
29
23
  getIfCoreFns,
30
24
  getPaths,
31
25
  getRelativePaths,
32
- logDataTable,
33
26
  moduleFileExtensions,
34
27
  resolveApp,
35
- resolveOwn,
36
- } from 'lib/helpers'
28
+ } from 'lib/resolve'
29
+ import {getEnvVars} from 'lib/env'
30
+ import {logDataTable, logTitle} from 'lib/logging'
37
31
 
38
32
  ///////////////////////////////////////////////////////////////////////////////
39
33
 
34
+ const require = createRequire(import.meta.url)
40
35
  const imageInlineSizeLimit = 0
41
36
  // const imageInlineSizeLimit = 8 * 1024 // 8kb
42
37
 
@@ -49,14 +44,17 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
49
44
  const {ifCore} = getIfCoreFns()
50
45
  const paths = getPaths(ifCore)
51
46
  const appHtmlFiles = glob.sync(paths.appHtml)
52
- const envVars = getEnvVars(paths.appEnv, ifMin, ifCore, ifLocalCore)
47
+ const appEnvFiles = glob.sync(paths.appEnv)
48
+ const envVars = getEnvVars(appEnvFiles, ifMin, ifCore, ifLocalCore)
53
49
  const {ifHmr} = getIfUtils({hmr: process.env.HMR_ENABLED === 'true'}, ['hmr'])
54
- const port = await getPortPromise({port: 1234})
55
50
  const useTailwind =
56
51
  ifCore() && paths.appTailwindConfig && existsSync(paths.appTailwindConfig)
57
52
 
58
- logDataTable(getRelativePaths(paths), 'Paths')
59
- logDataTable(envVars.raw, 'Environment variables')
53
+ logTitle('Paths:')
54
+ logDataTable(getRelativePaths(paths))
55
+
56
+ logTitle('Environment variables:')
57
+ logDataTable(envVars.raw)
60
58
 
61
59
  const getCssLoaders = (cssOptions: any = {}): RuleSetUseItem[] => {
62
60
  return removeEmpty([
@@ -121,7 +119,7 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
121
119
  }),
122
120
  ],
123
121
  },
124
- entry: [resolveOwn('src/lib/polyfills.js'), paths.appEntry],
122
+ entry: paths.appEntry,
125
123
  output: {
126
124
  publicPath: 'auto',
127
125
  path: ifMin(paths.appDist, undefined),
@@ -234,53 +232,9 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
234
232
  }),
235
233
  },
236
234
 
237
- // SVG (in HTML and styles)
238
- {
239
- test: /\.svg$/,
240
- issuer: [/\.html$/, /\.s?css$/],
241
- type: 'asset',
242
- parser: {
243
- dataUrlCondition: {
244
- maxSize: imageInlineSizeLimit,
245
- },
246
- },
247
- },
248
-
249
- // SVG (in components)
250
- {
251
- test: /\.svg$/,
252
- issuer: [/\.(ts|tsx|js|jsx|md|mdx)$/],
253
- use: [
254
- {
255
- loader: require.resolve('@svgr/webpack'),
256
- options: {
257
- svgoConfig: {
258
- plugins: [
259
- {
260
- removeHiddenElems: false,
261
- moveGroupAttrsToElems: false,
262
- collapseGroups: false,
263
- },
264
- ],
265
- },
266
- prettier: false,
267
- titleProp: true,
268
- ref: true,
269
- },
270
- },
271
- {
272
- loader: require.resolve('url-loader'),
273
- options: {
274
- name: 'assets/[name]-[contenthash:16].[ext]',
275
- limit: imageInlineSizeLimit,
276
- },
277
- },
278
- ],
279
- },
280
-
281
235
  // Images and fonts
282
236
  {
283
- test: /\.(png|jpe?g|webp|gif|ico|ttf|eot|woff2?)$/,
237
+ test: /\.(png|jpe?g|svg|webp|gif|ico|ttf|eot|woff2?)$/,
284
238
  type: 'asset',
285
239
  parser: {
286
240
  dataUrlCondition: {
@@ -321,7 +275,6 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
321
275
  devtool: ifMin(false, 'cheap-module-source-map'),
322
276
 
323
277
  devServer: {
324
- port,
325
278
  static: false,
326
279
  historyApiFallback: {
327
280
  disableDotRule: true,
@@ -347,7 +300,7 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
347
300
  },
348
301
 
349
302
  plugins: removeEmpty([
350
- new ProgressPlugin(),
303
+ new webpack.ProgressPlugin(),
351
304
  new ESLintPlugin({
352
305
  extensions: moduleFileExtensions,
353
306
  eslintPath: require.resolve('eslint'),
@@ -384,7 +337,7 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
384
337
  ),
385
338
 
386
339
  new InterpolateHtmlPlugin(envVars.raw),
387
- new DefinePlugin(envVars.stringified),
340
+ new webpack.DefinePlugin(envVars.stringified),
388
341
 
389
342
  new ForkTsCheckerWebpackPlugin({
390
343
  typescript: {
@@ -415,7 +368,7 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
415
368
  }),
416
369
  ),
417
370
 
418
- new IgnorePlugin({
371
+ new webpack.IgnorePlugin({
419
372
  resourceRegExp: /^\.\/locale$/,
420
373
  contextRegExp: /moment$/,
421
374
  }),
@@ -424,16 +377,7 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
424
377
 
425
378
  ifMin() && ifCore()
426
379
  ? new CopyPlugin({
427
- patterns: [
428
- {
429
- from: 'readme.md',
430
- to: 'readme.md',
431
- },
432
- {
433
- from: 'readme.html',
434
- to: 'readme.html',
435
- },
436
- ],
380
+ patterns: ['README.md', 'readme.html'],
437
381
  })
438
382
  : undefined,
439
383
 
@@ -447,6 +391,11 @@ const getWebpackConfig = async (env: any): Promise<Configuration> => {
447
391
  })
448
392
  : undefined,
449
393
  ]),
394
+
395
+ infrastructureLogging: {
396
+ stream: process.stdout,
397
+ appendOnly: false,
398
+ },
450
399
  }
451
400
 
452
401
  // console.log(util.inspect(config, {showHidden: false, depth: null}))
package/tsconfig.json CHANGED
@@ -5,7 +5,7 @@
5
5
  /* Basic Options */
6
6
  // "incremental": true, /* Enable incremental compilation */
7
7
  "target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
8
- "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
8
+ "module": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
9
9
  // "lib": [], /* Specify library files to be included in the compilation. */
10
10
  "allowJs": true, /* Allow javascript files to be compiled. */
11
11
  // "checkJs": true, /* Report errors in .js files. */