-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-env.ts
118 lines (110 loc) · 3.14 KB
/
prepare-env.ts
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
/*generate auth0-conf.json*/
import fs from "fs"
import https from "https"
import packageJsonLock from "./package-lock.json" assert {type:"json"}
import {LineCount} from "@sctg/code-stats"
const results = await LineCount.countLines(['src','api/add-short-url','api/autoroute','api/common','api/list-short-url','api/redirect'])
fs.writeFile(
"./src/config/codeStats.json",
JSON.stringify(results),
"utf8",
function (err) {
if (err) return console.log(err);
}
);
const auth0Conf = {
"domain": process.env.AUTH0_DOMAIN,
"clientId": process.env.AUTH0_CLIENT_ID,
"useRefreshTokens": true,
"cacheLocation": "localstorage",
"authorizationParams": {
"scope": 'openid email profile user_metadata app_metadata picture',
"audience": "https://kiik.api"
}
};
fs.writeFile('./src/config/auth0-conf.json',
JSON.stringify(auth0Conf),
'utf8', function (err) {
if (err) return console.log(err);
}
);
export interface Auth0JWKS {
alg: string;
kty: string;
use: string;
n: string;
e: string;
kid: string;
x5t: string;
x5c: string[];
domain: string;
namespace: string;
}
async function getJwks() {
console.log(
`retrieve https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
);
const url = `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`;
return new Promise<Auth0JWKS>((resolve, reject) => {
https
.get(url, (res) => {
let data = "" as string;
res.on("data", (chunk) => {
data += chunk;
});
res.on("end", () => {
const structuredData = JSON.parse(data) as Auth0JWKS;
structuredData.domain = process.env.AUTH0_DOMAIN || '';
structuredData.namespace = process.env.AUTH0_CUSTOM_NAMESPACE || '';
resolve(structuredData);
});
})
.on("error", (err) => {
console.log(err.message);
reject(err);
});
});
}
(async () => {
const jwks = await getJwks();
fs.writeFile(
"./src/config/jwks.json",
JSON.stringify(jwks),
"utf8",
function (err) {
if (err) return console.log(err);
}
);
})();
(async () => {
const jwks = await getJwks();
fs.writeFile(
"./api/common/config/jwks.json",
JSON.stringify(jwks),
"utf8",
function (err) {
if (err) return console.log(err);
}
);
})();
/*generate versions.json*/
const versions = {
cosmosDBSdkVersion: packageJsonLock.dependencies["@azure/cosmos"].version,
auth0SdkVersion: packageJsonLock.dependencies["@auth0/auth0-spa-js"].version,
viteVersion: packageJsonLock.dependencies.vite.version,
vueVersion: packageJsonLock.dependencies.vue.version,
};
fs.writeFile(
"./src/config/versions.json",
JSON.stringify(versions),
"utf8",
function (err) {
if (err) return console.log(err);
}
);
//Install necessary flags
import {availableLanguages} from './src/config/locales.js'
availableLanguages.forEach((lang)=>{
const baseFile = lang.substring(3).toLowerCase()
fs.copyFileSync(`./flags/${baseFile}.svg`,`./src/assets/lang/${baseFile}.svg`)
})