1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | const { isEmpty, isNullOrUndefined, readJSONSync, writeJSON } = require('./Utils');
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | class ProjectSetup {
|
22 | constructor(projectPath) {
|
23 | this._path = projectPath;
|
24 | this._setup = {};
|
25 | }
|
26 |
|
27 | save(done) {
|
28 | const data = this._setup;
|
29 | writeJSON({ file: this._path, data }, done);
|
30 | }
|
31 |
|
32 | load() {
|
33 | try {
|
34 | const projectSetup = readJSONSync(this._path);
|
35 | if (!isEmpty(projectSetup)) {
|
36 | this._setup = projectSetup;
|
37 | }
|
38 | } catch (err) {
|
39 | return err;
|
40 | }
|
41 | }
|
42 |
|
43 | getFlexNamespace(key) {
|
44 | if (isNullOrUndefined(this._setup[key])) {
|
45 | return {};
|
46 | }
|
47 |
|
48 | return Object.assign({}, this._setup[key].flex);
|
49 | }
|
50 |
|
51 | setFlexNamespace(key, { domain, domainEntityId, serviceId, serviceName, svcEnvId, schemaVersion }) {
|
52 | this._setup[key] = {
|
53 | flex: {
|
54 | domain,
|
55 | domainEntityId,
|
56 | serviceId,
|
57 | serviceName,
|
58 | svcEnvId,
|
59 | schemaVersion
|
60 | }
|
61 | };
|
62 | }
|
63 |
|
64 | clear() {
|
65 | this._setup = '';
|
66 | }
|
67 |
|
68 | setJobId(key, id) {
|
69 | if (isNullOrUndefined(this._setup[key]) || isNullOrUndefined(this._setup[key].flex)) {
|
70 | this._setup[key] = { flex: {} };
|
71 | }
|
72 |
|
73 | this._setup[key].flex.jobId = id;
|
74 | }
|
75 |
|
76 | _isPropertySetInFlexNamespace(firstLevelKey, propName) {
|
77 | return this._setup && !isEmpty(this._setup[firstLevelKey]) && !isEmpty(this._setup[firstLevelKey].flex)
|
78 | && !isNullOrUndefined(this._setup[firstLevelKey].flex[propName]);
|
79 | }
|
80 |
|
81 | _clearPropertyInFlexNamespace(firstLevelKey, propName) {
|
82 | delete this._setup[firstLevelKey].flex[propName];
|
83 | }
|
84 |
|
85 | isServiceSetInFlexNamespace(firstLevelKey, serviceId) {
|
86 | return this._isPropertySetInFlexNamespace(firstLevelKey, 'serviceId') && this.getFlexNamespace(firstLevelKey).serviceId === serviceId;
|
87 | }
|
88 |
|
89 | clearServiceInFlexNamespace(firstLevelKey) {
|
90 | const keysToRemove = ['serviceId', 'serviceName'];
|
91 | keysToRemove.forEach(k => this._clearPropertyInFlexNamespace(firstLevelKey, k));
|
92 | }
|
93 | }
|
94 |
|
95 | module.exports = ProjectSetup;
|