@raisenow/tamaro-cli 1.1.8 → 1.2.0

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.
Files changed (106) hide show
  1. package/.history/.eslintignore_20220609190420 +4 -0
  2. package/.history/.eslintignore_20230911190227 +6 -0
  3. package/.history/.eslintignore_20230911211247 +7 -0
  4. package/.history/.eslintignore_20230911211250 +7 -0
  5. package/.history/.eslintrc_20230911201601.js +49 -0
  6. package/.history/.eslintrc_20230911201643.js +49 -0
  7. package/.history/.eslintrc_20230911201735.js +49 -0
  8. package/.history/.eslintrc_20230911201913.js +64 -0
  9. package/.history/.eslintrc_20230911202002.js +62 -0
  10. package/.history/.eslintrc_20230911202138.js +133 -0
  11. package/.history/.eslintrc_20230911202140.js +133 -0
  12. package/.history/.eslintrc_20230911202145.js +133 -0
  13. package/.history/.eslintrc_20230911202147.js +133 -0
  14. package/.history/.eslintrc_20230911202406.js +133 -0
  15. package/.history/.eslintrc_20230911202447.js +133 -0
  16. package/.history/.eslintrc_20230911202453.js +133 -0
  17. package/.history/.eslintrc_20230911202511.js +133 -0
  18. package/.history/.eslintrc_20230911202527.js +133 -0
  19. package/.history/.eslintrc_20230911202639.js +125 -0
  20. package/.history/.eslintrc_20230911202721.js +149 -0
  21. package/.history/.eslintrc_20230911202746.js +149 -0
  22. package/.history/.eslintrc_20240423125702.cjs +148 -0
  23. package/.history/.gitignore_20220609190420 +14 -0
  24. package/.history/.gitignore_20230911185959 +4 -0
  25. package/.history/.gitignore_20230911190006 +4 -0
  26. package/.history/.gitignore_20230911190007 +4 -0
  27. package/.history/.nmprc_20241004144025 +0 -0
  28. package/.history/.nmprc_20241004144041 +1 -0
  29. package/.history/.npmrc_20241004144040 +1 -0
  30. package/.history/.npmrc_20241004144152 +1 -0
  31. package/.history/.npmrc_20241004145639 +2 -0
  32. package/.history/.npmrc_20241004145649 +1 -0
  33. package/.history/.nvmrc_20241125012803 +1 -0
  34. package/.history/.nvmrc_20241125022800 +1 -0
  35. package/.history/.nvmrc_20241125022806 +1 -0
  36. package/.history/.prettierignore_20220609190420 +5 -0
  37. package/.history/.prettierignore_20230911190242 +7 -0
  38. package/.history/.prettierignore_20230911190245 +7 -0
  39. package/.history/.prettierignore_20230911211301 +8 -0
  40. package/.history/CHANGELOG_20250624052910.md +20 -0
  41. package/.history/CHANGELOG_20250624055058.md +23 -0
  42. package/.history/CHANGELOG_20250624055107.md +23 -0
  43. package/.history/CHANGELOG_20250624055138.md +23 -0
  44. package/.history/CHANGELOG_20250624055156.md +23 -0
  45. package/.history/CHANGELOG_20250624055200.md +23 -0
  46. package/.history/CHANGELOG_20250624055203.md +23 -0
  47. package/.history/CHANGELOG_20250625142852.md +25 -0
  48. package/.history/CHANGELOG_20250625142901.md +22 -0
  49. package/.history/CHANGELOG_20250625142902.md +22 -0
  50. package/.history/README_20230911145033.md +245 -0
  51. package/.history/README_20230911151749.md +245 -0
  52. package/.history/README_20230911151844.md +245 -0
  53. package/.history/README_20230911153040.md +245 -0
  54. package/.history/README_20230911202959.md +245 -0
  55. package/.history/cli_20241005014539 +3 -0
  56. package/.history/cli_20241005014542 +3 -0
  57. package/.history/cli_20241005014848 +3 -0
  58. package/.history/dist/chunk-FICM3HUI_20230912183408.js +302 -0
  59. package/.history/dist/chunk-FICM3HUI_20230912201610.js +302 -0
  60. package/.history/package_20241107122123.json +106 -0
  61. package/.history/package_20241107122219.json +106 -0
  62. package/.history/package_20241107124611.json +106 -0
  63. package/.history/package_20241107125521.json +106 -0
  64. package/.history/package_20241107125538.json +106 -0
  65. package/.history/package_20241125013228.json +106 -0
  66. package/.history/package_20241125013249.json +106 -0
  67. package/.history/package_20241125014402.json +105 -0
  68. package/.history/package_20241125103106.json +105 -0
  69. package/.history/tsconfig_20241005001442.json +34 -0
  70. package/.history/tsconfig_20241005001500.json +34 -0
  71. package/.history/tsconfig_20241005001540.json +34 -0
  72. package/.history/tsconfig_20241005014429.json +42 -0
  73. package/.history/tsconfig_20241005014436.json +42 -0
  74. package/.history/tsconfig_20241005014439.json +38 -0
  75. package/.history/tsconfig_20241005014455.json +38 -0
  76. package/.idea/codeStyles/Project.xml +131 -0
  77. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  78. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  79. package/.idea/misc.xml +17 -0
  80. package/.idea/modules.xml +8 -0
  81. package/.idea/prettier.xml +6 -0
  82. package/.idea/tamaro-cli.iml +12 -0
  83. package/.idea/vcs.xml +6 -0
  84. package/README.md +35 -13
  85. package/bitbucket-pipelines.yml +43 -0
  86. package/dist/cli.js +42 -1
  87. package/dist/webpack.config.js +43 -12
  88. package/package.json +5 -1
  89. package/src/cli.ts +0 -178
  90. package/src/commands/build.ts +0 -131
  91. package/src/commands/deploy-email-config.ts +0 -159
  92. package/src/commands/deploy.ts +0 -164
  93. package/src/commands/dev.ts +0 -88
  94. package/src/commands/list-deployed.ts +0 -117
  95. package/src/commands/serve.ts +0 -69
  96. package/src/lib/InterpolateHtmlPlugin.ts +0 -47
  97. package/src/lib/aws.ts +0 -138
  98. package/src/lib/command.ts +0 -27
  99. package/src/lib/constants.ts +0 -9
  100. package/src/lib/env.ts +0 -175
  101. package/src/lib/https.ts +0 -27
  102. package/src/lib/logging.ts +0 -37
  103. package/src/lib/notifier.ts +0 -22
  104. package/src/lib/resolve.ts +0 -143
  105. package/src/webpack.config.ts +0 -437
  106. /package/{tsconfig.json → .history/tsconfig_20241005014521.json} +0 -0
