watskeburt 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +8 -8
- package/dist/cjs-bundle.js +1 -1
- package/package.json +4 -2
- package/src/cli.mjs +9 -10
- package/src/convert-to-change-object.mjs +0 -6
- package/src/main.mjs +7 -6
- package/src/version.mjs +1 -1
- package/types/watskeburt.d.ts +4 -7
package/README.md
CHANGED
@@ -40,16 +40,17 @@ source files in the JavaScript ecosystem (.js, .mjs, .ts, .tsx ...) that can
|
|
40
40
|
be used in e.g. the `--focus` filter of dependency-cruiser:
|
41
41
|
|
42
42
|
```
|
43
|
-
Usage: cli [options]
|
43
|
+
Usage: cli [options] [revision]
|
44
44
|
|
45
|
-
lists files & their statuses since
|
45
|
+
lists files & their statuses since [revision].
|
46
46
|
|
47
|
-
|
48
|
-
-V, --version output the version number
|
49
|
-
-T, --output-type <type> json,regex (default: "regex")
|
50
|
-
--tracked-only only take tracked files into account (default: false)
|
51
|
-
-h, --help display help for command
|
47
|
+
-> When you don't pass a revision the revision defaults to the current one.
|
52
48
|
|
49
|
+
Options:
|
50
|
+
-V, --version output the version number
|
51
|
+
-T, --output-type <type> json,regex (default: "regex")
|
52
|
+
--tracked-only only take tracked files into account (default: false)
|
53
|
+
-h, --help display help for command
|
53
54
|
```
|
54
55
|
|
55
56
|
### :scroll: API
|
@@ -75,7 +76,6 @@ An array of changes looks something like this:
|
|
75
76
|
name: "test/thing.spec.mjs",
|
76
77
|
changeType: "renamed",
|
77
78
|
oldName: "test/old-thing.spec.mjs",
|
78
|
-
similarity: 66,
|
79
79
|
},
|
80
80
|
{ name: "src/not-tracked-yet.mjs", changeType: "untracked" },
|
81
81
|
];
|
package/dist/cjs-bundle.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var
|
1
|
+
var s=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var n in t)s(e,n,{get:t[n],enumerable:!0})},_=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of E(t))!C.call(e,o)&&o!==n&&s(e,o,{get:()=>t[o],enumerable:!(r=x(t,o))||r.enumerable});return e};var R=e=>_(s({},"__esModule",{value:!0}),e);var H={};A(H,{getSHA:()=>w,list:()=>M});module.exports=R(H);var u=require("os"),D=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,L=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,O={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function i(e){return O[e]||"unknown"}function U(e){let t=e.match(L),n={};if(t){let r=i(t.groups.stagedChangeType),o=i(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(D),n={};return t&&(n.changeType=i(t.groups.changeType),t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name),n}function m(e){return e.split(u.EOL).filter(Boolean).map(U).filter(({changeType:t})=>Boolean(t))}function g(e){return e.split(u.EOL).filter(Boolean).map(v).filter(({changeType:t})=>Boolean(t))}var a=require("child_process");function d(e){return e instanceof Buffer?e.toString("utf8"):e}function $(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}function c(e,t,n){let r=n("git",e,{cwd:process.cwd(),env:process.env});if(r.error&&$(r.error),r.status===0)return d(r.stdout);throw new Error(t[r.status]||`internal git error: ${r.status} (${d(r.stderr)})`)}function T(e=a.spawnSync){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return c(["status","--porcelain"],t,e)}function h(e,t=a.spawnSync){let n={128:`revision '${e}' unknown `,129:`'${process.cwd()}' does not seem to be a git repository`};return c(["diff",e,"--name-status"],n,t)}function S(e=a.spawnSync){return c(["rev-parse","HEAD"],{},e).slice(0,40)}var N=require("path");function f(e,t=[".js",".jsx",".mjs",".cjs",".ts",".tsx",".vue",".vuex",".json"],n=["modified","added","renamed","copied","untracked"]){return`^(${e.filter(o=>n.includes(o.changeType)).map(({name:o})=>o).filter(o=>t.includes((0,N.extname)(o))).join("|")})$`}function p(e){return JSON.stringify(e,null,2)}var j={regex:f,json:p,object:e=>e},B="object";function l(e,t){return j[t||B](e)}function w(){return S()}function M(e,t){let n=e||w(),r=g(h(n)),o=t||{};return o.trackedOnly||(r=r.concat(m(T()).filter(({changeType:y})=>y==="untracked"))),l(r,o.outputType)}0&&(module.exports={getSHA,list});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "watskeburt",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.4.0",
|
4
4
|
"description": "List files changed since a git revision",
|
5
5
|
"keywords": [
|
6
6
|
"git",
|
@@ -62,7 +62,8 @@
|
|
62
62
|
"eslint-plugin-unicorn": "^43.0.1",
|
63
63
|
"mocha": "^10.0.0",
|
64
64
|
"npm-run-all": "^4.1.5",
|
65
|
-
"prettier": "^2.7.1"
|
65
|
+
"prettier": "^2.7.1",
|
66
|
+
"typescript": "^4.7.4"
|
66
67
|
},
|
67
68
|
"engines": {
|
68
69
|
"node": "^12.20||^14||>=16"
|
@@ -71,6 +72,7 @@
|
|
71
72
|
"build": "npm-run-all --sequential build:version build:dist",
|
72
73
|
"build:version": "node tools/get-version.mjs > src/version.mjs",
|
73
74
|
"build:dist": "esbuild src/main.mjs --format=cjs --target=node12 --platform=node --bundle --global-name=wkbtcjs --minify --outfile=dist/cjs-bundle.js",
|
75
|
+
"check": "npm-run-all --parallel --aggregate-output lint depcruise test:cover",
|
74
76
|
"clean": "rm -rf dist",
|
75
77
|
"test": "mocha \"src/**/*.spec.mjs\"",
|
76
78
|
"test:cover": "c8 --check-coverage --statements 100 --branches 100 --functions 100 --lines 100 --exclude \"**/*.spec.mjs\" --reporter text-summary --reporter html --reporter json-summary npm test",
|
package/src/cli.mjs
CHANGED
@@ -6,19 +6,18 @@ import { list } from "./main.mjs";
|
|
6
6
|
import { VERSION } from "./version.mjs";
|
7
7
|
|
8
8
|
program
|
9
|
-
.description(
|
9
|
+
.description(
|
10
|
+
"lists files & their statuses since [revision].\n\n" +
|
11
|
+
"-> When you don't pass a revision the revision defaults to the current one."
|
12
|
+
)
|
10
13
|
.version(VERSION)
|
11
14
|
.option("-T, --output-type <type>", "json,regex", "regex")
|
12
15
|
.option("--tracked-only", "only take tracked files into account", false)
|
13
|
-
.arguments("
|
16
|
+
.arguments("[revision]")
|
14
17
|
.parse(process.argv);
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
console.error(`ERROR: ${pError.message}`);
|
21
|
-
}
|
22
|
-
} else {
|
23
|
-
program.help();
|
19
|
+
try {
|
20
|
+
console.log(list(program.args[0], program.opts()));
|
21
|
+
} catch (pError) {
|
22
|
+
console.error(`ERROR: ${pError.message}`);
|
24
23
|
}
|
@@ -76,12 +76,6 @@ export function convertDiffLine(pString) {
|
|
76
76
|
lReturnValue.changeType = changeChar2ChangeType(
|
77
77
|
lMatchResult.groups.changeType
|
78
78
|
);
|
79
|
-
if (lMatchResult.groups.similarity) {
|
80
|
-
lReturnValue.similarity = Number.parseInt(
|
81
|
-
lMatchResult.groups.similarity,
|
82
|
-
10
|
83
|
-
);
|
84
|
-
}
|
85
79
|
if (lMatchResult.groups.newName) {
|
86
80
|
lReturnValue.name = lMatchResult.groups.newName;
|
87
81
|
lReturnValue.oldName = lMatchResult.groups.name;
|
package/src/main.mjs
CHANGED
@@ -5,9 +5,15 @@ import {
|
|
5
5
|
import { getDiffLines, getSHA1, getStatusShort } from "./git-primitives.mjs";
|
6
6
|
import format from "./formatters/format.mjs";
|
7
7
|
|
8
|
+
/** @type {import("../types/watskeburt.js").getSHA} */
|
9
|
+
export function getSHA() {
|
10
|
+
return getSHA1();
|
11
|
+
}
|
12
|
+
|
8
13
|
/** @type {import("../types/watskeburt.js").list} */
|
9
14
|
export function list(pOldRevision, pOptions) {
|
10
|
-
|
15
|
+
const lOldRevision = pOldRevision || getSHA();
|
16
|
+
let lChanges = convertDiffLines(getDiffLines(lOldRevision));
|
11
17
|
const lOptions = pOptions || {};
|
12
18
|
|
13
19
|
if (!lOptions.trackedOnly) {
|
@@ -19,8 +25,3 @@ export function list(pOldRevision, pOptions) {
|
|
19
25
|
}
|
20
26
|
return format(lChanges, lOptions.outputType);
|
21
27
|
}
|
22
|
-
|
23
|
-
/** @type {import("../types/watskeburt.js").getSHA} */
|
24
|
-
export function getSHA() {
|
25
|
-
return getSHA1();
|
26
|
-
}
|
package/src/version.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "0.
|
1
|
+
export const VERSION = "0.4.0";
|
package/types/watskeburt.d.ts
CHANGED
@@ -21,10 +21,6 @@ export interface IChange {
|
|
21
21
|
* how the file was changed
|
22
22
|
*/
|
23
23
|
changeType: changeTypeType;
|
24
|
-
/**
|
25
|
-
* if the file was renamed: the % of similarity (range: 0 - 100)
|
26
|
-
*/
|
27
|
-
similarity?: Number;
|
28
24
|
/**
|
29
25
|
* if the file was renamed: what the old file's name was
|
30
26
|
*/
|
@@ -52,14 +48,15 @@ export interface IOptions {
|
|
52
48
|
* returns a list of files changed since pOldRevision.
|
53
49
|
*
|
54
50
|
* @param pOldRevision the revision against which to compare. E.g. a commit-hash,
|
55
|
-
* a branch or a tag.
|
51
|
+
* a branch or a tag. When not passed defaults to the _current_
|
52
|
+
* commit hash (if there's any)
|
56
53
|
* @param pOptions Options that influence how the changes are returned and that
|
57
54
|
* filter what is returned and
|
58
55
|
* @throws {Error}
|
59
56
|
*/
|
60
57
|
export function list(
|
61
|
-
pOldRevision
|
62
|
-
pOptions
|
58
|
+
pOldRevision?: string,
|
59
|
+
pOptions?: IOptions
|
63
60
|
): IChange[] | string;
|
64
61
|
|
65
62
|
/**
|