forked from BgeeDB/bgee-unil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductionCreation.js
66 lines (58 loc) · 1.67 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
/* eslint-disable no-console */
const fs = require('fs/promises');
const fsStd = require('fs');
const { execSync } = require('child_process');
const main = async () => {
try {
let config = await fs.readFile('./src/config.json', 'utf8');
config = JSON.parse(config);
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('');
return;
}
console.log('\x1b[31m%s\x1b[0m', 'Building app');
execSync('yarn build:cra', { stdio: 'inherit' });
console.log('\x1b[31m%s\x1b[0m\n', 'App built successfully');
} catch (err) {
console.log('\x1b[31m%s\x1b[0m', err);
}
};
main();