xcraft-core-utils 4.3.8 → 4.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/modules.js CHANGED
@@ -1,184 +1,184 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fse = require('fs-extra');
5
- const xFs = require('xcraft-core-fs');
6
- const _ = require('lodash');
7
-
8
- function merge(obj, overloads) {
9
- _.mergeWith(obj, overloads, (_, src) =>
10
- Array.isArray(src) && src.length === 0 ? [] : undefined
11
- );
12
- }
13
-
14
- function applyOverloads(appDir, appId, variantId, app) {
15
- if (!variantId) {
16
- return;
17
- }
18
-
19
- try {
20
- const overloads = JSON.parse(
21
- fse.readFileSync(path.join(appDir, appId, `app.${variantId}.json`))
22
- );
23
- merge(app.xcraft, overloads);
24
- } catch (ex) {
25
- if (ex.code !== 'ENOENT') {
26
- throw ex;
27
- }
28
- }
29
- }
30
-
31
- exports.mergeOverloads = merge;
32
-
33
- exports.extractForEtc = (appDir, appId, variantId) => {
34
- const app = JSON.parse(
35
- fse.readFileSync(path.join(appDir, appId, 'app.json'))
36
- );
37
- applyOverloads(appDir, appId, variantId, app);
38
-
39
- Object.keys(app.xcraft)
40
- .filter((key) => key.includes('@'))
41
- .map((key) => {
42
- const arr = key.split('@');
43
- return {
44
- moduleName: arr[0],
45
- fullAppId: arr[1],
46
- appIds: arr[1].split('+'),
47
- };
48
- })
49
- .forEach((mod) => {
50
- const userOverloads = app.xcraft[`${mod.moduleName}@${mod.fullAppId}`];
51
- app.xcraft[mod.moduleName] = {};
52
-
53
- mod.appIds.forEach((appId) => {
54
- const appConfig = JSON.parse(
55
- fse.readFileSync(path.join(appDir, appId, 'app.json'))
56
- );
57
- applyOverloads(appDir, appId, variantId, appConfig);
58
- merge(app.xcraft[mod.moduleName], appConfig.xcraft[mod.moduleName]);
59
- });
60
-
61
- merge(app.xcraft[mod.moduleName], userOverloads);
62
- delete app.xcraft[`${mod.moduleName}@${mod.fullAppId}`];
63
- });
64
-
65
- return app.xcraft;
66
- };
67
-
68
- exports.loadAppConfig = (appId, appDir, configJson = {}, variantId = null) => {
69
- if (configJson[appId]) {
70
- return;
71
- }
72
-
73
- configJson[appId] = exports.extractForEtc(appDir, appId, variantId);
74
- const hordesCfg = configJson[appId]['xcraft-core-horde'];
75
-
76
- if (hordesCfg && hordesCfg.hordes) {
77
- hordesCfg.hordes
78
- .filter(
79
- (appId) =>
80
- !hordesCfg.topology ||
81
- (hordesCfg.topology && !hordesCfg.topology[appId])
82
- )
83
- .forEach((appId) =>
84
- exports.loadAppConfig(appId, appDir, configJson, variantId)
85
- );
86
- }
87
-
88
- return configJson;
89
- };
90
-
91
- exports.extractConfigDeps = (libDir, configJson) => {
92
- const deps = {};
93
-
94
- Object.keys(configJson).forEach((appId) => {
95
- const appCfg = configJson[appId];
96
- const serverCfg = appCfg['xcraft-core-server'];
97
- if (!serverCfg || !serverCfg.modules) {
98
- return;
99
- }
100
-
101
- serverCfg.modules.forEach((mod) => {
102
- deps[mod] = true;
103
- });
104
- });
105
-
106
- if (!Object.keys(deps).length) {
107
- xFs
108
- .lsdir(libDir)
109
- .filter((dir) => !/^xcraft-dev-.*/.test(dir))
110
- .forEach((dep) => {
111
- deps[dep] = true;
112
- });
113
- }
114
-
115
- return deps;
116
- };
117
-
118
- exports.extractAllDeps = (appId, libDir, configJson) => {
119
- const newDeps = exports.extractConfigDeps(libDir, configJson);
120
-
121
- const filters = [/^xcraft-(core|contrib)-/];
122
- const serverCfg = configJson[appId]['xcraft-core-server'];
123
- if (serverCfg) {
124
- if (serverCfg.userModulesFilter) {
125
- filters.push(new RegExp(serverCfg.userModulesFilter));
126
- }
127
- }
128
-
129
- const extract = (deps) => {
130
- let newDep = false;
131
-
132
- Object.keys(deps)
133
- .map((dep) => {
134
- const def = JSON.parse(
135
- fse.readFileSync(path.join(libDir, dep, 'package.json'))
136
- );
137
- return def.dependencies ? Object.keys(def.dependencies) : [];
138
- })
139
- .forEach((_deps) =>
140
- _deps
141
- .filter(
142
- (dep) =>
143
- !newDeps.hasOwnProperty(dep) &&
144
- filters.some((filter) => filter.test(dep))
145
- )
146
- .forEach((dep) => {
147
- newDep = true;
148
- newDeps[dep] = dep;
149
- })
150
- );
151
-
152
- if (newDep) {
153
- extract(newDeps);
154
- }
155
- };
156
-
157
- extract(newDeps);
158
- return Object.keys(newDeps);
159
- };
160
-
161
- exports.extractAllJs = (libDir, modules) => {
162
- let list = [];
163
-
164
- modules.forEach((mod) => {
165
- const location = path.join(libDir, mod);
166
- const files = xFs
167
- .lsall(location, true)
168
- .filter((file) => {
169
- const relativePath = file.substring(location.length + 1);
170
- const items = relativePath.split(path.sep);
171
- if (items.includes('node_modules')) {
172
- return false;
173
- }
174
- if (items[0] === 'test' || items[0] === 'species') {
175
- return false;
176
- }
177
- return true;
178
- })
179
- .filter((file) => /\.js$/.test(file));
180
- list = list.concat(files);
181
- });
182
-
183
- return list;
184
- };
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fse = require('fs-extra');
5
+ const xFs = require('xcraft-core-fs');
6
+ const _ = require('lodash');
7
+
8
+ function merge(obj, overloads) {
9
+ _.mergeWith(obj, overloads, (_, src) =>
10
+ Array.isArray(src) && src.length === 0 ? [] : undefined
11
+ );
12
+ }
13
+
14
+ function applyOverloads(appDir, appId, variantId, app) {
15
+ if (!variantId) {
16
+ return;
17
+ }
18
+
19
+ try {
20
+ const overloads = JSON.parse(
21
+ fse.readFileSync(path.join(appDir, appId, `app.${variantId}.json`))
22
+ );
23
+ merge(app.xcraft, overloads);
24
+ } catch (ex) {
25
+ if (ex.code !== 'ENOENT') {
26
+ throw ex;
27
+ }
28
+ }
29
+ }
30
+
31
+ exports.mergeOverloads = merge;
32
+
33
+ exports.extractForEtc = (appDir, appId, variantId) => {
34
+ const app = JSON.parse(
35
+ fse.readFileSync(path.join(appDir, appId, 'app.json'))
36
+ );
37
+ applyOverloads(appDir, appId, variantId, app);
38
+
39
+ Object.keys(app.xcraft)
40
+ .filter((key) => key.includes('@'))
41
+ .map((key) => {
42
+ const arr = key.split('@');
43
+ return {
44
+ moduleName: arr[0],
45
+ fullAppId: arr[1],
46
+ appIds: arr[1].split('+'),
47
+ };
48
+ })
49
+ .forEach((mod) => {
50
+ const userOverloads = app.xcraft[`${mod.moduleName}@${mod.fullAppId}`];
51
+ app.xcraft[mod.moduleName] = {};
52
+
53
+ mod.appIds.forEach((appId) => {
54
+ const appConfig = JSON.parse(
55
+ fse.readFileSync(path.join(appDir, appId, 'app.json'))
56
+ );
57
+ applyOverloads(appDir, appId, variantId, appConfig);
58
+ merge(app.xcraft[mod.moduleName], appConfig.xcraft[mod.moduleName]);
59
+ });
60
+
61
+ merge(app.xcraft[mod.moduleName], userOverloads);
62
+ delete app.xcraft[`${mod.moduleName}@${mod.fullAppId}`];
63
+ });
64
+
65
+ return app.xcraft;
66
+ };
67
+
68
+ exports.loadAppConfig = (appId, appDir, configJson = {}, variantId = null) => {
69
+ if (configJson[appId]) {
70
+ return;
71
+ }
72
+
73
+ configJson[appId] = exports.extractForEtc(appDir, appId, variantId);
74
+ const hordesCfg = configJson[appId]['xcraft-core-horde'];
75
+
76
+ if (hordesCfg && hordesCfg.hordes) {
77
+ hordesCfg.hordes
78
+ .filter(
79
+ (appId) =>
80
+ !hordesCfg.topology ||
81
+ (hordesCfg.topology && !hordesCfg.topology[appId])
82
+ )
83
+ .forEach((appId) =>
84
+ exports.loadAppConfig(appId, appDir, configJson, variantId)
85
+ );
86
+ }
87
+
88
+ return configJson;
89
+ };
90
+
91
+ exports.extractConfigDeps = (libDir, configJson) => {
92
+ const deps = {};
93
+
94
+ Object.keys(configJson).forEach((appId) => {
95
+ const appCfg = configJson[appId];
96
+ const serverCfg = appCfg['xcraft-core-server'];
97
+ if (!serverCfg || !serverCfg.modules) {
98
+ return;
99
+ }
100
+
101
+ serverCfg.modules.forEach((mod) => {
102
+ deps[mod] = true;
103
+ });
104
+ });
105
+
106
+ if (!Object.keys(deps).length) {
107
+ xFs
108
+ .lsdir(libDir)
109
+ .filter((dir) => !/^xcraft-dev-.*/.test(dir))
110
+ .forEach((dep) => {
111
+ deps[dep] = true;
112
+ });
113
+ }
114
+
115
+ return deps;
116
+ };
117
+
118
+ exports.extractAllDeps = (appId, libDir, configJson) => {
119
+ const newDeps = exports.extractConfigDeps(libDir, configJson);
120
+
121
+ const filters = [/^xcraft-(core|contrib)-/];
122
+ const serverCfg = configJson[appId]['xcraft-core-server'];
123
+ if (serverCfg) {
124
+ if (serverCfg.userModulesFilter) {
125
+ filters.push(new RegExp(serverCfg.userModulesFilter));
126
+ }
127
+ }
128
+
129
+ const extract = (deps) => {
130
+ let newDep = false;
131
+
132
+ Object.keys(deps)
133
+ .map((dep) => {
134
+ const def = JSON.parse(
135
+ fse.readFileSync(path.join(libDir, dep, 'package.json'))
136
+ );
137
+ return def.dependencies ? Object.keys(def.dependencies) : [];
138
+ })
139
+ .forEach((_deps) =>
140
+ _deps
141
+ .filter(
142
+ (dep) =>
143
+ !newDeps.hasOwnProperty(dep) &&
144
+ filters.some((filter) => filter.test(dep))
145
+ )
146
+ .forEach((dep) => {
147
+ newDep = true;
148
+ newDeps[dep] = dep;
149
+ })
150
+ );
151
+
152
+ if (newDep) {
153
+ extract(newDeps);
154
+ }
155
+ };
156
+
157
+ extract(newDeps);
158
+ return Object.keys(newDeps);
159
+ };
160
+
161
+ exports.extractAllJs = (libDir, modules) => {
162
+ let list = [];
163
+
164
+ modules.forEach((mod) => {
165
+ const location = path.join(libDir, mod);
166
+ const files = xFs
167
+ .lsall(location, true)
168
+ .filter((file) => {
169
+ const relativePath = file.substring(location.length + 1);
170
+ const items = relativePath.split(path.sep);
171
+ if (items.includes('node_modules')) {
172
+ return false;
173
+ }
174
+ if (items[0] === 'test' || items[0] === 'species') {
175
+ return false;
176
+ }
177
+ return true;
178
+ })
179
+ .filter((file) => /\.js$/.test(file));
180
+ list = list.concat(files);
181
+ });
182
+
183
+ return list;
184
+ };
package/lib/os.js CHANGED
@@ -1,13 +1,13 @@
1
- 'use strict';
2
-
3
- const os = require('os');
4
- const path = require('path');
5
-
6
- exports.getAppData = function () {
7
- return (
8
- (process.platform === 'win32' && process.env.APPDATA) ||
9
- (process.platform === 'darwin'
10
- ? path.join(os.homedir(), 'Library/Application Support')
11
- : path.join(os.homedir(), '.local/share'))
12
- );
13
- };
1
+ 'use strict';
2
+
3
+ const os = require('os');
4
+ const path = require('path');
5
+
6
+ exports.getAppData = function () {
7
+ return (
8
+ (process.platform === 'win32' && process.env.APPDATA) ||
9
+ (process.platform === 'darwin'
10
+ ? path.join(os.homedir(), 'Library/Application Support')
11
+ : path.join(os.homedir(), '.local/share'))
12
+ );
13
+ };