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/bin/art.js
CHANGED
|
@@ -1,45 +1,80 @@
|
|
|
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.3)
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
|
-
const
|
|
10
|
+
const artifact = require('../index.js');
|
|
9
11
|
const path = require('path');
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Extract command line arguments
|
|
15
|
+
*/
|
|
12
16
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
const [,, command, ...arguments] = process.argv;
|
|
18
|
+
|
|
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(arguments[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
|
-
if (!
|
|
50
|
+
if (!arguments[0]) {
|
|
28
51
|
throw new Error('Specify a repository slug (handle/repo).');
|
|
29
52
|
}
|
|
30
53
|
|
|
31
|
-
const tokenIndex =
|
|
32
|
-
const cliToken = (tokenIndex !== -1) &&
|
|
54
|
+
const tokenIndex = arguments.indexOf('--token');
|
|
55
|
+
const cliToken = (tokenIndex !== -1) && arguments[tokenIndex + 1];
|
|
33
56
|
|
|
34
|
-
console.log(
|
|
57
|
+
console.log(
|
|
58
|
+
await artifact.clone(arguments[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(arguments[0], arguments[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,75 +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 (!
|
|
147
|
+
if (!arguments[0]) {
|
|
148
|
+
throw new Error('Specify a file path to add.');
|
|
149
|
+
}
|
|
96
150
|
|
|
97
|
-
console.log(
|
|
151
|
+
console.log(artifact.add(arguments[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 (!
|
|
103
|
-
|
|
161
|
+
if (!arguments[0]) {
|
|
162
|
+
throw new Error('Specify a commit message.');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
console.log(artifact.commit(arguments[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
|
-
const isDelete = deleteFlags.includes(
|
|
110
|
-
const branchName = isDelete ?
|
|
176
|
+
const isDelete = deleteFlags.includes(arguments[0]);
|
|
177
|
+
const branchName = isDelete ? arguments[1] : arguments[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 (!
|
|
197
|
+
if (!arguments[0]) {
|
|
198
|
+
throw new Error('Specify a branch name.');
|
|
199
|
+
}
|
|
124
200
|
|
|
125
|
-
console.log(
|
|
201
|
+
console.log(artifact.checkout(arguments[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 (!
|
|
211
|
+
if (!arguments[0]) {
|
|
212
|
+
throw new Error('Specify a target branch to merge.');
|
|
213
|
+
}
|
|
131
214
|
|
|
132
|
-
console.log(
|
|
215
|
+
console.log(artifact.merge(arguments[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(arguments[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
|
+
);
|
|
262
|
+
|
|
263
|
+
await artifact.fetch()
|
|
153
264
|
|
|
154
265
|
break;
|
|
155
266
|
|
|
267
|
+
/**
|
|
268
|
+
* log
|
|
269
|
+
* Show the commit history logs.
|
|
270
|
+
*/
|
|
271
|
+
|
|
156
272
|
case 'log':
|
|
157
|
-
console.log(
|
|
273
|
+
console.log(artifact.log());
|
|
158
274
|
|
|
159
275
|
break;
|
|
160
276
|
|
|
277
|
+
/**
|
|
278
|
+
* diff
|
|
279
|
+
* Show changes between commits, commit and working tree, etc.
|
|
280
|
+
*/
|
|
281
|
+
|
|
161
282
|
case 'diff':
|
|
162
|
-
const { fileDiffs, staged: diffStaged } =
|
|
283
|
+
const { fileDiffs, staged: diffStaged } = artifact.diff();
|
|
163
284
|
|
|
164
285
|
if (fileDiffs.length === 0 && diffStaged.length === 0) {
|
|
165
286
|
console.log('No changes detected.');
|
|
@@ -167,19 +288,19 @@ async function run() {
|
|
|
167
288
|
break;
|
|
168
289
|
}
|
|
169
290
|
|
|
170
|
-
for (const
|
|
171
|
-
console.log(`diff --art a/${
|
|
291
|
+
for (const diffFile of fileDiffs) {
|
|
292
|
+
console.log(`diff --art a/${diffFile.file} b/${diffFile.file}`);
|
|
172
293
|
|
|
173
|
-
if (
|
|
174
|
-
|
|
294
|
+
if (diffFile.deleted) {
|
|
295
|
+
for (const line of diffFile.deleted.split('\n')) {
|
|
175
296
|
console.log(`${RED}- ${line}${RESET}`);
|
|
176
|
-
}
|
|
297
|
+
}
|
|
177
298
|
}
|
|
178
299
|
|
|
179
|
-
if (
|
|
180
|
-
|
|
300
|
+
if (diffFile.added) {
|
|
301
|
+
for (const line of diffFile.added.split('\n')) {
|
|
181
302
|
console.log(`${GREEN}+ ${line}${RESET}`);
|
|
182
|
-
}
|
|
303
|
+
}
|
|
183
304
|
}
|
|
184
305
|
|
|
185
306
|
console.log('');
|
|
@@ -187,15 +308,23 @@ async function run() {
|
|
|
187
308
|
|
|
188
309
|
if (diffStaged.length > 0) {
|
|
189
310
|
console.log('--- Staged Changes ---');
|
|
190
|
-
|
|
311
|
+
|
|
312
|
+
for (const file of diffStaged) {
|
|
313
|
+
console.log(`staged: ${GREEN}${file}${RESET}`);
|
|
314
|
+
}
|
|
191
315
|
}
|
|
192
316
|
|
|
193
317
|
break;
|
|
194
318
|
|
|
319
|
+
/**
|
|
320
|
+
* stash
|
|
321
|
+
* Stash the changes in a dirty working directory away.
|
|
322
|
+
*/
|
|
323
|
+
|
|
195
324
|
case 'stash':
|
|
196
|
-
const isPop =
|
|
197
|
-
const isList =
|
|
198
|
-
const result =
|
|
325
|
+
const isPop = arguments[0] === 'pop';
|
|
326
|
+
const isList = arguments[0] === 'list';
|
|
327
|
+
const result = artifact.stash({ pop: isPop, list: isList });
|
|
199
328
|
|
|
200
329
|
if (isList && Array.isArray(result)) {
|
|
201
330
|
if (result.length === 0) {
|
|
@@ -203,8 +332,8 @@ async function run() {
|
|
|
203
332
|
} else {
|
|
204
333
|
console.log('Saved stashes:');
|
|
205
334
|
|
|
206
|
-
for (const
|
|
207
|
-
console.log(`${
|
|
335
|
+
for (const stash of result) {
|
|
336
|
+
console.log(`${stash.id}: WIP on branch: (${stash.date})`);
|
|
208
337
|
}
|
|
209
338
|
}
|
|
210
339
|
} else {
|
|
@@ -213,25 +342,48 @@ async function run() {
|
|
|
213
342
|
|
|
214
343
|
break;
|
|
215
344
|
|
|
345
|
+
/**
|
|
346
|
+
* reset
|
|
347
|
+
* Reset current HEAD to the specified state.
|
|
348
|
+
*/
|
|
349
|
+
|
|
216
350
|
case 'reset':
|
|
217
|
-
console.log(
|
|
351
|
+
console.log(artifact.reset(arguments[0]));
|
|
218
352
|
|
|
219
353
|
break;
|
|
220
354
|
|
|
355
|
+
/**
|
|
356
|
+
* remove
|
|
357
|
+
* Remove files from the working tree and from the index.
|
|
358
|
+
*/
|
|
359
|
+
|
|
221
360
|
case 'remove':
|
|
222
361
|
case 'rm':
|
|
223
|
-
if (!
|
|
362
|
+
if (!arguments[0]) {
|
|
363
|
+
throw new Error('Specify a file path to remove.');
|
|
364
|
+
}
|
|
224
365
|
|
|
225
|
-
console.log(
|
|
366
|
+
console.log(artifact.rm(arguments[0]));
|
|
226
367
|
|
|
227
368
|
break;
|
|
228
369
|
|
|
370
|
+
/**
|
|
371
|
+
* version
|
|
372
|
+
* Output the current version of the Artifact CLI.
|
|
373
|
+
*/
|
|
374
|
+
|
|
229
375
|
case '--version':
|
|
230
376
|
case '-v':
|
|
231
|
-
console.log(`art version ${
|
|
377
|
+
console.log(`art version ${artifact.version}`);
|
|
232
378
|
|
|
233
379
|
break;
|
|
234
380
|
|
|
381
|
+
/**
|
|
382
|
+
* help
|
|
383
|
+
* Display help information about Artifact commands.
|
|
384
|
+
*/
|
|
385
|
+
|
|
386
|
+
case 'help':
|
|
235
387
|
default:
|
|
236
388
|
console.log('Usage: art <command> [arguments]');
|
|
237
389
|
console.log('Available commands: init, clone, status, add, commit, branch, checkout, merge, remote, fetch, pull, push, log, diff, stash, reset, rm');
|
|
@@ -242,4 +394,6 @@ async function run() {
|
|
|
242
394
|
}
|
|
243
395
|
}
|
|
244
396
|
|
|
397
|
+
// Execute the command line interface
|
|
398
|
+
|
|
245
399
|
run();
|