-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathproductionCreation.js
126 lines (118 loc) · 4.84 KB
/
productionCreation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* eslint-disable no-console */
const fs = require('fs/promises');
const fsStd = require('fs');
const { execSync } = require('child_process');
const ANNOT_URL = 'annotations.bgee.org';
const DEV_URL = 'http://dbbgee.unil.ch';
const main = async () => {
try {
let config = await fs.readFile('./src/config.json', 'utf8');
config = JSON.parse(config);
if (config.isRawDataOnly && config.isDevOnly) {
console.log('Try to build RawData and Dev at the same time!');
return;
}
const originalGenericDomain = config.genericDomain;
const originalPermanentVersionedDomain = config.permanentVersionedDomain;
const originalApiDomain = config.apiDomain;
const originalFtpDomain = config.ftpDomain;
if (config.isRawDataOnly) {
/* Change root URLs */
config.genericDomain = config.genericDomain.replace('www.bgee.org', `${ANNOT_URL}`);
config.permanentVersionedDomain = config.permanentVersionedDomain.replace('www.bgee.org', `${ANNOT_URL}`);
config.apiDomain = config.apiDomain.replace('www.bgee.org', `${ANNOT_URL}`);
config.ftpDomain = config.ftpDomain.replace('www.bgee.org', `${ANNOT_URL}`);
/* Change API URL */
const API_VERSION = config.version;
const API_DOMAIN = API_VERSION.replaceAll('.', '-');
config.apiDomain = config.apiDomain.replace('/api', `/api-${API_DOMAIN}`);
/* Write modified config.json */
await fs.writeFile('./src/config.json', JSON.stringify(config, null, 2));
console.log('Setting config as annotations');
}
if (config.isDevOnly) {
/* Change root URLs */
config.genericDomain = config.genericDomain.replace('https://www.bgee.org', `${DEV_URL}`);
config.permanentVersionedDomain = config.permanentVersionedDomain.replace('https://www.bgee.org', `${DEV_URL}`);
config.apiDomain = config.apiDomain.replace('https://www.bgee.org', `${DEV_URL}`);
config.ftpDomain = config.ftpDomain.replace('https://www.bgee.org', `${DEV_URL}`);
/* Write modified config.json */
await fs.writeFile('./src/config.json', JSON.stringify(config, null, 2));
console.log('Setting config as dev/test');
}
const scss = await fs.readFile('./src/styles/global.scss', 'utf8');
const html = await fs.readFile('./public/index.html', 'utf8');
const noIndexSource = await fs.readFile(
'./archives/resources/htmlHead.txt',
'utf8'
);
let pkg = await fs.readFile('./package.json', 'utf8');
pkg = JSON.parse(pkg);
console.log('Checking production attributes\n');
let prod = true;
if (config.archive) {
prod = false;
console.log(
'\x1b[31m[ERROR] %s\x1b[0m',
'config.json is set as an archive'
);
}
if (scss.indexOf('$archive: false;') === -1) {
prod = false;
console.log(
'\x1b[31m[ERROR] %s\x1b[0m',
'styles.scss is set as an archive'
);
}
if (html.indexOf(noIndexSource) !== -1) {
prod = false;
console.log(
'\x1b[31m[ERROR] %s\x1b[0m',
'noindex meta tag are put in public/index.html'
);
}
if (pkg.homepage) {
prod = false;
console.log(
'\x1b[31m[ERROR] %s\x1b[0m',
'Unwanted "homepage" key is defined in package.json'
);
}
if (!prod) {
console.log('Problem with prod environement : Canceling build');
return;
}
const paths = await fs.readFile('./src/routes/paths.js', 'utf8');
if (config.isRawDataOnly) {
console.log('\x1b[31m%s\x1b[0m', 'Annotation/Raw data interface settings');
/* Change the default homepage for the Annotation/Raw data interface */
const pathsTmp = paths.replace('HOME: `${URL_ROOT}/`', 'HOME: `${URL_ROOT}/search/raw-data`');
await fs.writeFile('./src/routes/paths.js', pathsTmp);
}
console.log('\x1b[31m%s\x1b[0m', 'Building app');
execSync('yarn build:cra', { stdio: 'inherit' });
if (config.isRawDataOnly) {
/* Back to default */
await fs.writeFile('./src/routes/paths.js', paths);
config.genericDomain = originalGenericDomain;
config.permanentVersionedDomain = originalPermanentVersionedDomain;
config.apiDomain = originalApiDomain;
config.ftpDomain = originalFtpDomain;
await fs.writeFile('./src/config.json', JSON.stringify(config, null, 2));
}
if (config.isDevOnly) {
/* Back to default */
config.genericDomain = originalGenericDomain;
config.permanentVersionedDomain = originalPermanentVersionedDomain;
config.apiDomain = originalApiDomain;
config.ftpDomain = originalFtpDomain;
await fs.writeFile('./src/config.json', JSON.stringify(config, null, 2));
}
console.log('\x1b[31m%s\x1b[0m\n', 'App built successfully');
} catch (err) {
console.log('\x1b[31m%s\x1b[0m', 'CATCH ! Error occured when building');
console.log('\x1b[31m%s\x1b[0m', err);
process.exit(1);
}
};
main();