pagan-artifact 0.3.1 → 0.3.3
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/bin/art.js +213 -59
- package/branching/index.js +266 -110
- package/caches/index.js +257 -77
- package/changes/index.js +93 -29
- package/contributions/index.js +251 -100
- package/index.js +2 -2
- package/package.json +1 -1
- package/setup/index.js +190 -55
- package/utils/constants.js +15 -0
- package/utils/getStateByHash/index.js +135 -78
- package/utils/shouldIgnore/index.js +44 -3
- package/workflow/index.js +256 -132
package/changes/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Artifact - Modern version control.
|
|
3
|
+
* @author Benny Schmidt (https://github.com/bennyschmidt)
|
|
4
|
+
* @project https://github.com/bennyschmidt/artifact
|
|
5
|
+
* Module: Changes (v0.3.3)
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
8
|
const fs = require('fs');
|
|
@@ -14,32 +16,51 @@ const getStateByHash = require('../utils/getStateByHash');
|
|
|
14
16
|
*/
|
|
15
17
|
|
|
16
18
|
function log () {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Initialize repository paths and verify the existence of an .art directory
|
|
21
|
+
*/
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
const artifactPath = path.join(process.cwd(), '.art');
|
|
24
|
+
const artifactJsonPath = path.join(artifactPath, 'art.json');
|
|
25
|
+
|
|
26
|
+
if (!fs.existsSync(artifactJsonPath)) {
|
|
21
27
|
throw new Error('No art repository found.');
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Retrieve active branch details and locate the history manifest.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
const artifactJson = JSON.parse(
|
|
35
|
+
fs.readFileSync(artifactJsonPath, 'utf8')
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const branch = artifactJson.active.branch;
|
|
39
|
+
const branchPath = path.join(artifactPath, 'history/local', branch);
|
|
27
40
|
const manifestPath = path.join(branchPath, 'manifest.json');
|
|
28
41
|
|
|
29
42
|
if (!fs.existsSync(manifestPath)) {
|
|
30
43
|
return 'No commits found.';
|
|
31
44
|
}
|
|
32
45
|
|
|
33
|
-
const manifest = JSON.parse(
|
|
46
|
+
const manifest = JSON.parse(
|
|
47
|
+
fs.readFileSync(manifestPath, 'utf8')
|
|
48
|
+
);
|
|
34
49
|
|
|
35
50
|
let output = `Branch: ${branch}\n\n`;
|
|
36
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Build the commit history in reverse chronological order.
|
|
54
|
+
*/
|
|
55
|
+
|
|
37
56
|
for (let i = manifest.commits.length - 1; i >= 0; i--) {
|
|
38
57
|
const hash = manifest.commits[i];
|
|
39
58
|
const commitMasterPath = path.join(branchPath, `${hash}.json`);
|
|
40
59
|
|
|
41
60
|
if (fs.existsSync(commitMasterPath)) {
|
|
42
|
-
const commitData = JSON.parse(
|
|
61
|
+
const commitData = JSON.parse(
|
|
62
|
+
fs.readFileSync(commitMasterPath, 'utf8')
|
|
63
|
+
);
|
|
43
64
|
|
|
44
65
|
output += `commit ${commitData.hash}\n`;
|
|
45
66
|
output += `Date: ${new Date(commitData.timestamp).toLocaleString()}\n`;
|
|
@@ -56,24 +77,41 @@ function log () {
|
|
|
56
77
|
*/
|
|
57
78
|
|
|
58
79
|
function diff () {
|
|
80
|
+
/**
|
|
81
|
+
* Set up environment roots and retrieve the state of the last committed parent.
|
|
82
|
+
*/
|
|
83
|
+
|
|
59
84
|
const root = process.cwd();
|
|
60
|
-
const
|
|
61
|
-
const
|
|
85
|
+
const artifactPath = path.join(root, '.art');
|
|
86
|
+
const artifactJsonPath = path.join(artifactPath, 'art.json');
|
|
62
87
|
|
|
63
|
-
if (!fs.existsSync(
|
|
88
|
+
if (!fs.existsSync(artifactJsonPath)) {
|
|
64
89
|
throw new Error('No art repository found.');
|
|
65
90
|
}
|
|
66
91
|
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
92
|
+
const artifactJson = JSON.parse(
|
|
93
|
+
fs.readFileSync(artifactJsonPath, 'utf8')
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const activeBranch = artifactJson.active.branch;
|
|
97
|
+
const lastCommitHash = artifactJson.active.parent;
|
|
70
98
|
const lastCommitState = lastCommitHash ? getStateByHash(activeBranch, lastCommitHash) : {};
|
|
71
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Scan the working directory for files, excluding the .art internal folder.
|
|
102
|
+
*/
|
|
103
|
+
|
|
72
104
|
const currentFiles = fs.readdirSync(root, { recursive: true })
|
|
73
|
-
.filter(
|
|
105
|
+
.filter(file => {
|
|
106
|
+
return !file.startsWith('.art') && !fs.statSync(path.join(root, file)).isDirectory();
|
|
107
|
+
});
|
|
74
108
|
|
|
75
109
|
const fileDiffs = [];
|
|
76
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Calculate differences between current file content and the last known state.
|
|
113
|
+
*/
|
|
114
|
+
|
|
77
115
|
for (const filePath of currentFiles) {
|
|
78
116
|
const fullPath = path.join(root, filePath);
|
|
79
117
|
const currentBuffer = fs.readFileSync(fullPath);
|
|
@@ -83,6 +121,10 @@ function diff () {
|
|
|
83
121
|
const previousContent = lastCommitState[filePath] || '';
|
|
84
122
|
|
|
85
123
|
if (!isBinary && currentContent !== previousContent) {
|
|
124
|
+
/**
|
|
125
|
+
* Identify the range of changed characters to generate a compact diff.
|
|
126
|
+
*/
|
|
127
|
+
|
|
86
128
|
let start = 0;
|
|
87
129
|
|
|
88
130
|
while (start < previousContent.length && start < currentContent.length && previousContent[start] === currentContent[start]) {
|
|
@@ -103,40 +145,62 @@ function diff () {
|
|
|
103
145
|
added: currentContent.slice(start, newEnd + 1)
|
|
104
146
|
});
|
|
105
147
|
} else if (isBinary) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Handle binary files by checking existence rather than performing a text-based diff.
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
const previousHash = lastCommitState[filePath] ? 'exists' : 'null';
|
|
153
|
+
|
|
154
|
+
if (previousHash === 'null') {
|
|
155
|
+
fileDiffs.push({
|
|
156
|
+
file: filePath,
|
|
157
|
+
added: '<Binary Data>',
|
|
158
|
+
deleted: ''
|
|
159
|
+
});
|
|
110
160
|
}
|
|
111
161
|
}
|
|
112
162
|
}
|
|
113
163
|
|
|
114
|
-
|
|
115
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Access the staging area to identify files currently prepared for the next commit.
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
const stageDirectory = path.join(artifactPath, 'stage');
|
|
169
|
+
const stageManifestPath = path.join(stageDirectory, 'manifest.json');
|
|
116
170
|
|
|
117
171
|
let staged = [];
|
|
118
172
|
|
|
119
173
|
if (fs.existsSync(stageManifestPath)) {
|
|
120
|
-
const manifest = JSON.parse(
|
|
174
|
+
const manifest = JSON.parse(
|
|
175
|
+
fs.readFileSync(stageManifestPath, 'utf8')
|
|
176
|
+
);
|
|
121
177
|
const stagedFilesSet = new Set();
|
|
122
178
|
|
|
123
179
|
for (const partName of manifest.parts) {
|
|
124
|
-
const partPath = path.join(
|
|
180
|
+
const partPath = path.join(stageDirectory, partName);
|
|
125
181
|
|
|
126
182
|
if (fs.existsSync(partPath)) {
|
|
127
|
-
const partData = JSON.parse(
|
|
183
|
+
const partData = JSON.parse(
|
|
184
|
+
fs.readFileSync(partPath, 'utf8')
|
|
185
|
+
);
|
|
128
186
|
|
|
129
|
-
Object.keys(partData.changes)
|
|
187
|
+
for (const file of Object.keys(partData.changes)) {
|
|
188
|
+
stagedFilesSet.add(file);
|
|
189
|
+
}
|
|
130
190
|
}
|
|
131
191
|
}
|
|
192
|
+
|
|
132
193
|
staged = Array.from(stagedFilesSet);
|
|
133
194
|
}
|
|
134
195
|
|
|
135
|
-
return {
|
|
196
|
+
return {
|
|
197
|
+
fileDiffs,
|
|
198
|
+
staged
|
|
199
|
+
};
|
|
136
200
|
}
|
|
137
201
|
|
|
138
202
|
module.exports = {
|
|
139
|
-
__libraryVersion: '0.3.
|
|
203
|
+
__libraryVersion: '0.3.3',
|
|
140
204
|
__libraryAPIName: 'Changes',
|
|
141
205
|
log,
|
|
142
206
|
diff
|