-
Notifications
You must be signed in to change notification settings - Fork 0
/
copyprogaccess.js
75 lines (54 loc) · 2.21 KB
/
copyprogaccess.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
const fs = require('fs');
const path = require('path');
const apps_dir = path.join(__dirname, 'apps');
const target_config_dir = process.argv[2]
if (target_config_dir===undefined) {
console.log('Direktori tujuan belum didefinisikan');
process.exit(0);
}
if (!fs.existsSync(target_config_dir)) {
console.log(`Direktori tujuan '${target_config_dir}' tidak ditemukan.`);
process.exit(0);
}
if (!fs.lstatSync(target_config_dir).isDirectory()) {
console.log(`'${target_config_dir}' bukan direktori.`);
process.exit(0);
}
console.log(`Reading directory '${apps_dir}' ...`);
var dircontents = fs.readdirSync(apps_dir);
for (var prj_dc_name of dircontents) {
//console.log(prj_dc_name);
var prj_path = path.join(apps_dir, prj_dc_name)
if (!fs.lstatSync(prj_path).isSymbolicLink()) { continue; }
if (prj_dc_name==='fgta' || prj_dc_name=='etap') { continue; }
var prj_dircontents = fs.readdirSync(prj_path);
for (var mod_dc_name of prj_dircontents) {
var mod_path = path.join(prj_path, mod_dc_name)
if (mod_dc_name=='.git' && mod_dc_name=='.vscode') { continue; }
if (!fs.lstatSync(mod_path).isDirectory()) { continue; }
var pro_dircontents = fs.readdirSync(mod_path);
for (var pro_dc_name of pro_dircontents) {
var pro_path = path.join(mod_path, pro_dc_name)
if (!fs.lstatSync(pro_path).isDirectory()) { continue; }
// console.log(prj_dc_name, mod_dc_name, pro_dc_name);
var ori_configfile_path = path.join(pro_path, `${pro_dc_name}.json`)
if (fs.existsSync(ori_configfile_path)) {
// console.log(ori_configfile_path);
var ori_configfile_content = fs.readFileSync(ori_configfile_path)
var ori_config = JSON.parse(ori_configfile_content)
var config_to_copy = {
allowanonymous: ori_config.allowanonymous,
allowedgroups: ori_config.allowedgroups,
apis: ori_config.apis
}
var config_string = JSON.stringify(config_to_copy, null, 4);
var config_filename = `${prj_dc_name}#${mod_dc_name}#${pro_dc_name}.json`
var config_filepath = path.join(target_config_dir, config_filename)
if (!fs.existsSync(config_filepath)) {
console.log('writing config file', config_filename, '..')
fs.writeFileSync(config_filepath, config_string)
}
}
}
}
}