-
Notifications
You must be signed in to change notification settings - Fork 42
/
setup.js
70 lines (62 loc) · 2.12 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
59
60
61
62
63
64
65
66
67
68
69
70
//azure config mode arm
var uuid = require('node-uuid');
var fs = require('fs');
var spawn = require('child_process').spawn;
var uuidrg = uuid.v4().toLowerCase().replace(/-/g, '');
var resourceGroup = "rg" + uuidrg.substring(0,19);
var storageAccountName = "sa" + uuidrg.substring(0,19);
var location = "westus";
var errorHasOccurred = false;
var connectionData = "";
var wasInArmMode = false;
executeAzureCLI(['config', 'list'], function() {
executeAzureCLI(['config', 'mode', 'arm'], function() {
executeAzureCLI(['group', 'create', resourceGroup, location], function() {
executeAzureCLI(['storage', 'account', 'create', storageAccountName, '-g', resourceGroup, '--type', 'RAGRS', '-l', location], function(code) {
executeAzureCLI(['storage', 'account', 'connectionstring', 'show', '--json', storageAccountName, '-g', resourceGroup], function(code) {
try {
var connectionString = JSON.parse(connectionData).string;
var stream = fs.createWriteStream("resources/config.properties");
stream.once('open', function(fd) {
stream.write('#{"uuid":"' + uuidrg + '"}\n');
stream.write('#StorageConnectionString = UseDevelopmentStorage=true\n');
stream.write('StorageConnectionString = ' + connectionString + '\n');
stream.end();
});
}catch(ex) {
}
if(!wasInArmMode) {
executeAzureCLI(['config', 'mode', 'asm']);
}
},
function(data) {
connectionData += data;
});
});
});
});
}, function(data) {
wasInArmMode = data.match(/mode\s*arm/) != null
});
function executeAzureCLI(params, closeCallback, stdOutCallback) {
var prc = spawn('azure', params);
prc.stderr.on('data', (data) => {
errorHasOccurred = true;
if(!wasInArmMode && ("config mode asm" != params.join(' '))) {
executeAzureCLI(['config', 'mode', 'asm']);
}
process.stdout.write(`stderr: ${data}`);
});
prc.stdout.on('data', (data) => {
var outData = `${data}`;
process.stdout.write(outData);
if(stdOutCallback) {
stdOutCallback(outData);
}
});
prc.on('close', (code) => {
if(!errorHasOccurred && closeCallback) {
closeCallback(code);
}
});
}