|
1 | | -const path = require('path'); |
| 1 | +const path = require('./lib/path2'); |
2 | 2 | const fs = require('fs'); |
3 | 3 | const kleur = require('kleur'); |
4 | | - |
| 4 | +const { EXT_CONFIGS_DIR } = require('./lib/Constants'); |
5 | 5 |
|
6 | 6 | class PackageCreator |
7 | 7 | { |
8 | 8 | static CONF_FILE_PATH = path.join(__dirname, 'config.json'); |
| 9 | + |
9 | 10 |
|
10 | 11 | constructor() |
11 | 12 | { |
12 | 13 | console.log("### CONFIGURING PACKAGE ###"); |
| 14 | + |
| 15 | + this.createAppDirectories(); |
13 | 16 | try {this.conf = JSON.parse(fs.readFileSync(PackageCreator.CONF_FILE_PATH));} |
14 | 17 | catch (e) {return console.log('Could not load config file:', e);} |
15 | 18 |
|
16 | 19 | // console.log(conf); |
17 | 20 |
|
18 | 21 | this.createConfigurations(); |
19 | 22 |
|
20 | | - try { fs.writeFileSync(path.join(__dirname, 'data.json'), JSON.stringify({...conf.default_data, is_configured: false}, null, 2)); } |
21 | | - catch { console.log('Could not create data.json file'); } |
| 23 | + try { fs.writeFileSync(path.joinAppData('data.json'), JSON.stringify({...this.conf.default_data, is_configured: false}, null, 2)); } |
| 24 | + catch (e) { console.log('Could not create data.json file:', e); } |
22 | 25 | // this.conf.is_configured = true; |
23 | 26 | // fs.writeFileSync(PackageCreator.CONF_FILE_PATH, JSON.stringify(this.conf, null, 2)); |
24 | 27 | console.log("### PACKAGE CONFIGURATION CONCLUDED ###"); |
25 | 28 | } |
26 | 29 |
|
27 | | - |
| 30 | + createAppDirectories() |
| 31 | + { |
| 32 | + [EXT_CONFIGS_DIR].forEach(dir => { |
| 33 | + dir = path.joinAppData(dir); |
| 34 | + if (!fs.existsSync(dir)) |
| 35 | + { |
| 36 | + console.log("@ Creating", dir); |
| 37 | + fs.mkdirSync(dir, { recursive: true }); |
| 38 | + } |
| 39 | + }); |
| 40 | + } |
28 | 41 | createConfigurations() |
29 | 42 | { |
30 | 43 | this.conf_files_dir = this.conf.configuration.conf_files_dir; |
@@ -68,7 +81,7 @@ class PackageCreator |
68 | 81 | this.betterLog(depth + 1, 'configuring', kleur.green(name)); |
69 | 82 | const ext_name = ext.extension; |
70 | 83 | Reflect.deleteProperty(ext, 'extension'); |
71 | | - fs.writeFileSync(path.join(__dirname, this.conf_files_dir, ext_name) + '.json', JSON.stringify(ext, null, 2)); |
| 84 | + fs.writeFileSync(path.joinConfigDir(ext_name + '.json'), JSON.stringify(ext, null, 2)); |
72 | 85 | } |
73 | 86 |
|
74 | 87 | betterLog(depth, ...msg) |
|
0 commit comments