-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathconfig.js
35 lines (24 loc) · 970 Bytes
/
config.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
const {exec} = require("child_process");
const util = require('util');
const fs = require('fs');
const execp = util.promisify(exec);
let BP = '/var/www/html/magento/';
function getBasePath(){
console.log(this.BP);
}
async function getMagentoConfig(scope = this){
let magentoFonfigFile = scope.BP + "app/etc/env.php";
if (!fs.existsSync(magentoFonfigFile)) {
throw new Error("Magento configuration file doesn't exist at " + scope.BP + "app/etc/env.php Try to change BP variable at your code");
}
const cmd = `php -r 'echo json_encode(include "${magentoFonfigFile}");'`;
let result = await execp(cmd);
result = result.stdout;
//console.log(result);
return result;
}
async function getDBConfig(){
//If BP was changed outside the module we need pass scope(this) of the functin to the child getMagentoConfig
return JSON.parse(await getMagentoConfig(this)).db.connection.default;
}
module.exports = {BP, getDBConfig, getMagentoConfig, getBasePath}