@magentrix-corp/magentrix-cli 1.3.16 → 1.3.17
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/LICENSE +25 -25
- package/README.md +1166 -1166
- package/actions/autopublish.old.js +293 -293
- package/actions/config.js +182 -182
- package/actions/create.js +466 -466
- package/actions/help.js +164 -164
- package/actions/iris/buildStage.js +874 -874
- package/actions/iris/delete.js +256 -256
- package/actions/iris/dev.js +391 -391
- package/actions/iris/index.js +6 -6
- package/actions/iris/link.js +375 -375
- package/actions/iris/recover.js +268 -268
- package/actions/main.js +80 -80
- package/actions/publish.js +1420 -1420
- package/actions/pull.js +684 -684
- package/actions/setup.js +148 -148
- package/actions/status.js +17 -17
- package/actions/update.js +248 -248
- package/bin/magentrix.js +393 -393
- package/package.json +55 -55
- package/utils/assetPaths.js +158 -158
- package/utils/autopublishLock.js +77 -77
- package/utils/cacher.js +206 -206
- package/utils/cli/checkInstanceUrl.js +76 -74
- package/utils/cli/helpers/compare.js +282 -282
- package/utils/cli/helpers/ensureApiKey.js +63 -63
- package/utils/cli/helpers/ensureCredentials.js +68 -68
- package/utils/cli/helpers/ensureInstanceUrl.js +75 -75
- package/utils/cli/writeRecords.js +262 -262
- package/utils/compare.js +135 -135
- package/utils/compress.js +17 -17
- package/utils/config.js +527 -527
- package/utils/debug.js +144 -144
- package/utils/diagnostics/testPublishLogic.js +96 -96
- package/utils/diff.js +49 -49
- package/utils/downloadAssets.js +291 -291
- package/utils/filetag.js +115 -115
- package/utils/hash.js +14 -14
- package/utils/iris/backup.js +411 -411
- package/utils/iris/builder.js +541 -541
- package/utils/iris/config-reader.js +664 -664
- package/utils/iris/deleteHelper.js +150 -150
- package/utils/iris/errors.js +537 -537
- package/utils/iris/linker.js +601 -601
- package/utils/iris/lock.js +360 -360
- package/utils/iris/validation.js +360 -360
- package/utils/iris/validator.js +281 -281
- package/utils/iris/zipper.js +248 -248
- package/utils/logger.js +291 -291
- package/utils/magentrix/api/assets.js +220 -220
- package/utils/magentrix/api/auth.js +107 -107
- package/utils/magentrix/api/createEntity.js +61 -61
- package/utils/magentrix/api/deleteEntity.js +55 -55
- package/utils/magentrix/api/iris.js +251 -251
- package/utils/magentrix/api/meqlQuery.js +36 -36
- package/utils/magentrix/api/retrieveEntity.js +86 -86
- package/utils/magentrix/api/updateEntity.js +66 -66
- package/utils/magentrix/fetch.js +168 -168
- package/utils/merge.js +22 -22
- package/utils/permissionError.js +70 -70
- package/utils/preferences.js +40 -40
- package/utils/progress.js +469 -469
- package/utils/spinner.js +43 -43
- package/utils/template.js +52 -52
- package/utils/updateFileBase.js +121 -121
- package/utils/workspaces.js +108 -108
- package/vars/config.js +11 -11
- package/vars/global.js +50 -50
package/utils/compare.js
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { sha256 } from './hash.js';
|
|
3
|
-
import { findFileByTag } from './filetag.js';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Compares a local file to its remote representation and determines their sync status.
|
|
8
|
-
*
|
|
9
|
-
* - Checks file existence, last modified times, and content hashes.
|
|
10
|
-
* - Returns detailed sync info; never logs or warns directly.
|
|
11
|
-
*
|
|
12
|
-
* @param {string} localFilePath - The path to the local file.
|
|
13
|
-
* @param {Object} remoteData - Object containing remote file metadata and content.
|
|
14
|
-
* @param {string} remoteData.content - The file content from the remote.
|
|
15
|
-
* @param {string} remoteData.ModifiedOn - The last modified date of the remote file (ISO string).
|
|
16
|
-
* @returns {Object} An object describing the sync status. Possible statuses:
|
|
17
|
-
* - 'in_sync': Files match (hashes and times).
|
|
18
|
-
* - 'behind': Local file is older than remote, but content is identical.
|
|
19
|
-
* - 'conflict': Local file is behind remote and contents differ (conflict).
|
|
20
|
-
* - 'ahead': Local file is newer than remote and contents differ.
|
|
21
|
-
* - 'ahead_identical': Local file is newer than remote but contents are identical (possible clock drift).
|
|
22
|
-
* - 'content_differs': Timestamps match but contents differ (possible manual edit).
|
|
23
|
-
* - 'missing': Local file does not exist (safe to download from remote).
|
|
24
|
-
* Additional returned fields depend on status.
|
|
25
|
-
*/
|
|
26
|
-
export function compareLocalAndRemote(localFilePath, remoteData) {
|
|
27
|
-
// If local file does not exist, it's fine—just return 'missing'
|
|
28
|
-
if (!fs.existsSync(localFilePath)) {
|
|
29
|
-
return {
|
|
30
|
-
status: 'missing',
|
|
31
|
-
message: 'Local file is missing.'
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Gather local file details
|
|
36
|
-
const localStats = fs.statSync(localFilePath);
|
|
37
|
-
const localContent = fs.readFileSync(localFilePath, 'utf8');
|
|
38
|
-
const localMtime = Math.ceil(localStats.mtimeMs); // Local last modified time (ms)
|
|
39
|
-
const localHash = sha256(localContent); // Local file content hash
|
|
40
|
-
|
|
41
|
-
// Gather remote file details
|
|
42
|
-
const remoteContent = remoteData.content;
|
|
43
|
-
const remoteMtime = Math.ceil(new Date(remoteData.ModifiedOn).getTime()); // Remote last modified time (ms)
|
|
44
|
-
const remoteHash = sha256(remoteContent); // Remote file content hash
|
|
45
|
-
|
|
46
|
-
// Case: local is behind remote (older mtime)
|
|
47
|
-
if (localMtime < remoteMtime) {
|
|
48
|
-
if (localHash !== remoteHash) {
|
|
49
|
-
// File changed on both local and remote: conflict!
|
|
50
|
-
return {
|
|
51
|
-
status: 'conflict',
|
|
52
|
-
localMtime,
|
|
53
|
-
remoteMtime,
|
|
54
|
-
localHash,
|
|
55
|
-
remoteHash,
|
|
56
|
-
message: 'Local file is behind remote and has conflicting changes.'
|
|
57
|
-
};
|
|
58
|
-
} else {
|
|
59
|
-
// Local is older but identical to remote
|
|
60
|
-
// return {
|
|
61
|
-
// status: 'behind',
|
|
62
|
-
// localMtime,
|
|
63
|
-
// remoteMtime,
|
|
64
|
-
// message: 'Local file is behind remote but contents are identical.'
|
|
65
|
-
// };
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
status: 'in_sync',
|
|
69
|
-
localMtime,
|
|
70
|
-
remoteMtime,
|
|
71
|
-
message: 'Local and remote file are in sync.'
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// Case: local is ahead of remote (newer mtime)
|
|
76
|
-
else if (localMtime > remoteMtime) {
|
|
77
|
-
if (localHash !== remoteHash) {
|
|
78
|
-
return {
|
|
79
|
-
status: 'ahead',
|
|
80
|
-
localMtime,
|
|
81
|
-
remoteMtime,
|
|
82
|
-
localHash,
|
|
83
|
-
remoteHash,
|
|
84
|
-
message: 'Local file is ahead of remote and content differs.'
|
|
85
|
-
};
|
|
86
|
-
} else {
|
|
87
|
-
// Local is ahead but identical
|
|
88
|
-
// return {
|
|
89
|
-
// status: 'ahead_identical',
|
|
90
|
-
// localMtime,
|
|
91
|
-
// remoteMtime,
|
|
92
|
-
// message: 'Local file is ahead of remote but contents are identical.'
|
|
93
|
-
// };
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
status: 'in_sync',
|
|
97
|
-
localMtime,
|
|
98
|
-
remoteMtime,
|
|
99
|
-
message: 'Local and remote file are in sync.'
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
// Case: mtimes match
|
|
104
|
-
else {
|
|
105
|
-
// Check for rename
|
|
106
|
-
const matchingFilePath = findFileByTag(remoteData.Id);
|
|
107
|
-
const absoluteLocalPath = path.resolve(localFilePath);
|
|
108
|
-
|
|
109
|
-
if (matchingFilePath !== absoluteLocalPath) {
|
|
110
|
-
return {
|
|
111
|
-
status: 'rename',
|
|
112
|
-
localMtime,
|
|
113
|
-
remoteMtime,
|
|
114
|
-
message: 'Local and remote file names differ.'
|
|
115
|
-
};
|
|
116
|
-
} else if (localHash === remoteHash) {
|
|
117
|
-
return {
|
|
118
|
-
status: 'in_sync',
|
|
119
|
-
localMtime,
|
|
120
|
-
remoteMtime,
|
|
121
|
-
message: 'Local and remote file are in sync.'
|
|
122
|
-
};
|
|
123
|
-
} else {
|
|
124
|
-
// Timestamps match but contents do not
|
|
125
|
-
return {
|
|
126
|
-
status: 'content_differs',
|
|
127
|
-
localMtime,
|
|
128
|
-
remoteMtime,
|
|
129
|
-
localHash,
|
|
130
|
-
remoteHash,
|
|
131
|
-
message: 'File times match, but content differs (possible manual edit).'
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { sha256 } from './hash.js';
|
|
3
|
+
import { findFileByTag } from './filetag.js';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Compares a local file to its remote representation and determines their sync status.
|
|
8
|
+
*
|
|
9
|
+
* - Checks file existence, last modified times, and content hashes.
|
|
10
|
+
* - Returns detailed sync info; never logs or warns directly.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} localFilePath - The path to the local file.
|
|
13
|
+
* @param {Object} remoteData - Object containing remote file metadata and content.
|
|
14
|
+
* @param {string} remoteData.content - The file content from the remote.
|
|
15
|
+
* @param {string} remoteData.ModifiedOn - The last modified date of the remote file (ISO string).
|
|
16
|
+
* @returns {Object} An object describing the sync status. Possible statuses:
|
|
17
|
+
* - 'in_sync': Files match (hashes and times).
|
|
18
|
+
* - 'behind': Local file is older than remote, but content is identical.
|
|
19
|
+
* - 'conflict': Local file is behind remote and contents differ (conflict).
|
|
20
|
+
* - 'ahead': Local file is newer than remote and contents differ.
|
|
21
|
+
* - 'ahead_identical': Local file is newer than remote but contents are identical (possible clock drift).
|
|
22
|
+
* - 'content_differs': Timestamps match but contents differ (possible manual edit).
|
|
23
|
+
* - 'missing': Local file does not exist (safe to download from remote).
|
|
24
|
+
* Additional returned fields depend on status.
|
|
25
|
+
*/
|
|
26
|
+
export function compareLocalAndRemote(localFilePath, remoteData) {
|
|
27
|
+
// If local file does not exist, it's fine—just return 'missing'
|
|
28
|
+
if (!fs.existsSync(localFilePath)) {
|
|
29
|
+
return {
|
|
30
|
+
status: 'missing',
|
|
31
|
+
message: 'Local file is missing.'
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Gather local file details
|
|
36
|
+
const localStats = fs.statSync(localFilePath);
|
|
37
|
+
const localContent = fs.readFileSync(localFilePath, 'utf8');
|
|
38
|
+
const localMtime = Math.ceil(localStats.mtimeMs); // Local last modified time (ms)
|
|
39
|
+
const localHash = sha256(localContent); // Local file content hash
|
|
40
|
+
|
|
41
|
+
// Gather remote file details
|
|
42
|
+
const remoteContent = remoteData.content;
|
|
43
|
+
const remoteMtime = Math.ceil(new Date(remoteData.ModifiedOn).getTime()); // Remote last modified time (ms)
|
|
44
|
+
const remoteHash = sha256(remoteContent); // Remote file content hash
|
|
45
|
+
|
|
46
|
+
// Case: local is behind remote (older mtime)
|
|
47
|
+
if (localMtime < remoteMtime) {
|
|
48
|
+
if (localHash !== remoteHash) {
|
|
49
|
+
// File changed on both local and remote: conflict!
|
|
50
|
+
return {
|
|
51
|
+
status: 'conflict',
|
|
52
|
+
localMtime,
|
|
53
|
+
remoteMtime,
|
|
54
|
+
localHash,
|
|
55
|
+
remoteHash,
|
|
56
|
+
message: 'Local file is behind remote and has conflicting changes.'
|
|
57
|
+
};
|
|
58
|
+
} else {
|
|
59
|
+
// Local is older but identical to remote
|
|
60
|
+
// return {
|
|
61
|
+
// status: 'behind',
|
|
62
|
+
// localMtime,
|
|
63
|
+
// remoteMtime,
|
|
64
|
+
// message: 'Local file is behind remote but contents are identical.'
|
|
65
|
+
// };
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
status: 'in_sync',
|
|
69
|
+
localMtime,
|
|
70
|
+
remoteMtime,
|
|
71
|
+
message: 'Local and remote file are in sync.'
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Case: local is ahead of remote (newer mtime)
|
|
76
|
+
else if (localMtime > remoteMtime) {
|
|
77
|
+
if (localHash !== remoteHash) {
|
|
78
|
+
return {
|
|
79
|
+
status: 'ahead',
|
|
80
|
+
localMtime,
|
|
81
|
+
remoteMtime,
|
|
82
|
+
localHash,
|
|
83
|
+
remoteHash,
|
|
84
|
+
message: 'Local file is ahead of remote and content differs.'
|
|
85
|
+
};
|
|
86
|
+
} else {
|
|
87
|
+
// Local is ahead but identical
|
|
88
|
+
// return {
|
|
89
|
+
// status: 'ahead_identical',
|
|
90
|
+
// localMtime,
|
|
91
|
+
// remoteMtime,
|
|
92
|
+
// message: 'Local file is ahead of remote but contents are identical.'
|
|
93
|
+
// };
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
status: 'in_sync',
|
|
97
|
+
localMtime,
|
|
98
|
+
remoteMtime,
|
|
99
|
+
message: 'Local and remote file are in sync.'
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Case: mtimes match
|
|
104
|
+
else {
|
|
105
|
+
// Check for rename
|
|
106
|
+
const matchingFilePath = findFileByTag(remoteData.Id);
|
|
107
|
+
const absoluteLocalPath = path.resolve(localFilePath);
|
|
108
|
+
|
|
109
|
+
if (matchingFilePath !== absoluteLocalPath) {
|
|
110
|
+
return {
|
|
111
|
+
status: 'rename',
|
|
112
|
+
localMtime,
|
|
113
|
+
remoteMtime,
|
|
114
|
+
message: 'Local and remote file names differ.'
|
|
115
|
+
};
|
|
116
|
+
} else if (localHash === remoteHash) {
|
|
117
|
+
return {
|
|
118
|
+
status: 'in_sync',
|
|
119
|
+
localMtime,
|
|
120
|
+
remoteMtime,
|
|
121
|
+
message: 'Local and remote file are in sync.'
|
|
122
|
+
};
|
|
123
|
+
} else {
|
|
124
|
+
// Timestamps match but contents do not
|
|
125
|
+
return {
|
|
126
|
+
status: 'content_differs',
|
|
127
|
+
localMtime,
|
|
128
|
+
remoteMtime,
|
|
129
|
+
localHash,
|
|
130
|
+
remoteHash,
|
|
131
|
+
message: 'File times match, but content differs (possible manual edit).'
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
package/utils/compress.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import pako from 'pako';
|
|
2
|
-
|
|
3
|
-
export const compressString = (input) => {
|
|
4
|
-
const compressed = pako.deflate(input);
|
|
5
|
-
const compressedStr = Buffer.from(compressed).toString('base64');
|
|
6
|
-
return compressedStr;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const decompressString = (compressedInput) => {
|
|
10
|
-
try {
|
|
11
|
-
if (!compressedInput) return '';
|
|
12
|
-
const decoded = Buffer.from(compressedInput, 'base64');
|
|
13
|
-
const decompressed = pako.inflate(decoded, { to: 'string' });
|
|
14
|
-
return decompressed;
|
|
15
|
-
} catch (err) {
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
1
|
+
import pako from 'pako';
|
|
2
|
+
|
|
3
|
+
export const compressString = (input) => {
|
|
4
|
+
const compressed = pako.deflate(input);
|
|
5
|
+
const compressedStr = Buffer.from(compressed).toString('base64');
|
|
6
|
+
return compressedStr;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const decompressString = (compressedInput) => {
|
|
10
|
+
try {
|
|
11
|
+
if (!compressedInput) return '';
|
|
12
|
+
const decoded = Buffer.from(compressedInput, 'base64');
|
|
13
|
+
const decompressed = pako.inflate(decoded, { to: 'string' });
|
|
14
|
+
return decompressed;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
18
|
}
|