refs #4823 Added checkConfig function
This commit is contained in:
parent
1a97f16a11
commit
17533d873f
|
@ -28,7 +28,7 @@ npm i
|
|||
### .env file template
|
||||
|
||||
```bash
|
||||
#FLORIDAY DATA
|
||||
#FLORIDAY DATA CONFIG
|
||||
CLIENT_ID = xxxxxxxxxx
|
||||
CLIENT_SECRET = xxxxxxxxxx
|
||||
API_KEY = xxxxxxxxxx
|
||||
|
|
|
@ -9,8 +9,8 @@ const env = process.env;
|
|||
class Floriday {
|
||||
async start() {
|
||||
try {
|
||||
await utils.checkConfig();
|
||||
this.tokenExpirationDate = await utils.requestToken(models);
|
||||
if (!env.API_KEY) throw new Error(`You haven't provided the API key`)
|
||||
if (JSON.parse(env.SYNC_SEQUENCE)) await utils.syncSequence();
|
||||
if (JSON.parse(env.SYNC_SUPPLIER)) await utils.syncSuppliers();
|
||||
if (JSON.parse(env.SYNC_CONN)) await utils.syncConn();
|
||||
|
|
22
utils.js
22
utils.js
|
@ -16,9 +16,6 @@ export async function requestToken() {
|
|||
let spinner;
|
||||
try {
|
||||
spinner = ora(`Requesting new token...`).start();
|
||||
|
||||
if (!env.CLIENT_ID || !env.CLIENT_SECRET)
|
||||
throw new Error(`You haven't provided the credentials`)
|
||||
|
||||
const clientConfigData = await models.clientConfig.findOne();
|
||||
|
||||
|
@ -95,6 +92,25 @@ export async function getCurrentToken() {
|
|||
let data = await models.clientConfig.findOne();
|
||||
return data.currentToken
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the floriday data config
|
||||
*/
|
||||
export async function checkConfig() {
|
||||
const spinner = ora(`Checking config...`).start();
|
||||
|
||||
const excludedEnvVars = ['VSCODE_GIT_ASKPASS_EXTRA_ARGS'];
|
||||
const requiredEnvVars = Object.keys(env);
|
||||
const filteredEnvVars = requiredEnvVars.filter(reqEnvVar => !excludedEnvVars.includes(reqEnvVar));
|
||||
|
||||
for (const reqEnvVar of filteredEnvVars) {
|
||||
if (!process.env[reqEnvVar]) {
|
||||
spinner.fail();
|
||||
throw new Error(`You haven't provided the ${reqEnvVar} environment variable`);
|
||||
}
|
||||
}
|
||||
spinner.succeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expiration data of current token
|
||||
|
|
Loading…
Reference in New Issue