package/src/lib/aws.ts DELETED
@@ -1,138 +0,0 @@
1
- import {execaCommandSync} from 'execa'
2
- // eslint-disable-next-line import/no-named-as-default
3
- import prompts from 'prompts'
4
- import stripIndent from 'strip-indent'
5
- import {halt} from 'lib/command'
6
-
7
- ///////////////////////////////////////////////////////////////////////////////
8
-
9
- export type AwsOptions = {
10
- profile?: string
11
- ci?: boolean
12
- }
13
-
14
- ///////////////////////////////////////////////////////////////////////////////
15
-
16
- export const awsAuthenticate = (options: AwsOptions) => {
17
- if (options.ci) {
18
- /**
19
- * Don't try to authenticate the user.
20
- * This is done when CLI is running within an automated system like pipeline,
21
- * In this case "AWS_ACCESS_KEY_ID" and "AWS_SECRET_ACCESS_KEY" are used instead of "AWS_PROFILE".
22
- */
23
- return
24
- }
25
-
26
- try {
27
- checkIdentity(options)
28
- } catch (error) {
29
- login(options)
30
- }
31
- }
32
-
33
- ///////////////////////////////////////////////////////////////////////////////
34
-
35
- export const assertProfilesPresent = () => {
36
- const profiles = getAvailableProfiles()
37
-
38
- if (profiles.length === 0) {
39
- halt(
40
- stripIndent(`
41
- No AWS profiles found.
42
- Run "aws configure sso" to set up SSO-enabled profile.
43
- Check the wiki for more information:
44
- https://raisenow.atlassian.net/wiki/x/lIrWvg
45
- `),
46
- )
47
- }
48
- }
49
-
50
- ///////////////////////////////////////////////////////////////////////////////
51
-
52
- export const getAvailableProfiles = (): string[] => {
53
- const {stdout} = execaCommandSync('aws configure list-profiles')
54
-
55
- return stdout.split('\n')
56
- }
57
-
58
- ///////////////////////////////////////////////////////////////////////////////
59
-
60
- /**
61
- * Returns caller identity data (output is ignored here).
62
- * Fails in case of expired SSO session.
63
- */
64
- const checkIdentity = (options: AwsOptions) => {
65
- const flags = prepareFlags(options)
66
-
67
- execaCommandSync(`aws sts get-caller-identity ${flags}`)
68
- }
69
-
70
- ///////////////////////////////////////////////////////////////////////////////
71
-
72
- /**
73
- * Opens SSO authentication page in the browser.
74
- * Fails if user canceled authentication process.
75
- */
76
- const login = (options: AwsOptions) => {
77
- const flags = prepareFlags(options)
78
-
79
- try {
80
- execaCommandSync(`aws sso login ${flags}`, {stdio: 'inherit'})
81
- // eslint-disable-next-line no-console
82
- console.log('')
83
- } catch (error) {
84
- halt('Login failed.')
85
- }
86
- }
87
-
88
- ///////////////////////////////////////////////////////////////////////////////
89
-
90
- export const prepareFlags = (options: AwsOptions) => {
91
- const flags: string[] = []
92
- const {profile} = options
93
-
94
- if (profile) {
95
- flags.push(`--profile ${profile}`)
96
- }
97
-
98
- return flags.join(' ')
99
- }
100
-
101
- ///////////////////////////////////////////////////////////////////////////////
102
-
103
- export const assertProfileValid = (profile: string) => {
104
- const profiles = getAvailableProfiles()
105
-
106
- if (!profiles.includes(profile)) {
107
- halt(
108
- stripIndent(`
109
- AWS profile "${profile}" is not found.
110
- Available profiles are: ${profiles.map((v) => `"${v}"`).join(', ')}.
111
- `),
112
- )
113
- }
114
- }
115
-
116
- ///////////////////////////////////////////////////////////////////////////////
117
-
118
- export const promptProfile = async (): Promise<string | undefined> => {
119
- const profiles = getAvailableProfiles()
120
- .filter((v) => !!v)
121
- .map((v) => ({title: v, value: v}))
122
-
123
- const {profile} = await prompts(
124
- [
125
- {
126
- type: 'select',
127
- name: 'profile',
128
- message: 'Select AWS profile',
129
- choices: profiles,
130
- },
131
- ],
132
- {
133
- onCancel: () => halt(),
134
- },
135
- )
136
-
137
- return profile
138
- }
@@ -1,27 +0,0 @@
1
- import {execaCommandSync, type SyncOptions, type SyncResult} from 'execa'
2
- import {logError} from 'lib/logging'
3
-
4
- ///////////////////////////////////////////////////////////////////////////////
5
-
6
- export const halt = (message?: string) => {
7
- logError(message)
8
- process.exit(1)
9
- }
10
-
11
- ///////////////////////////////////////////////////////////////////////////////
12
-
13
- export const prepareCommand = (cmd: string): string => {
14
- return cmd
15
- .replace(/\n/gm, ' ')
16
- .replace(/[ \t]{2,}/gm, ' ')
17
- .trim()
18
- }
19
-
20
- ///////////////////////////////////////////////////////////////////////////////
21
-
22
- export const runCommandSync = (
23
- cmd: string,
24
- options?: SyncOptions,
25
- ): SyncResult => {
26
- return execaCommandSync(prepareCommand(cmd), options)
27
- }
@@ -1,9 +0,0 @@
1
- export const DEFAULT_TAG = 'latest'
2
- export const DEFAULT_PORT = 1234
3
- export const AWS_S3_BUCKET_TAMARO = 'tamaro.raisenow.com'
4
- export const AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE = 'rnw-stage-email-service'
5
- export const AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD = 'rnw-email-service'
6
- export const CORE_CONFIG_NAME = 'tamaro-core'
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 DELETED
@@ -1,175 +0,0 @@
1
- import {createRequire} from 'module'
2
- import {basename} from 'path'
3
- import {config as dotenvConfig} from 'dotenv'
4
- import {globSync} from 'glob'
5
- import stripIndent from 'strip-indent'
6
- import type {IfUtilsFn} from 'webpack-config-utils'
7
- import {halt} from 'lib/command'
8
- import {getIfCoreFns, getPaths, getWidgetUuid, resolveApp} from 'lib/resolve'
9
-
10
- ///////////////////////////////////////////////////////////////////////////////
11
-
12
- export type EnvVars = Record<string, string | undefined>
13
-
14
- ///////////////////////////////////////////////////////////////////////////////
15
-
16
- const require = createRequire(import.meta.url)
17
-
18
- ///////////////////////////////////////////////////////////////////////////////
19
-
20
- export const getEnvVars = (
21
- files: string[],
22
- ifMin: IfUtilsFn,
23
- ifCore: IfUtilsFn,
24
- ifLocalCore: IfUtilsFn,
25
- ifHttps: IfUtilsFn,
26
- ) => {
27
- const filePath = files.find((file) => basename(file) === '.env')
28
-
29
- if (filePath) {
30
- dotenvConfig({path: filePath})
31
- }
32
-
33
- process.env.NODE_ENV ??= ifMin('production', 'development')
34
- process.env.BABEL_ENV ??= ifMin('production', 'development')
35
- process.env.EXPOSE_VAR ??= ifCore('rnw.tamaroCore', 'rnw.tamaro')
36
- process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET ??= ifCore(
37
- 'rnw-tamaro-core',
38
- 'rnw-tamaro',
39
- )
40
- process.env.WEBPACK_UNIQUE_NAME ??= ifCore('RnwTamaroCore', 'RnwTamaro')
41
- process.env.BUILD_DATE = new Date().toISOString()
42
- process.env.PUBLIC_URL ??= ''
43
- process.env.HMR_ENABLED ??= ifMin('false', 'true')
44
-
45
- if (ifCore()) {
46
- process.env.PRODUCT_NAME = 'tamaro'
47
-
48
- const corePkgPath = resolveApp('package.json')
49
- // eslint-disable-next-line @typescript-eslint/no-var-requires
50
- const {version} = require(corePkgPath)
51
-
52
- process.env.PRODUCT_VERSION = version
53
- }
54
-
55
- if (!ifCore()) {
56
- process.env.WIDGET_UUID = getWidgetUuid()
57
-
58
- if (ifLocalCore()) {
59
- const protocol = ifHttps() ? 'https' : 'http'
60
- process.env.CORE_URL = `${protocol}://localhost:1234/index.js`
61
- } else {
62
- let version = process.env.CORE_VERSION
63
- version = version ? `@${version}` : ''
64
-
65
- process.env.CORE_URL ??= `https://cdn.jsdelivr.net/npm/@raisenow/tamaro-core${version}/dist/index.js`
66
- // process.env.CORE_URL ??= `https://fastly.jsdelivr.net/npm/@raisenow/tamaro-core${version}/dist/index.js`
67
- }
68
- }
69
-
70
- // var names which will be exposed along with "PUBLIC_*" var names
71
- const varNames = [
72
- // common
73
- 'NODE_ENV',
74
- 'BABEL_ENV',
75
- 'EXPOSE_VAR',
76
- 'ELEMENT_ATTRIBUTE_DATA_WIDGET',
77
- 'WEBPACK_UNIQUE_NAME',
78
- 'BUILD_DATE',
79
- 'PUBLIC_URL',
80
-
81
- // core
82
- 'PRODUCT_NAME',
83
- 'PRODUCT_VERSION',
84
-
85
- // config
86
- 'WIDGET_UUID',
87
- 'CORE_URL',
88
- 'CORE_VERSION', // should be explicitly specified in each config
89
-
90
- // epik (obsolete since Tamaro v2.5.0)
91
- 'EPP_API_KEY_DEFAULT',
92
- 'EPP_API_URL_STAGE',
93
- 'EPP_API_URL_PROD',
94
- 'EPMS_API_URL_STAGE',
95
- 'EPMS_API_URL_PROD',
96
- 'EPP_PROXY_URL_STAGE',
97
- 'EPP_PROXY_URL_PROD',
98
- 'EPMS_PROXY_URL_STAGE',
99
- 'EPMS_PROXY_URL_PROD',
100
- 'EPMS_TWINT_CHECKOUT_URL_STAGE',
101
- 'EPMS_TWINT_CHECKOUT_URL_PROD',
102
- ]
103
-
104
- // Collect all vars which names start from "PUBLIC_" or present in "varNames" array
105
- const raw = Object.keys(process.env)
106
- .filter((key) => key.startsWith('PUBLIC_') || varNames.includes(key))
107
- .reduce<EnvVars>((env, key) => {
108
- env[key] = process.env[key]
109
-
110
- return env
111
- }, {})
112
-
113
- // Stringify all values so we can feed into webpack DefinePlugin
114
- const stringified = {
115
- 'process.env': Object.keys(raw).reduce<EnvVars>((env, key) => {
116
- env[key] = JSON.stringify(raw[key])
117
-
118
- return env
119
- }, {}),
120
- }
121
-
122
- return {raw, stringified}
123
- }
124
-
125
- ///////////////////////////////////////////////////////////////////////////////
126
-
127
- export const assertEnvValid = (env?: string) => {
128
- const {ifCore} = getIfCoreFns()
129
- const paths = getPaths(ifCore)
130
- const files = globSync(paths.appEnv)
131
- const envs = files
132
- .map((file) => basename(file).replace(/^\.env\./, ''))
133
- .map((file) => basename(file).replace(/^\.env$/, ''))
134
- .filter((v) => !!v)
135
-
136
- if (envs.length === 0) {
137
- if (env) {
138
- // There are no ".env.<env>" files, so we must ignore "--env" flag
139
- // eslint-disable-next-line no-console
140
- console.log('Flag "--env" is ignored.')
141
- }
142
- }
143
-
144
- if (envs.length !== 0) {
145
- if (!env) {
146
- // There are some ".env.<env>" files, but no "--env" flag is specified, so we must require it
147
- halt('Flag "--env" is required.')
148
- }
149
-
150
- if (env && !envs.includes(env)) {
151
- // There are some ".env.<env>" files, but specified "--env" flag is incorrect
152
- halt(
153
- stripIndent(`
154
- Flag "--env" has wrong value.
155
- Available values are: ${envs.map((v) => `"${v}"`).join(', ')}.
156
- `),
157
- )
158
- }
159
- }
160
- }
161
-
162
- export const applyEnv = (env?: string) => {
163
- if (!env) {
164
- return
165
- }
166
-
167
- const {ifCore} = getIfCoreFns()
168
- const paths = getPaths(ifCore)
169
- const files = globSync(paths.appEnv)
170
- const filePath = files.find((file) => basename(file) === `.env.${env}`)
171
-
172
- if (filePath) {
173
- dotenvConfig({path: filePath})
174
- }
175
- }
package/src/lib/https.ts DELETED
@@ -1,27 +0,0 @@
1
- import {existsSync} from 'fs'
2
- import {resolve} from 'path'
3
- import stripIndent from 'strip-indent'
4
- import {halt} from 'lib/command'
5
- import {HTTPS_CRT_FILE, HTTPS_KEY_FILE} from 'lib/constants'
6
- import {getIfCoreFns, getPaths} from 'lib/resolve'
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
- }
@@ -1,37 +0,0 @@
1
- import chalk from 'chalk'
2
- import columnify from 'columnify'
3
- import stripIndent from 'strip-indent'
4
-
5
- ///////////////////////////////////////////////////////////////////////////////
6
-
7
- export const logTitle = (title: string) => {
8
- // eslint-disable-next-line no-console
9
- console.log(chalk.bold(title))
10
- }
11
-
12
- ///////////////////////////////////////////////////////////////////////////////
13
-
14
- export const logError = (message?: string) => {
15
- if (message) {
16
- // eslint-disable-next-line no-console
17
- console.log(chalk.red(message))
18
- }
19
- }
20
-
21
- ///////////////////////////////////////////////////////////////////////////////
22
-
23
- export const logCommand = (cmd: string): void => {
24
- // eslint-disable-next-line no-console
25
- console.log(`\n${chalk.dim(stripIndent(cmd).trim())}\n`)
26
- }
27
-
28
- ///////////////////////////////////////////////////////////////////////////////
29
-
30
- export const logDataTable = (
31
- data: Record<string, string | undefined>,
32
- ): void => {
33
- // eslint-disable-next-line no-console
34
- console.log(columnify(data, {showHeaders: false}))
35
- // eslint-disable-next-line no-console
36
- console.log('')
37
- }
@@ -1,22 +0,0 @@
1
- import notifier from 'node-notifier'
2
- import stripIndent from 'strip-indent'
3
-
4
- ///////////////////////////////////////////////////////////////////////////////
5
-
6
- export type NotifyArgs = {
7
- title: string
8
- message: string
9
- }
10
-
11
- ///////////////////////////////////////////////////////////////////////////////
12
-
13
- export const notify = (args: NotifyArgs) => {
14
- const {title, message = ''} = args
15
-
16
- notifier.notify({
17
- title,
18
- message: stripIndent(message).trim(),
19
- contentImage: 'https://assets.raisenow.io/favicon.png',
20
- sound: 'Funk',
21
- })
22
- }
@@ -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
- }