-
Notifications
You must be signed in to change notification settings - Fork 42
/
teardown.js
70 lines (62 loc) · 2.54 KB
/
teardown.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
var fs = require("fs");
var spawn = require('child_process').spawn;
var wasInArmMode = false;
readUUIDFromConfigFile();
var errorHasOccurred = false;
var connectionData = "";
var wasInArmMode = false;
function readUUIDFromConfigFile() {
fs.readFile('resources/config.properties', (err, data) => {
if (err) throw err;
var fileData = `${data}`;
var firstLineIndex = fileData.indexOf("\n");
if(firstLineIndex > 0) {
var uuidrg = JSON.parse(fileData.substring(1, firstLineIndex + 1)).uuid;
executeAzureCLI(['config', 'list'], function() {
executeAzureCLI(['config', 'mode', 'arm'], function() {
var resourceGroup = "rg" + uuidrg.substring(0,19);
executeAzureCLI(['group', 'delete', '-q', resourceGroup], function() {
var stream = fs.createWriteStream("resources/config.properties");
stream.once('open', function(fd) {
stream.write('#By default we are assuming you will use the Azure Storage Emulator. If you have an Azure Subscription, you can alternatively\n');
stream.write('#create a Storage Account and run against the storage service by commenting out the connection string below and using the\n');
stream.write('#second connection string - in which case you must also insert your storage account name and key in the line below.\n\n');
stream.write('StorageConnectionString = UseDevelopmentStorage=true\n');
stream.write('#StorageConnectionString = DefaultEndpointsProtocol=https;AccountName=[AccountName];AccountKey=[AccountKey]\n');
stream.end();
});
if(!wasInArmMode) {
executeAzureCLI(['config', 'mode', 'asm']);
}
});
});
}, function(data) {
wasInArmMode = data.match(/mode\s*arm/) != null
});
}else {
console.log('unable to teardown');
}
});
}
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);
}
});
}