pagan-artifact 0.3.2 → 0.3.4
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 +205 -53
- package/branching/index.js +266 -110
- package/caches/index.js +257 -77
- package/changes/index.js +93 -29
- package/contributions/index.js +249 -101
- 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/bin/art.js
CHANGED
|
@@ -1,28 +1,51 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Artifact - Modern version control.
|
|
5
|
+
* @author Benny Schmidt (https://github.com/bennyschmidt)
|
|
6
|
+
* @project https://github.com/bennyschmidt/artifact
|
|
7
|
+
* CLI (v0.3.4)
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
|
-
const
|
|
10
|
+
const artifact = require('../index.js');
|
|
9
11
|
const path = require('path');
|
|
10
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Extract command line args
|
|
15
|
+
*/
|
|
16
|
+
|
|
11
17
|
const [,, command, ...args] = process.argv;
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Console text color constants
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
RED,
|
|
25
|
+
GREEN,
|
|
26
|
+
RESET,
|
|
27
|
+
GRAY
|
|
28
|
+
} = require('../utils/constants.js');
|
|
17
29
|
|
|
18
30
|
async function run() {
|
|
19
31
|
try {
|
|
20
32
|
switch (command) {
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* init
|
|
36
|
+
* Initialize a new local repository.
|
|
37
|
+
*/
|
|
38
|
+
|
|
21
39
|
case 'init':
|
|
22
|
-
console.log(
|
|
40
|
+
console.log(artifact.init(args[0]));
|
|
23
41
|
|
|
24
42
|
break;
|
|
25
43
|
|
|
44
|
+
/**
|
|
45
|
+
* clone
|
|
46
|
+
* Clone an existing repository from a remote source.
|
|
47
|
+
*/
|
|
48
|
+
|
|
26
49
|
case 'clone':
|
|
27
50
|
if (!args[0]) {
|
|
28
51
|
throw new Error('Specify a repository slug (handle/repo).');
|
|
@@ -31,15 +54,27 @@ async function run() {
|
|
|
31
54
|
const tokenIndex = args.indexOf('--token');
|
|
32
55
|
const cliToken = (tokenIndex !== -1) && args[tokenIndex + 1];
|
|
33
56
|
|
|
34
|
-
console.log(
|
|
57
|
+
console.log(
|
|
58
|
+
await artifact.clone(args[0], cliToken)
|
|
59
|
+
);
|
|
35
60
|
|
|
36
61
|
break;
|
|
37
62
|
|
|
63
|
+
/**
|
|
64
|
+
* config
|
|
65
|
+
* Set or update contributor configuration data.
|
|
66
|
+
*/
|
|
67
|
+
|
|
38
68
|
case 'config':
|
|
39
|
-
console.log(
|
|
69
|
+
console.log(artifact.config(args[0], args[1]));
|
|
40
70
|
|
|
41
71
|
break;
|
|
42
72
|
|
|
73
|
+
/**
|
|
74
|
+
* status
|
|
75
|
+
* Display the state of the working directory and the staging area.
|
|
76
|
+
*/
|
|
77
|
+
|
|
43
78
|
case 'status':
|
|
44
79
|
const {
|
|
45
80
|
activeBranch,
|
|
@@ -48,24 +83,33 @@ async function run() {
|
|
|
48
83
|
modified,
|
|
49
84
|
untracked,
|
|
50
85
|
ignored
|
|
51
|
-
} =
|
|
86
|
+
} = artifact.status();
|
|
52
87
|
|
|
53
88
|
console.log(`On branch ${activeBranch}`);
|
|
54
89
|
console.log(`Last commit: ${lastCommit || 'None'}`);
|
|
55
90
|
|
|
56
91
|
if (staged.length > 0) {
|
|
57
92
|
console.log('\nChanges to be committed:');
|
|
58
|
-
|
|
93
|
+
|
|
94
|
+
for (const file of staged) {
|
|
95
|
+
console.log(`${GREEN}\t${file}${RESET}`);
|
|
96
|
+
}
|
|
59
97
|
}
|
|
60
98
|
|
|
61
99
|
if (modified.length > 0) {
|
|
62
100
|
console.log('\nChanges not staged for commit:');
|
|
63
|
-
|
|
101
|
+
|
|
102
|
+
for (const file of modified) {
|
|
103
|
+
console.log(`${RED}\tmodified: ${file}${RESET}`);
|
|
104
|
+
}
|
|
64
105
|
}
|
|
65
106
|
|
|
66
107
|
if (untracked.length > 0) {
|
|
67
108
|
console.log('\nUntracked files:');
|
|
68
|
-
|
|
109
|
+
|
|
110
|
+
for (const file of untracked) {
|
|
111
|
+
console.log(`${RED}\t${file}${RESET}`);
|
|
112
|
+
}
|
|
69
113
|
}
|
|
70
114
|
|
|
71
115
|
if (ignored && ignored.length > 0) {
|
|
@@ -73,16 +117,19 @@ async function run() {
|
|
|
73
117
|
|
|
74
118
|
const compressedIgnored = new Set();
|
|
75
119
|
|
|
76
|
-
|
|
77
|
-
const parts =
|
|
120
|
+
for (const file of ignored) {
|
|
121
|
+
const parts = file.split(path.sep);
|
|
122
|
+
|
|
78
123
|
if (parts.length > 1) {
|
|
79
124
|
compressedIgnored.add(`${parts[0]}${path.sep}`);
|
|
80
125
|
} else {
|
|
81
|
-
compressedIgnored.add(
|
|
126
|
+
compressedIgnored.add(file);
|
|
82
127
|
}
|
|
83
|
-
}
|
|
128
|
+
}
|
|
84
129
|
|
|
85
|
-
|
|
130
|
+
for (const file of compressedIgnored) {
|
|
131
|
+
console.log(`${GRAY}\t${file}${RESET}`);
|
|
132
|
+
}
|
|
86
133
|
}
|
|
87
134
|
|
|
88
135
|
if (untracked.length === 0 && modified.length === 0 && staged.length === 0) {
|
|
@@ -91,77 +138,149 @@ async function run() {
|
|
|
91
138
|
|
|
92
139
|
break;
|
|
93
140
|
|
|
141
|
+
/**
|
|
142
|
+
* add
|
|
143
|
+
* Add file contents to the staging area.
|
|
144
|
+
*/
|
|
145
|
+
|
|
94
146
|
case 'add':
|
|
95
|
-
if (!args[0])
|
|
147
|
+
if (!args[0]) {
|
|
148
|
+
throw new Error('Specify a file path to add.');
|
|
149
|
+
}
|
|
96
150
|
|
|
97
|
-
console.log(
|
|
151
|
+
console.log(artifact.add(args[0]));
|
|
98
152
|
|
|
99
153
|
break;
|
|
100
154
|
|
|
155
|
+
/**
|
|
156
|
+
* commit
|
|
157
|
+
* Record changes to the repository with a descriptive message.
|
|
158
|
+
*/
|
|
159
|
+
|
|
101
160
|
case 'commit':
|
|
102
|
-
if (!args[0])
|
|
103
|
-
|
|
161
|
+
if (!args[0]) {
|
|
162
|
+
throw new Error('Specify a commit message.');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
console.log(artifact.commit(args[0]));
|
|
104
166
|
|
|
105
167
|
break;
|
|
106
168
|
|
|
169
|
+
/**
|
|
170
|
+
* branch
|
|
171
|
+
* List, create, or delete branches.
|
|
172
|
+
*/
|
|
173
|
+
|
|
107
174
|
case 'branch':
|
|
108
175
|
const deleteFlags = ['--delete', '-d', '-D'];
|
|
109
176
|
const isDelete = deleteFlags.includes(args[0]);
|
|
110
177
|
const branchName = isDelete ? args[1] : args[0];
|
|
111
178
|
|
|
112
|
-
const branches =
|
|
179
|
+
const branches = artifact.branch({ name: branchName, isDelete });
|
|
113
180
|
|
|
114
181
|
if (Array.isArray(branches)) {
|
|
115
|
-
for (const
|
|
182
|
+
for (const branch of branches) {
|
|
183
|
+
console.log(branch);
|
|
184
|
+
}
|
|
116
185
|
} else {
|
|
117
186
|
console.log(branches);
|
|
118
187
|
}
|
|
119
188
|
|
|
120
189
|
break;
|
|
121
190
|
|
|
191
|
+
/**
|
|
192
|
+
* checkout
|
|
193
|
+
* Switch branches or restore working tree files.
|
|
194
|
+
*/
|
|
195
|
+
|
|
122
196
|
case 'checkout':
|
|
123
|
-
if (!args[0])
|
|
197
|
+
if (!args[0]) {
|
|
198
|
+
throw new Error('Specify a branch name.');
|
|
199
|
+
}
|
|
124
200
|
|
|
125
|
-
console.log(
|
|
201
|
+
console.log(artifact.checkout(args[0]));
|
|
126
202
|
|
|
127
203
|
break;
|
|
128
204
|
|
|
205
|
+
/**
|
|
206
|
+
* merge
|
|
207
|
+
* Join two or more development histories together.
|
|
208
|
+
*/
|
|
209
|
+
|
|
129
210
|
case 'merge':
|
|
130
|
-
if (!args[0])
|
|
211
|
+
if (!args[0]) {
|
|
212
|
+
throw new Error('Specify a target branch to merge.');
|
|
213
|
+
}
|
|
131
214
|
|
|
132
|
-
console.log(
|
|
215
|
+
console.log(artifact.merge(args[0]));
|
|
133
216
|
|
|
134
217
|
break;
|
|
135
218
|
|
|
219
|
+
/**
|
|
220
|
+
* remote
|
|
221
|
+
* Manage set of tracked repositories.
|
|
222
|
+
*/
|
|
223
|
+
|
|
136
224
|
case 'remote':
|
|
137
|
-
console.log(
|
|
225
|
+
console.log(artifact.remote(args[0]));
|
|
138
226
|
|
|
139
227
|
break;
|
|
140
228
|
|
|
229
|
+
/**
|
|
230
|
+
* fetch
|
|
231
|
+
* Download objects and refs from another repository.
|
|
232
|
+
*/
|
|
233
|
+
|
|
141
234
|
case 'fetch':
|
|
142
|
-
console.log(
|
|
235
|
+
console.log(
|
|
236
|
+
await artifact.fetch()
|
|
237
|
+
);
|
|
143
238
|
|
|
144
239
|
break;
|
|
145
240
|
|
|
241
|
+
/**
|
|
242
|
+
* pull
|
|
243
|
+
* Fetch from and integrate with another repository or a local branch.
|
|
244
|
+
*/
|
|
245
|
+
|
|
146
246
|
case 'pull':
|
|
147
|
-
console.log(
|
|
247
|
+
console.log(
|
|
248
|
+
await artifact.pull()
|
|
249
|
+
);
|
|
148
250
|
|
|
149
251
|
break;
|
|
150
252
|
|
|
253
|
+
/**
|
|
254
|
+
* push
|
|
255
|
+
* Update remote refs along with associated objects.
|
|
256
|
+
*/
|
|
257
|
+
|
|
151
258
|
case 'push':
|
|
152
|
-
console.log(
|
|
259
|
+
console.log(
|
|
260
|
+
await artifact.push()
|
|
261
|
+
);
|
|
153
262
|
|
|
154
|
-
await
|
|
263
|
+
await artifact.fetch()
|
|
155
264
|
|
|
156
265
|
break;
|
|
157
266
|
|
|
267
|
+
/**
|
|
268
|
+
* log
|
|
269
|
+
* Show the commit history logs.
|
|
270
|
+
*/
|
|
271
|
+
|
|
158
272
|
case 'log':
|
|
159
|
-
console.log(
|
|
273
|
+
console.log(artifact.log());
|
|
160
274
|
|
|
161
275
|
break;
|
|
162
276
|
|
|
277
|
+
/**
|
|
278
|
+
* diff
|
|
279
|
+
* Show changes between commits, commit and working tree, etc.
|
|
280
|
+
*/
|
|
281
|
+
|
|
163
282
|
case 'diff':
|
|
164
|
-
const { fileDiffs, staged: diffStaged } =
|
|
283
|
+
const { fileDiffs, staged: diffStaged } = artifact.diff();
|
|
165
284
|
|
|
166
285
|
if (fileDiffs.length === 0 && diffStaged.length === 0) {
|
|
167
286
|
console.log('No changes detected.');
|
|
@@ -169,19 +288,19 @@ async function run() {
|
|
|
169
288
|
break;
|
|
170
289
|
}
|
|
171
290
|
|
|
172
|
-
for (const
|
|
173
|
-
console.log(`diff --art a/${
|
|
291
|
+
for (const diffFile of fileDiffs) {
|
|
292
|
+
console.log(`diff --art a/${diffFile.file} b/${diffFile.file}`);
|
|
174
293
|
|
|
175
|
-
if (
|
|
176
|
-
|
|
294
|
+
if (diffFile.deleted) {
|
|
295
|
+
for (const line of diffFile.deleted.split('\n')) {
|
|
177
296
|
console.log(`${RED}- ${line}${RESET}`);
|
|
178
|
-
}
|
|
297
|
+
}
|
|
179
298
|
}
|
|
180
299
|
|
|
181
|
-
if (
|
|
182
|
-
|
|
300
|
+
if (diffFile.added) {
|
|
301
|
+
for (const line of diffFile.added.split('\n')) {
|
|
183
302
|
console.log(`${GREEN}+ ${line}${RESET}`);
|
|
184
|
-
}
|
|
303
|
+
}
|
|
185
304
|
}
|
|
186
305
|
|
|
187
306
|
console.log('');
|
|
@@ -189,15 +308,23 @@ async function run() {
|
|
|
189
308
|
|
|
190
309
|
if (diffStaged.length > 0) {
|
|
191
310
|
console.log('--- Staged Changes ---');
|
|
192
|
-
|
|
311
|
+
|
|
312
|
+
for (const file of diffStaged) {
|
|
313
|
+
console.log(`staged: ${GREEN}${file}${RESET}`);
|
|
314
|
+
}
|
|
193
315
|
}
|
|
194
316
|
|
|
195
317
|
break;
|
|
196
318
|
|
|
319
|
+
/**
|
|
320
|
+
* stash
|
|
321
|
+
* Stash the changes in a dirty working directory away.
|
|
322
|
+
*/
|
|
323
|
+
|
|
197
324
|
case 'stash':
|
|
198
325
|
const isPop = args[0] === 'pop';
|
|
199
326
|
const isList = args[0] === 'list';
|
|
200
|
-
const result =
|
|
327
|
+
const result = artifact.stash({ pop: isPop, list: isList });
|
|
201
328
|
|
|
202
329
|
if (isList && Array.isArray(result)) {
|
|
203
330
|
if (result.length === 0) {
|
|
@@ -205,8 +332,8 @@ async function run() {
|
|
|
205
332
|
} else {
|
|
206
333
|
console.log('Saved stashes:');
|
|
207
334
|
|
|
208
|
-
for (const
|
|
209
|
-
console.log(`${
|
|
335
|
+
for (const stash of result) {
|
|
336
|
+
console.log(`${stash.id}: WIP on branch: (${stash.date})`);
|
|
210
337
|
}
|
|
211
338
|
}
|
|
212
339
|
} else {
|
|
@@ -215,27 +342,50 @@ async function run() {
|
|
|
215
342
|
|
|
216
343
|
break;
|
|
217
344
|
|
|
345
|
+
/**
|
|
346
|
+
* reset
|
|
347
|
+
* Reset current HEAD to the specified state.
|
|
348
|
+
*/
|
|
349
|
+
|
|
218
350
|
case 'reset':
|
|
219
|
-
console.log(
|
|
351
|
+
console.log(artifact.reset(args[0]));
|
|
220
352
|
|
|
221
353
|
break;
|
|
222
354
|
|
|
355
|
+
/**
|
|
356
|
+
* remove
|
|
357
|
+
* Remove files from the working tree and from the index.
|
|
358
|
+
*/
|
|
359
|
+
|
|
223
360
|
case 'remove':
|
|
224
361
|
case 'rm':
|
|
225
|
-
if (!args[0])
|
|
362
|
+
if (!args[0]) {
|
|
363
|
+
throw new Error('Specify a file path to remove.');
|
|
364
|
+
}
|
|
226
365
|
|
|
227
|
-
console.log(
|
|
366
|
+
console.log(artifact.rm(args[0]));
|
|
228
367
|
|
|
229
368
|
break;
|
|
230
369
|
|
|
370
|
+
/**
|
|
371
|
+
* version
|
|
372
|
+
* Output the current version of the Artifact CLI.
|
|
373
|
+
*/
|
|
374
|
+
|
|
231
375
|
case '--version':
|
|
232
376
|
case '-v':
|
|
233
|
-
console.log(`art version ${
|
|
377
|
+
console.log(`art version ${artifact.version}`);
|
|
234
378
|
|
|
235
379
|
break;
|
|
236
380
|
|
|
381
|
+
/**
|
|
382
|
+
* help
|
|
383
|
+
* Display help information about Artifact commands.
|
|
384
|
+
*/
|
|
385
|
+
|
|
386
|
+
case 'help':
|
|
237
387
|
default:
|
|
238
|
-
console.log('Usage: art <command> [
|
|
388
|
+
console.log('Usage: art <command> [args]');
|
|
239
389
|
console.log('Available commands: init, clone, status, add, commit, branch, checkout, merge, remote, fetch, pull, push, log, diff, stash, reset, rm');
|
|
240
390
|
}
|
|
241
391
|
} catch (error) {
|
|
@@ -244,4 +394,6 @@ async function run() {
|
|
|
244
394
|
}
|
|
245
395
|
}
|
|
246
396
|
|
|
397
|
+
// Execute the command line interface
|
|
398
|
+
|
|
247
399
|
run();
|