-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.js
58 lines (50 loc) · 2.44 KB
/
setup.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
var fetchControlledTerms = require('./server/kg-util/fetchControlledTerms');
var fetchCoreSchemaInstances = require('./server/kg-util/fetchCoreSchemaInstances'); // Todo?
const {exec} = require('child_process');
if (process.env.NODE_ENV === 'docker-build') {
console.log ('Skipping setup for docker build process.')
} else {
setup();
}
async function setup() {
// Fetch controlled terms from KG
// This is done before the React App is built so that the controlled terms are available
var startTime = performance.now()
configObject = {
openMindsType: "Person",
instanceProperties: ["familyName", "givenName"]
}
console.log('Fetching openMINDS instances...')
fetchCoreSchemaInstances(configObject)
.then( () => {
console.log('Fetching controlled terms...')
fetchControlledTerms()
.then( () => {
var endTime = performance.now()
console.log(`Fetched all instance and controlled terms in: ${(endTime - startTime)/1000} seconds`)
// Make this import here, because the controlled term files are needed before the module can be properly imported
var assembleRJSFSchemas = require('./server/internal/formSchemaAssembler');
assembleRJSFSchemas()
.then( () => {
console.log('Assembled form schemas from templates and controlled terms.')
// Redo the build in order for the updated terms to be used by the frontend
console.log('Creating a production build for the React App...')
exec('npm run build', (err) => {
if (err) {
console.error(`exec error: ${err}`);
} else {
console.log(`Completed React App build in: ${(performance.now() - endTime)/1000} seconds`);
}
//console.log(`Completed React App build in: ${(performance.now() - endTime)/1000} seconds`);
});
})
})
.catch(err => {
console.log('Error fetching controlled terms: ' + err);
})
})
.catch(err => {
console.log('Error fetching openMINDS instances: ' + err);
}
)
}