This repository has been archived by the owner on Sep 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.js
88 lines (76 loc) · 1.94 KB
/
utils.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const fs = require('fs');
const path = require('path');
const co = require('co');
const { saveConfig } = require('./config');
const { APPLICATION } = require('./properties');
/**
* Synchronously checks for provided file
* @param file {string}
* @returns {Promise}
*/
function fileExists(file) {
return new Promise((resolve, reject) => {
try {
let result = fs.statSync(file).isFile();
resolve(result);
} catch (err) {
if (err.code === 'ENOENT') {
resolve(false);
} else {
reject(err);
}
}
});
}
/**
* Synchronously checks check for provided dir
* @param dir {string}
* @returns {Promise}
*/
function dirExists(dir) {
return new Promise((resolve, reject) => {
try {
let result = fs.statSync(dir).isDirectory();
resolve(result);
} catch (err) {
if (err.code === 'ENOENT') {
resolve(false);
} else {
reject(err);
}
}
});
}
/**
* Validates strato configuration - config.yaml file
* @returns {Promise}
*/
function validateConfig() {
return new Promise((resolve, reject) => {
const target = path.join(APPLICATION.HOME_PATH, APPLICATION.CONFIG_FOLDER, APPLICATION.CONFIG_FILE);
co(function* () {
let _exists = false;
yield fileExists(target)
.then((exists) => {
_exists = exists;
})
.catch((err) => {
return reject(err);
})
if (_exists) {
return resolve();
}
console.log('In order to configure your strato environment, you must enter your information below');
console.log('Note: if you have already completed this step, make sure that User\'s home directory /strato contains a config.yaml file');
saveConfig()
.then(() => {
return resolve();
})
.catch((err) => {
return reject(err);
});
});
});
}
module.exports.dirExists = dirExists;
module.exports.validateConfig = validateConfig;