forked from criticalmanufacturing/dev-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.js
25 lines (23 loc) · 1.25 KB
/
context.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
var path = require("path");
var fs = require('fs');
module.exports = {
/**
* Will set the repo folder name acording to the running environment
*
* @param repoFolderProperty {string} Name of the symbol that will represent the repo folder name
* @param repoFolderName {string} Name of repo
*/
updateContext: function(repoFolderProperty, repoFolderName) {
/** Update context.json with the current repository folder name. This can vary in the build agent, so we alwys depend on what we get. The context.json will hold all the folder names
that will be used by the install and build. This seems a clean enough way that will work in any use case **/
if (typeof repoFolderProperty === "string" && typeof repoFolderName === "string") {
process.chdir(__dirname);
var contextVariables = JSON.parse(fs.readFileSync('./context.json', 'utf8'));
// We should receive which repository to configure as a parameter
if (contextVariables != null) {
contextVariables[repoFolderProperty] = repoFolderName;
fs.writeFileSync('./context.json', JSON.stringify(contextVariables), 'utf8');
}
}
}
};