@raisenow/tamaro-cli 1.1.8 → 1.1.9

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,143 +0,0 @@
1
- import {existsSync, realpathSync} from 'fs'
2
- import {createRequire} from 'module'
3
- import {basename, dirname, join, relative, resolve} from 'path'
4
- import chalk from 'chalk'
5
- import stripIndent from 'strip-indent'
6
- import {getIfUtils, type IfUtils, type IfUtilsFn} from 'webpack-config-utils'
7
- import {logError} from 'lib/logging'
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
- const TAMARO_SELF_SERVICE_PACKAGE_NAMES = ['@raisenow/tamaro-self-service']
24
-
25
- ///////////////////////////////////////////////////////////////////////////////
26
-
27
- export const resolveApp: ResolveFn = (relativePath) =>
28
- resolve(realpathSync(process.cwd()), relativePath)
29
-
30
- ///////////////////////////////////////////////////////////////////////////////
31
-
32
- // __dirname is "dist" in runtime
33
- export const resolveOwn: ResolveFn = (relativePath) =>
34
- resolve(__dirname, '..', relativePath)
35
-
36
- ///////////////////////////////////////////////////////////////////////////////
37
-
38
- export const resolveModule = (resolveFn: ResolveFn, filePath: string) => {
39
- const extension = moduleFileExtensions.find((extension) =>
40
- existsSync(resolveFn(`${filePath}.${extension}`)),
41
- )
42
-
43
- if (extension) {
44
- return resolveFn(`${filePath}.${extension}`)
45
- }
46
-
47
- return resolveFn(`${filePath}.js`)
48
- }
49
-
50
- ///////////////////////////////////////////////////////////////////////////////
51
-
52
- export const resolveBin = (name: string) => {
53
- const pkgPath = require.resolve(`${name}/package.json`)
54
- const {bin} = require(pkgPath)
55
- const dir = dirname(pkgPath)
56
- const binPath: string = typeof bin === 'object' ? bin[name] : bin
57
-
58
- return join(dir, binPath)
59
- }
60
-
61
- ///////////////////////////////////////////////////////////////////////////////
62
-
63
- export const getWidgetUuid = () => basename(resolveApp('.'))
64
-
65
- ///////////////////////////////////////////////////////////////////////////////
66
-
67
- export const getPaths = (ifCore: IfUtilsFn) => {
68
- return ifCore(
69
- {
70
- root: resolveApp('.'),
71
- app: resolveApp('.'),
72
- appEntry: resolveModule(resolveApp, 'src/index'),
73
- appDist: resolveApp('dist'),
74
- appNodeModules: resolveApp('node_modules'),
75
- appTsConfig: resolveApp('tsconfig.json'),
76
- appHtml: resolveApp('src/*.html'),
77
- appEnv: resolveApp('.env*'),
78
- appTailwindConfig: resolveApp('tailwind.config.js'),
79
- },
80
- {
81
- root: resolveApp('../..'),
82
- app: resolveApp('.'),
83
- appEntry: resolveModule(resolveApp, 'widget'),
84
- appDist: resolveApp(`../../dist/${getWidgetUuid()}`),
85
- appNodeModules: resolveApp('../../node_modules'),
86
- appTsConfig: resolveApp('tsconfig.json'),
87
- appHtml: resolveApp('*.html'),
88
- appEnv: resolveApp('.env*'),
89
- appTailwindConfig: undefined,
90
- },
91
- )
92
- }
93
-
94
- ///////////////////////////////////////////////////////////////////////////////
95
-
96
- type Paths = Record<string, string | undefined>
97
-
98
- export const getRelativePaths = (paths: Paths): Paths => {
99
- const relativePaths: Paths = {}
100
-
101
- for (const [type, absPath] of Object.entries(paths)) {
102
- if (absPath) {
103
- relativePaths[type] = relative('./', absPath) || '.'
104
- }
105
- }
106
-
107
- return relativePaths
108
- }
109
-
110
- ///////////////////////////////////////////////////////////////////////////////
111
-
112
- export const getIfCoreFns = (): IfUtils => {
113
- const corePkgPath = resolveApp('package.json')
114
- const configsPkgPath = resolveApp('../../package.json')
115
- let packageName
116
-
117
- if (existsSync(corePkgPath)) {
118
- packageName = require(corePkgPath).name
119
- } else if (existsSync(configsPkgPath)) {
120
- packageName = require(configsPkgPath).name
121
- }
122
-
123
- if (packageName) {
124
- return getIfUtils({core: TAMARO_CORE_PACKAGE_NAMES.includes(packageName)}, [
125
- 'core',
126
- ])
127
- }
128
-
129
- logError(
130
- stripIndent(`\
131
- You must run "npx @raisenow/tamaro-cli" commands from:
132
- 1. Root of "${chalk.bold(TAMARO_CORE_PACKAGE_NAMES[0])}" package folder.
133
- 2. Root of particular customer configuration folder of "${chalk.bold(
134
- TAMARO_CONFIGURATIONS_PACKAGE_NAMES[0],
135
- )}" package.
136
- 3. "src/self-service" folder of "${chalk.bold(
137
- TAMARO_SELF_SERVICE_PACKAGE_NAMES[0],
138
- )}" package.
139
- You are currently in "${chalk.bold(realpathSync(process.cwd()))}".
140
- `),
141
- )
142
- process.exit(1)
143
- }
@@ -1,437 +0,0 @@
1
- import {existsSync} from 'fs'
2
- import {createRequire} from 'module'
3
- import {basename, dirname, resolve} from 'path'
4
- import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
5
- import StatoscopeWebpackPlugin from '@statoscope/webpack-plugin'
6
- import {CleanWebpackPlugin} from 'clean-webpack-plugin'
7
- import CopyPlugin from 'copy-webpack-plugin'
8
- import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
9
- import ESLintPlugin from 'eslint-webpack-plugin'
10
- import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
11
- import {globSync} from 'glob'
12
- import HtmlWebpackPlugin from 'html-webpack-plugin'
13
- import MiniCssExtractPlugin from 'mini-css-extract-plugin'
14
- import {TsconfigPathsPlugin} from 'tsconfig-paths-webpack-plugin'
15
- import type {Configuration, RuleSetUseItem} from 'webpack'
16
- // eslint-disable-next-line import/no-named-as-default
17
- import webpack from 'webpack'
18
- import {getIfUtils, removeEmpty} from 'webpack-config-utils'
19
- // Needed for webpack-dev-server types to be picked up correctly
20
- import {} from 'webpack-dev-server'
21
- import {HTTPS_CRT_FILE, HTTPS_KEY_FILE} from 'lib/constants'
22
- import {getEnvVars} from 'lib/env'
23
- import {InterpolateHtmlPlugin} from 'lib/InterpolateHtmlPlugin'
24
- import {logDataTable, logTitle} from 'lib/logging'
25
- import {
26
- extensions,
27
- getIfCoreFns,
28
- getPaths,
29
- getRelativePaths,
30
- moduleFileExtensions,
31
- resolveApp,
32
- } from 'lib/resolve'
33
-
34
- ///////////////////////////////////////////////////////////////////////////////
35
-
36
- const require = createRequire(import.meta.url)
37
- const imageInlineSizeLimit = 0
38
- // const imageInlineSizeLimit = 8 * 1024 // 8kb
39
-
40
- ///////////////////////////////////////////////////////////////////////////////
41
-
42
- const getWebpackConfig = (env: any): Configuration => {
43
- const {ifMin, ifNotMin} = getIfUtils(env, ['min'])
44
- const {ifAnalyze} = getIfUtils(env, ['analyze'])
45
- const {ifHttps} = getIfUtils(env, ['https'])
46
- const {ifLocalCore} = getIfUtils(env, ['localCore'])
47
- const {ifCore} = getIfCoreFns()
48
- const paths = getPaths(ifCore)
49
- const appHtmlFiles = globSync(paths.appHtml)
50
- const appEnvFiles = globSync(paths.appEnv)
51
- const envVars = getEnvVars(appEnvFiles, ifMin, ifCore, ifLocalCore, ifHttps)
52
- const {ifHmr} = getIfUtils({hmr: process.env.HMR_ENABLED === 'true'}, ['hmr'])
53
- const {ifNolint} = getIfUtils(env, ['nolint'])
54
- const useTailwind =
55
- ifCore() && paths.appTailwindConfig && existsSync(paths.appTailwindConfig)
56
-
57
- logTitle('Paths:')
58
- logDataTable(getRelativePaths(paths))
59
-
60
- logTitle('Environment variables:')
61
- logDataTable(envVars.raw)
62
-
63
- const getCssLoaders = ({
64
- styleLoader = true,
65
- ...cssOptions
66
- }: {styleLoader?: boolean} & Record<string, any>): RuleSetUseItem[] => {
67
- return removeEmpty([
68
- styleLoader ? ifMin({loader: MiniCssExtractPlugin.loader}) : undefined,
69
- styleLoader
70
- ? ifNotMin({
71
- loader: require.resolve('style-loader'),
72
- options: {
73
- attributes: {
74
- 'data-widget': process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET,
75
- },
76
- },
77
- })
78
- : undefined,
79
- {
80
- loader: require.resolve('css-loader'),
81
- options: {
82
- sourceMap: ifNotMin(),
83
- importLoaders: 3,
84
- ...cssOptions,
85
- },
86
- },
87
- {
88
- loader: require.resolve('postcss-loader'),
89
- options: {
90
- postcssOptions: {
91
- plugins: removeEmpty([
92
- useTailwind
93
- ? [
94
- require.resolve('tailwindcss', {
95
- paths: [paths.appNodeModules],
96
- }),
97
- paths.appTailwindConfig,
98
- ]
99
- : undefined,
100
- require.resolve('postcss-custom-properties'),
101
- require.resolve('autoprefixer'),
102
- ]),
103
- },
104
- },
105
- },
106
- {
107
- loader: require.resolve('resolve-url-loader'),
108
- options: {sourceMap: ifNotMin()},
109
- },
110
- {
111
- loader: require.resolve('sass-loader'),
112
- options: {api: 'modern-compiler', sourceMap: true},
113
- },
114
- ])
115
- }
116
-
117
- const config: Configuration = {
118
- mode: ifMin('production', 'development'),
119
- resolve: {
120
- symlinks: false,
121
- extensions: [...extensions, '...'],
122
- modules: ['node_modules', paths.appNodeModules],
123
- plugins: [
124
- new TsconfigPathsPlugin({
125
- configFile: paths.appTsConfig,
126
- extensions,
127
- }),
128
- ],
129
- },
130
- entry: paths.appEntry,
131
- output: {
132
- publicPath: 'auto',
133
- path: ifMin(paths.appDist, undefined),
134
- pathinfo: false,
135
- filename: ifCore('index.js', 'widget.js'),
136
- chunkFilename: ifMin('[name]-[contenthash:16].js', '[name].js'),
137
- assetModuleFilename: 'assets/[name]-[contenthash:16][ext]',
138
- crossOriginLoading: 'anonymous',
139
- uniqueName: process.env.WEBPACK_UNIQUE_NAME,
140
- },
141
- stats: ifAnalyze(
142
- {
143
- all: undefined,
144
- },
145
- {
146
- modules: false,
147
- children: false,
148
- chunks: false,
149
- env: true,
150
- entrypoints: true,
151
- errorDetails: true,
152
- },
153
- ),
154
- module: {
155
- rules: removeEmpty([
156
- // Source maps
157
- ifNotMin({
158
- enforce: 'pre',
159
- exclude: /@babel\/runtime/,
160
- test: /\.(js|jsx|ts|tsx|css|scss)$/,
161
- use: require.resolve('source-map-loader'),
162
- }),
163
-
164
- {
165
- oneOf: [
166
- /**
167
- * App Javascript and Typescript (Babel)
168
- * and some dependencies distributed in a non-es5 formats
169
- */
170
- {
171
- test: /\.(js|ts)x?$/,
172
- include: ifCore(
173
- [
174
- resolveApp('src'),
175
- resolveApp('node_modules/micromark'),
176
- resolveApp('node_modules/decode-named-character-reference'),
177
- ],
178
- [resolveApp('.'), resolveApp('../../src')],
179
- ),
180
-
181
- loader: require.resolve('babel-loader'),
182
- options: {
183
- babelrc: false,
184
- configFile: false,
185
- sourceMaps: ifNotMin(),
186
- inputSourceMap: ifNotMin(),
187
- presets: [
188
- require.resolve('@babel/preset-env'),
189
- [
190
- require.resolve('@babel/preset-typescript'),
191
- {
192
- allowDeclareFields: true,
193
- },
194
- ],
195
- require.resolve('@babel/preset-react'),
196
- ],
197
- plugins: removeEmpty([
198
- [
199
- require.resolve('@babel/plugin-transform-runtime'),
200
- {
201
- corejs: {
202
- version: 3,
203
- proposals: true,
204
- },
205
- absoluteRuntime: dirname(
206
- require.resolve('@babel/runtime-corejs3/package.json'),
207
- ),
208
- },
209
- ],
210
- [
211
- require.resolve('@babel/plugin-proposal-decorators'),
212
- {
213
- legacy: true,
214
- },
215
- ],
216
- require.resolve('@babel/plugin-syntax-dynamic-import'),
217
- require.resolve('babel-plugin-lodash'),
218
- ifHmr(require.resolve('react-refresh/babel')),
219
- ifNotMin(require.resolve('babel-plugin-istanbul')),
220
- ]),
221
- },
222
- },
223
-
224
- // Other Javascript (not in app) - no transformation
225
- {
226
- test: /\.(js|mjs)$/,
227
- },
228
-
229
- // Styles (extracted)
230
- {
231
- test: /\.s?css$/,
232
- resourceQuery: {not: [/inline/]},
233
- use: getCssLoaders({
234
- styleLoader: true,
235
- }),
236
- },
237
-
238
- // Styles (as string)
239
- {
240
- test: /\.s?css$/,
241
- resourceQuery: /inline/,
242
- use: getCssLoaders({
243
- styleLoader: false,
244
- exportType: 'string',
245
- sourceMap: false,
246
- }),
247
- },
248
-
249
- // Images and fonts
250
- {
251
- test: /\.(png|jpe?g|svg|webp|gif|ico|ttf|eot|woff2?)$/,
252
- type: 'asset',
253
- parser: {
254
- dataUrlCondition: {
255
- maxSize: imageInlineSizeLimit,
256
- },
257
- },
258
- },
259
-
260
- // YML
261
- {
262
- test: /\.ya?ml$/,
263
- use: [
264
- {loader: require.resolve('json-loader')},
265
- {
266
- loader: require.resolve('yaml-loader'),
267
- options: {asJSON: true},
268
- },
269
- ],
270
- },
271
-
272
- // HTML
273
- {
274
- test: /\.html$/,
275
- loader: require.resolve('html-loader'),
276
- options: {
277
- minimize: false,
278
- },
279
- },
280
-
281
- /**
282
- * All other files - fallback
283
- * This must be the latest rule!
284
- */
285
- {
286
- exclude: [/^$/, /\.(js|jsx|ts|tsx|mjs)$/, /\.html$/, /\.json$/],
287
- type: 'asset/resource',
288
- },
289
- ],
290
- },
291
- ]),
292
- },
293
-
294
- devtool: ifMin(false, 'cheap-module-source-map'),
295
-
296
- devServer: {
297
- static: false,
298
- historyApiFallback: {
299
- disableDotRule: true,
300
- },
301
- hot: ifHmr(),
302
- headers: {
303
- 'Access-Control-Allow-Origin': '*',
304
- },
305
- allowedHosts: 'all',
306
- client: {
307
- overlay: {
308
- warnings: false,
309
- errors: true,
310
- },
311
- },
312
- server: ifHttps({
313
- type: 'https',
314
- options: {
315
- cert: resolve(paths.root, HTTPS_CRT_FILE),
316
- key: resolve(paths.root, HTTPS_KEY_FILE),
317
- },
318
- }),
319
- },
320
-
321
- optimization: {
322
- // minimize: false,
323
- removeEmptyChunks: true,
324
- // moduleIds: 'deterministic', // todo: use instead of HashedModuleIdsPlugin
325
- // chunkIds: 'named',
326
- minimizer: ['...', new CssMinimizerPlugin()], // sourceMaps: true?
327
- },
328
-
329
- plugins: removeEmpty([
330
- new webpack.ProgressPlugin(),
331
- ifNolint(
332
- false,
333
- new ESLintPlugin({
334
- extensions: moduleFileExtensions,
335
- eslintPath: require.resolve('eslint'),
336
- cwd: paths.app,
337
- resolvePluginsRelativeTo: paths.app,
338
- }),
339
- ),
340
- ifMin(
341
- new CleanWebpackPlugin({
342
- // verbose: true,
343
- }),
344
- ),
345
-
346
- ...appHtmlFiles.map(
347
- (file) =>
348
- new HtmlWebpackPlugin({
349
- template: file,
350
- filename: basename(file),
351
- inject: false,
352
- minify: false,
353
- // ...ifMin({
354
- // minify: {
355
- // collapseWhitespace: true,
356
- // removeComments: true,
357
- // removeRedundantAttributes: true,
358
- // removeScriptTypeAttributes: true,
359
- // removeStyleLinkTypeAttributes: true,
360
- // useShortDoctype: true,
361
- // quoteCharacter: '"',
362
- // minifyJS: true,
363
- // minifyCSS: true,
364
- // },
365
- // }),
366
- }),
367
- ),
368
-
369
- new InterpolateHtmlPlugin(envVars.raw),
370
- new webpack.DefinePlugin(envVars.stringified),
371
-
372
- new ForkTsCheckerWebpackPlugin({
373
- typescript: {
374
- typescriptPath: require.resolve('typescript', {
375
- paths: [paths.appNodeModules],
376
- }),
377
- configFile: paths.appTsConfig,
378
- mode: 'write-references',
379
- diagnosticOptions: {
380
- syntactic: true,
381
- semantic: true,
382
- declaration: false,
383
- global: false,
384
- },
385
- },
386
- }),
387
-
388
- ifHmr(new ReactRefreshWebpackPlugin()),
389
-
390
- ifMin(
391
- new MiniCssExtractPlugin({
392
- filename: '[name]-[contenthash:16].css',
393
- chunkFilename: '[name]-[contenthash:16].css',
394
- ignoreOrder: true,
395
- attributes: {
396
- 'data-widget': process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET!,
397
- },
398
- }),
399
- ),
400
-
401
- new webpack.IgnorePlugin({
402
- resourceRegExp: /^\.\/locale$/,
403
- contextRegExp: /moment$/,
404
- }),
405
-
406
- // eslint-disable-next-line import/no-named-as-default-member
407
- ifMin(new webpack.ids.HashedModuleIdsPlugin()), // todo: remove?
408
-
409
- ifMin() && ifCore()
410
- ? new CopyPlugin({
411
- patterns: ['*.md', '*.html'],
412
- })
413
- : undefined,
414
-
415
- ifMin() && ifAnalyze()
416
- ? new StatoscopeWebpackPlugin({
417
- name: ifCore('tamaro-core', 'tamaro-customer-config'),
418
- saveReportTo: 'reports/report.html',
419
- saveStatsTo: 'reports/stats-[name]-[hash].json',
420
- additionalStats: globSync('reports/*.json'),
421
- open: false,
422
- })
423
- : undefined,
424
- ]),
425
-
426
- infrastructureLogging: {
427
- stream: process.stdout,
428
- appendOnly: false,
429
- },
430
- }
431
-
432
- // console.log(util.inspect(config, {showHidden: false, depth: null}))
433
-
434
- return removeEmpty(config)
435
- }
436
-
437
- export default getWebpackConfig
package/tsconfig.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- /* https://aka.ms/tsconfig.json */
3
- "compilerOptions": {
4
- "moduleDetection": "force",
5
- "resolveJsonModule": true,
6
- "allowJs": true,
7
- "esModuleInterop": true,
8
- "isolatedModules": true,
9
-
10
- "noEmit": true,
11
- "strict": true,
12
- "noFallthroughCasesInSwitch": true,
13
- "allowSyntheticDefaultImports": true,
14
- "skipLibCheck": true,
15
- "forceConsistentCasingInFileNames": true,
16
-
17
- "target": "ESNext",
18
- "module": "ESNext",
19
- "moduleResolution": "Bundler",
20
- "jsx": "react",
21
-
22
- "baseUrl": ".",
23
- "paths": {
24
- "commands/*": ["src/commands/*"],
25
- "lib/*": ["src/lib/*"]
26
- },
27
- },
28
- "include": [
29
- "**/*",
30
- ".eslintrc.cjs",
31
- ],
32
- "exclude": [
33
- ".history",
34
- ".idea",
35
- "dist",
36
- "node_modules",
37
- ]
38
- }