-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
68 lines (54 loc) · 2.13 KB
/
index.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
const { readFile, readdir, writeFile, writeFileSync, mkdirSync, existsSync, readFileSync } = require('fs');
const util = require('util');
const readFileAsync = util.promisify(readFile);
const writeFileAsync = util.promisify(writeFile)
const readDirAsync = util.promisify(readdir);
const process = require('process');
const { BlobServiceClient } = require("@azure/storage-blob");
let environments = {
"DEVELOPMENT": "dev",
"PRODUCTION": "prod"
}
const webContainerClient = (
BlobServiceClient
.fromConnectionString(process.env.CONNECTION_STRING)
.getContainerClient('aditya-test')
);
const url = webContainerClient.url;
webContainerClient.createIfNotExists()
.catch(err => console.error(err));
function upload(localPath, blobPath) {
const blobClient = webContainerClient.getBlockBlobClient(blobPath);
return blobClient.uploadFile(localPath, {
blobHTTPHeaders: {
blobContentType: 'application/octet-stream',
blobCacheControl: 'no-cache', // Disable caching since we want changes to be immediately visible in WebXR.
}
});
}
async function getApplicationsList(env){
let dirPath = `${env}/apps`;
let filesList = await readDirAsync(dirPath);
let appsList = [];
if(filesList.length === 0) return [];
filesList.forEach(async item => {
let app = readFileSync(`${dirPath}/${item}`, "utf8");
app = JSON.parse(app);
appsList.push(app);
})
return appsList;
}
const main = async (env) => {
let shellFile = await readFileAsync(`dev/config.json`, "utf8");
shellFile = JSON.parse(shellFile);
if(!existsSync("./config"))
mkdirSync(`${process.cwd()}/config`)
let applications = await getApplicationsList(env);
shellFile.applications = applications;
let fileContents = `export let config = ${JSON.stringify(shellFile, null , 2)}`;
writeFileSync("./config/config.js", fileContents);
// let status = await upload(`${process.cwd()}/config/config.js`, `config.js`)
}
let environment = process.env.environment ? process.env.environment : "dev";
console.log(environment);
main(environments[environment]);