watskeburt 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +9 -2
- package/dist/cjs-bundle.js +1 -1
- package/package.json +1 -1
- package/src/cli.mjs +6 -4
- package/src/git-primitives.mjs +14 -3
- package/src/main.mjs +4 -2
- package/src/version.mjs +1 -1
- package/types/watskeburt.d.ts +3 -0
package/README.md
CHANGED
@@ -35,9 +35,16 @@ console.log(getSHASync());
|
|
35
35
|
/** @type {import('watskeburt').IChange[]} */
|
36
36
|
const lChangedFiles = listSync("main");
|
37
37
|
|
38
|
-
//
|
38
|
+
// list all files that differ between 'v0.6.1' and 'v0.7.1' (by definition
|
39
|
+
// won't include files staged for commit and/ or not under revision control)
|
40
|
+
/** @type {import('watskeburt').IChange[]} */
|
41
|
+
const lChangedFiles = listSync("v0.6.1", "v0.7.1");
|
42
|
+
|
43
|
+
// As a third parameter you can pass some options
|
44
|
+
// (pass null as the second parameter if you only want to compare between
|
45
|
+
// a revision and the working tree):
|
39
46
|
/** @type {import('watskeburt').IChange[]|string} */
|
40
|
-
const lChangedFiles = listSync("main", {
|
47
|
+
const lChangedFiles = listSync("main", null, {
|
41
48
|
trackedOnly: false, // when set to true leaves out files not under revision control
|
42
49
|
outputType: "object", // other options: "json" and "regex" (as used in the CLI)
|
43
50
|
});
|
package/dist/cjs-bundle.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";var
|
1
|
+
"use strict";var i=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var _=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},D=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of C(t))!A.call(e,o)&&o!==n&&i(e,o,{get:()=>t[o],enumerable:!(r=x(t,o))||r.enumerable});return e};var L=e=>D(i({},"__esModule",{value:!0}),e);var P={};_(P,{getSHASync:()=>k,listSync:()=>F});module.exports=L(P);var c=require("os"),R=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,O=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,U={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function u(e){return U[e]||"unknown"}function $(e){let t=e.match(O),n={};if(t){let r=u(t.groups.stagedChangeType),o=u(t.groups.unStagedChangeType);n.changeType=r==="unmodified"?o:r,t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name}return n}function v(e){let t=e.match(R),n={};return t&&(n.changeType=u(t.groups.changeType),t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name),n}function T(e){return e.split(c.EOL).filter(Boolean).map($).filter(({changeType:t})=>Boolean(t))}function S(e){return e.split(c.EOL).filter(Boolean).map(v).filter(({changeType:t})=>Boolean(t))}var a=require("child_process");function h(e){return e instanceof Buffer?e.toString("utf8"):e}function M(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}function f(e,t,n){let r=n("git",e,{cwd:process.cwd(),env:process.env});if(r.error&&M(r.error),r.status===0)return h(r.stdout);throw new Error(t[r.status]||`internal git error: ${r.status} (${h(r.stderr)})`)}function N(e=a.spawnSync){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return f(["status","--porcelain"],t,e)}function y(e,t,n=a.spawnSync){let r={128:`revision '${e}' ${t?`(or '${t}') `:""}unknown`,129:`'${process.cwd()}' does not seem to be a git repository`};return f(t?["diff",e,t,"--name-status"]:["diff",e,"--name-status"],r,n)}function l(e=a.spawnSync){return f(["rev-parse","HEAD"],{},e).slice(0,40)}var E=require("path"),B=new Set([".cjs",".cjsx",".coffee",".csx",".js",".json",".jsx",".litcoffee",".ls",".mjs",".svelte",".ts",".tsx",".vue",".vuex"]),H=new Set(["modified","added","renamed","copied","untracked"]);function p(e,t=B,n=H){return`^(${e.filter(o=>n.has(o.changeType)).map(({name:o})=>o).filter(o=>t.has((0,E.extname)(o))).join("|")})$`}function m(e){return JSON.stringify(e,null,2)}var j=e=>e,I=new Map([["regex",p],["json",m]]);function g(e,t){return(I.get(t)||j)(e)}function k(){return l()}function F(e,t,n){let r=e||l(),o=t||null,d=n||{},s=S(y(r,o));return d.trackedOnly||(s=s.concat(T(N()).filter(({changeType:w})=>w==="untracked"))),g(s,d.outputType)}0&&(module.exports={getSHASync,listSync});
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
@@ -7,17 +7,19 @@ import { VERSION } from "./version.mjs";
|
|
7
7
|
|
8
8
|
program
|
9
9
|
.description(
|
10
|
-
"lists files & their statuses since [revision]
|
11
|
-
"
|
10
|
+
"lists files & their statuses since [old-revision] " +
|
11
|
+
"or between [old-revision] and [new-revision]." +
|
12
|
+
"\n\n" +
|
13
|
+
"-> When you don't pass a revision at all old-revision defaults to the current one."
|
12
14
|
)
|
13
15
|
.version(VERSION)
|
14
16
|
.option("-T, --output-type <type>", "json,regex", "regex")
|
15
17
|
.option("--tracked-only", "only take tracked files into account", false)
|
16
|
-
.arguments("[revision]")
|
18
|
+
.arguments("[old-revision] [new-revision]")
|
17
19
|
.parse(process.argv);
|
18
20
|
|
19
21
|
try {
|
20
|
-
console.log(listSync(program.args[0], program.opts()));
|
22
|
+
console.log(listSync(program.args[0], program.args[1], program.opts()));
|
21
23
|
} catch (pError) {
|
22
24
|
console.error(`ERROR: ${pError.message}`);
|
23
25
|
}
|
package/src/git-primitives.mjs
CHANGED
@@ -60,16 +60,27 @@ export function getStatusShort(pSpawnFunction = spawnSync) {
|
|
60
60
|
/**
|
61
61
|
*
|
62
62
|
* @param {string} pOldRevision the target to compare against (e.g. branch name, commit, tag etc)
|
63
|
+
* @param {string} pNewRevision Newer revision against which to compare. Leave out or pass
|
64
|
+
* null when you want to compare against the working tree
|
63
65
|
* @return {string}
|
64
66
|
* @throws {Error}
|
65
67
|
*/
|
66
|
-
export function getDiffLines(
|
68
|
+
export function getDiffLines(
|
69
|
+
pOldRevision,
|
70
|
+
pNewRevision,
|
71
|
+
pSpawnFunction = spawnSync
|
72
|
+
) {
|
67
73
|
const lErrorMap = {
|
68
|
-
128: `revision '${pOldRevision}'
|
74
|
+
128: `revision '${pOldRevision}' ${
|
75
|
+
pNewRevision ? `(or '${pNewRevision}') ` : ""
|
76
|
+
}unknown`,
|
69
77
|
129: `'${process.cwd()}' does not seem to be a git repository`,
|
70
78
|
};
|
79
|
+
|
71
80
|
return getGitResult(
|
72
|
-
|
81
|
+
pNewRevision
|
82
|
+
? ["diff", pOldRevision, pNewRevision, "--name-status"]
|
83
|
+
: ["diff", pOldRevision, "--name-status"],
|
73
84
|
lErrorMap,
|
74
85
|
pSpawnFunction
|
75
86
|
);
|
package/src/main.mjs
CHANGED
@@ -11,11 +11,13 @@ export function getSHASync() {
|
|
11
11
|
}
|
12
12
|
|
13
13
|
/** @type {import("../types/watskeburt").listSync} */
|
14
|
-
export function listSync(pOldRevision, pOptions) {
|
14
|
+
export function listSync(pOldRevision, pNewRevision, pOptions) {
|
15
15
|
const lOldRevision = pOldRevision || getSHA1();
|
16
|
-
|
16
|
+
const lNewRevision = pNewRevision || null;
|
17
17
|
const lOptions = pOptions || {};
|
18
18
|
|
19
|
+
let lChanges = convertDiffLines(getDiffLines(lOldRevision, lNewRevision));
|
20
|
+
|
19
21
|
if (!lOptions.trackedOnly) {
|
20
22
|
lChanges = lChanges.concat(
|
21
23
|
convertStatusLines(getStatusShort()).filter(
|
package/src/version.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "0.
|
1
|
+
export const VERSION = "0.7.0";
|
package/types/watskeburt.d.ts
CHANGED
@@ -50,12 +50,15 @@ export interface IOptions {
|
|
50
50
|
* @param pOldRevision The revision against which to compare. E.g. a commit-hash,
|
51
51
|
* a branch or a tag. When not passed defaults to the _current_
|
52
52
|
* commit hash (if there's any)
|
53
|
+
* @param pNewRevision Newer revision against which to compare. Leave out or pass
|
54
|
+
* null when you want to compare against the working tree
|
53
55
|
* @param pOptions Options that influence how the changes are returned and that
|
54
56
|
* filter what is returned and
|
55
57
|
* @throws {Error}
|
56
58
|
*/
|
57
59
|
export function listSync(
|
58
60
|
pOldRevision?: string,
|
61
|
+
pNewRevision?: string,
|
59
62
|
pOptions?: IOptions
|
60
63
|
): IChange[] | string;
|
61
64
|
|