This repository has been archived by the owner on Sep 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgulpfile.js
121 lines (106 loc) · 3.23 KB
/
gulpfile.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
var gulp = require('gulp');
var gulpSequence = require('gulp-sequence');
var prompt = require('prompt');
var fse = require('fs-extra');
var mustache = require('mustache');
gulp.task('start', gulpSequence('condition', 'deploy'));
gulp.task('condition', function (cb) {
mustache.tags = ['<%', '%>'];
var condition = [];
condition.push({
name: 'hasdatastore',
description: 'Do you have cloud datastore instance? Enter - true/false',
type: 'boolean',
required: true
});
prompt.get(condition, function (err, results) {
if (results['hasdatastore']) {
var required_values = [];
required_values.push({
name: 'serviceaccount_project',
description: 'Enter the cloud datastore project id',
type: 'string',
required: true
});
required_values.push({
name: 'serviceaccount_private_key',
description: 'Enter the service account private key',
type: 'string',
required: true
});
required_values.push({
name: 'serviceaccount_token_uri',
description: 'Enter the token uri of the service account',
type: 'string',
required: true
});
required_values.push({
name: 'serviceaccount_client_email',
description: 'Enter the client email of the service account',
type: 'string',
required: true
});
prompt.start();
prompt.get(required_values, function (err, results) {
//
results["datastore_basepath"] = "";
updateConfig(results, cb);
})
//
}
else {
var required_values = [];
required_values["serviceaccount_project"] = "replace_with_datastore_project_id";
required_values["serviceaccount_private_key"] = "replace_with_datastore_service_account_private_key";
required_values["serviceaccount_token_uri"] = "http://replace_with_datastore_service_account_token_uri";
required_values["serviceaccount_client_email"] = "replace_with_datastore_service_account_email";
required_values["datastore_basepath"] = "/connector/fhirsandbox";//fhir sandbox org
updateConfig(required_values, cb);
}
})
});
function updateConfig(required_values, cb) {
fse.copy('config.yml.orig', 'config.yml', function (error) {
if (error) {
cb(error);
}
else {
replace_variables(['config.yml'], required_values, function (error, res) {
mustache.tags = ['{{', '}}'];
require('edge-launchpad')(gulp);
cb(error, res)
});
}
})
}
function replace_variables(paths, inject_object, cb) {
mustache.escape = function (value) {
return value;
};
for (var i = 0; i < paths.length; i++) {
var path_to_template = paths[i];
var data;
try {
data = fse.readFileSync(path_to_template, 'utf8')
} catch (e) {
console.log(e);
cb(e);
}
var mu_template = String(data);
try {
var output = mustache.render(mu_template, inject_object)
} catch (e) {
console.log(e);
cb(e);
}
try {
fse.outputFileSync(path_to_template.split('.').slice(0, 2).join('.'),
output)
} catch (e) {
console.log(e);
cb(e);
}
output = '< yet to copy from original template >';
}
cb(null, inject_object);
}