1 const path
= require('path');
2 const dedent
= require('dedent');
3 const execa
= require('execa');
5 const readJSON
= (file
) => {
6 const fileName
= `${file}.json`;
8 return require(path
.join(process
.cwd(), fileName
));
14 const getGitBranch
= () => {
16 const { stdout
= '' } = execa
.sync('git describe --all', { shell
: true });
23 const getGitCommitHash
= () => {
25 const { stdout
= '' } = execa
.sync('git rev-parse HEAD', { shell
: true });
32 const getGitTagVersion
= (applicationName
) => {
34 const { stdout
= '' } = execa
.sync(`git describe --abbrev=0 --match=${applicationName}*`, { shell
: true });
42 * Clean ex. proton-mail@4.x.x to 4.x.x
44 const getVersionNumberFromTag
= (tag
) => {
45 return tag
.replace(/[^@]*@/g, '');
48 const APP_CONFIG_JSON
= readJSON('appConfig') || {};
50 const LOCALES
= (() => {
52 return require(path
.join(process
.cwd(), 'locales', 'config', 'locales.json'));
58 const ENV_CONFIG
= Object
.keys(APP_CONFIG_JSON
).reduce(
60 if (key
=== 'appConfig') {
61 acc
.app
= APP_CONFIG_JSON
[key
];
64 const { api
, secure
} = APP_CONFIG_JSON
[key
];
69 acc
.secure
[key
] = secure
;
73 { api
: {}, secure
: {}, app
: {} }
77 prod
: 'https://mail.proton.me',
78 localhost
: 'https://localhost',
83 const getApi
= (value
) => {
84 // We can do --api=https://mail.proton.me/api and it's only for dev, so we can stop here
85 if (value
.startsWith('http') || value
.startsWith('/api')) {
88 return API_TARGETS
[value
] || API_TARGETS
.prod
;
91 const getConfigData
= ({ api
, sso
, apiProxy
, publicPath
, version
}) => {
92 const pkg
= require(path
.join(process
.cwd(), 'package.json'));
93 const appName
= pkg
.name
;
95 throw new Error('Missing app name');
98 const isProduction
= process
.env
.NODE_ENV
=== 'production';
103 version
|| getVersionNumberFromTag(process
.env
.CI_COMMIT_TAG
|| getGitTagVersion(appName
)) || '5.0.999.999',
108 sentryDsn
: isProduction
? ENV_CONFIG
.app
.sentry
|| '' : '',
109 sentryDesktopDsn
: isProduction
? ENV_CONFIG
.app
.sentryDesktop
|| '' : '',
114 version
: appData
.version
,
115 commit
: process
.env
.CI_COMMIT_SHA
|| getGitCommitHash(),
116 branch
: process
.env
.CI_COMMIT_REF_NAME
|| getGitBranch(),
117 date
: new Date().toGMTString(),
126 const getConfigFile
= ({ buildData
, appData
}) => {
128 export const CLIENT_TYPE = ${ENV_CONFIG.app.clientType || 1};
129 export const CLIENT_SECRET = '${ENV_CONFIG.app.clientSecret || ''}';
130 export const APP_VERSION = '${buildData.version}';
131 export const COMMIT = '${buildData.commit}';
132 export const BRANCH = '${buildData.branch}';
133 export const DATE_VERSION = '${buildData.date}';
134 export const APP_NAME = '${appData.appName}';
135 export const API_URL = '${(!appData.apiProxy && appData.api) || '/api'}';
136 export const SSO_URL = '${appData.sso || ''}';
137 export const LOCALES = ${JSON.stringify(LOCALES)};
138 export const VERSION_PATH = '${appData.publicPath}assets/version.json';
139 export const SENTRY_DSN = '${appData.sentryDsn}';
140 export const SENTRY_DESKTOP_DSN = '${appData?.sentryDesktopDsn ?? ''}';