pagan-artifact 0.3.2 → 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 CHANGED
@@ -1,45 +1,80 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * art - Modern version control.
5
- * CLI (v0.3.2)
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 art = require('../index.js');
10
+ const artifact = require('../index.js');
9
11
  const path = require('path');
10
12
 
11
- const [,, command, ...args] = process.argv;
13
+ /**
14
+ * Extract command line arguments
15
+ */
16
+
17
+ const [,, command, ...arguments] = process.argv;
18
+
19
+ /**
20
+ * Console text color constants
21
+ */
12
22
 
13
- const RED = '\x1b[31m';
14
- const GREEN = '\x1b[32m';
15
- const RESET = '\x1b[0m';
16
- const GRAY = '\x1b[90m';
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(art.init(args[0]));
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 (!args[0]) {
50
+ if (!arguments[0]) {
28
51
  throw new Error('Specify a repository slug (handle/repo).');
29
52
  }
30
53
 
31
- const tokenIndex = args.indexOf('--token');
32
- const cliToken = (tokenIndex !== -1) && args[tokenIndex + 1];
54
+ const tokenIndex = arguments.indexOf('--token');
55
+ const cliToken = (tokenIndex !== -1) && arguments[tokenIndex + 1];
33
56
 
34
- console.log(await art.clone(args[0], cliToken));
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(art.config(args[0], args[1]));
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
- } = art.status();
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
- staged.forEach(f => console.log(`${GREEN}\t${f}${RESET}`));
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
- modified.forEach(f => console.log(`${RED}\tmodified: ${f}${RESET}`));
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
- untracked.forEach(f => console.log(`${RED}\t${f}${RESET}`));
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
- ignored.forEach(f => {
77
- const parts = f.split(path.sep);
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(f);
126
+ compressedIgnored.add(file);
82
127
  }
83
- });
128
+ }
84
129
 
85
- compressedIgnored.forEach(f => console.log(`${GRAY}\t${f}${RESET}`));
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]) throw new Error('Specify a file path to add.');
147
+ if (!arguments[0]) {
148
+ throw new Error('Specify a file path to add.');
149
+ }
96
150
 
97
- console.log(art.add(args[0]));
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 (!args[0]) throw new Error('Specify a commit message.');
103
- console.log(art.commit(args[0]));
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(args[0]);
110
- const branchName = isDelete ? args[1] : args[0];
176
+ const isDelete = deleteFlags.includes(arguments[0]);
177
+ const branchName = isDelete ? arguments[1] : arguments[0];
111
178
 
112
- const branches = art.branch({ name: branchName, isDelete });
179
+ const branches = artifact.branch({ name: branchName, isDelete });
113
180
 
114
181
  if (Array.isArray(branches)) {
115
- for (const b of branches) console.log(b);
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]) throw new Error('Specify a branch name.');
197
+ if (!arguments[0]) {
198
+ throw new Error('Specify a branch name.');
199
+ }
124
200
 
125
- console.log(art.checkout(args[0]));
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 (!args[0]) throw new Error('Specify a target branch to merge.');
211
+ if (!arguments[0]) {
212
+ throw new Error('Specify a target branch to merge.');
213
+ }
131
214
 
132
- console.log(art.merge(args[0]));
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(art.remote(args[0]));
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(await art.fetch());
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(await art.pull());
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(await art.push());
259
+ console.log(
260
+ await artifact.push()
261
+ );
153
262
 
154
- await art.fetch()
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(art.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 } = art.diff();
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 df of fileDiffs) {
173
- console.log(`diff --art a/${df.file} b/${df.file}`);
291
+ for (const diffFile of fileDiffs) {
292
+ console.log(`diff --art a/${diffFile.file} b/${diffFile.file}`);
174
293
 
175
- if (df.deleted) {
176
- df.deleted.split('\n').forEach(line => {
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 (df.added) {
182
- df.added.split('\n').forEach(line => {
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
- diffStaged.forEach(f => console.log(`staged: ${GREEN}${f}${RESET}`));
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
- const isPop = args[0] === 'pop';
199
- const isList = args[0] === 'list';
200
- const result = art.stash({ pop: isPop, list: isList });
325
+ const isPop = arguments[0] === 'pop';
326
+ const isList = arguments[0] === 'list';
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 s of result) {
209
- console.log(`${s.id}: WIP on branch: (${s.date})`);
335
+ for (const stash of result) {
336
+ console.log(`${stash.id}: WIP on branch: (${stash.date})`);
210
337
  }
211
338
  }
212
339
  } else {
@@ -215,25 +342,48 @@ 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(art.reset(args[0]));
351
+ console.log(artifact.reset(arguments[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]) throw new Error('Specify a file path to remove.');
362
+ if (!arguments[0]) {
363
+ throw new Error('Specify a file path to remove.');
364
+ }
226
365
 
227
- console.log(art.rm(args[0]));
366
+ console.log(artifact.rm(arguments[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 ${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
388
  console.log('Usage: art <command> [arguments]');
239
389
  console.log('Available commands: init, clone, status, add, commit, branch, checkout, merge, remote, fetch, pull, push, log, diff, stash, reset, rm');
@@ -244,4 +394,6 @@ async function run() {
244
394
  }
245
395
  }
246
396
 
397
+ // Execute the command line interface
398
+
247
399
  run();