watskeburt 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +1 -1
- package/README.md +5 -5
- package/dist/cjs-bundle.js +1 -1
- package/package.json +1 -1
- package/src/cli.mjs +2 -2
- package/src/main.mjs +5 -5
- package/src/version.mjs +1 -1
- package/types/watskeburt.d.ts +4 -4
package/LICENSE
CHANGED
package/README.md
CHANGED
@@ -24,20 +24,20 @@ but for just this simple usage they're a bit overkill.
|
|
24
24
|
### :scroll: API
|
25
25
|
|
26
26
|
```javascript
|
27
|
-
// const {
|
28
|
-
import {
|
27
|
+
// const { listSync, getSHASync } = require("watskeburt"); // in commonjs contexts you can also require it
|
28
|
+
import { listSync, getSHASync } from "watskeburt";
|
29
29
|
|
30
30
|
// print the SHA1 of the current HEAD
|
31
|
-
console.log(
|
31
|
+
console.log(getSHASync());
|
32
32
|
|
33
33
|
// list all files that differ between 'main' and the current revision (including
|
34
34
|
// files not staged for commit and files not under revision control)
|
35
35
|
/** @type {import('watskeburt').IChange[]} */
|
36
|
-
const lChangedFiles =
|
36
|
+
const lChangedFiles = listSync("main");
|
37
37
|
|
38
38
|
// As a second parameter you can pass some options:
|
39
39
|
/** @type {import('watskeburt').IChange[]|string} */
|
40
|
-
const lChangedFiles =
|
40
|
+
const lChangedFiles = listSync("main", {
|
41
41
|
trackedOnly: false, // when set to true leaves out files not under revision control
|
42
42
|
outputType: "object", // other options: "json" and "regex" (as used in the CLI)
|
43
43
|
});
|
package/dist/cjs-bundle.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";var a=Object.defineProperty;var
|
1
|
+
"use strict";var a=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},C=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of y(t))!x.call(e,r)&&r!==n&&a(e,r,{get:()=>t[r],enumerable:!(o=w(t,r))||o.enumerable});return e};var _=e=>C(a({},"__esModule",{value:!0}),e);var I={};A(I,{getSHASync:()=>M,listSync:()=>F});module.exports=_(I);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]+))?$/,R={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 R[e]||"unknown"}function U(e){let t=e.match(L),n={};if(t){let o=i(t.groups.stagedChangeType),r=i(t.groups.unStagedChangeType);n.changeType=o==="unmodified"?r:o,t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name}return n}function O(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 g(e){return e.split(u.EOL).filter(Boolean).map(U).filter(({changeType:t})=>Boolean(t))}function d(e){return e.split(u.EOL).filter(Boolean).map(O).filter(({changeType:t})=>Boolean(t))}var s=require("child_process");function T(e){return e instanceof Buffer?e.toString("utf8"):e}function v(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}function c(e,t,n){let o=n("git",e,{cwd:process.cwd(),env:process.env});if(o.error&&v(o.error),o.status===0)return T(o.stdout);throw new Error(t[o.status]||`internal git error: ${o.status} (${T(o.stderr)})`)}function S(e=s.spawnSync){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return c(["status","--porcelain"],t,e)}function h(e,t=s.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 f(e=s.spawnSync){return c(["rev-parse","HEAD"],{},e).slice(0,40)}var N=require("path"),j=new Set([".cjs",".cjsx",".coffee",".csx",".js",".json",".jsx",".litcoffee",".ls",".mjs",".svelte",".ts",".tsx",".vue",".vuex"]),$=new Set(["modified","added","renamed","copied","untracked"]);function p(e,t=j,n=$){return`^(${e.filter(r=>n.has(r.changeType)).map(({name:r})=>r).filter(r=>t.has((0,N.extname)(r))).join("|")})$`}function l(e){return JSON.stringify(e,null,2)}var B={regex:p,json:l,object:e=>e},H="object";function m(e,t){return B[t||H](e)}function M(){return f()}function F(e,t){let n=e||f(),o=d(h(n)),r=t||{};return r.trackedOnly||(o=o.concat(g(S()).filter(({changeType:E})=>E==="untracked"))),m(o,r.outputType)}0&&(module.exports={getSHASync,listSync});
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
/* eslint-disable no-console */
|
3
3
|
|
4
4
|
import { program } from "commander";
|
5
|
-
import {
|
5
|
+
import { listSync } from "./main.mjs";
|
6
6
|
import { VERSION } from "./version.mjs";
|
7
7
|
|
8
8
|
program
|
@@ -17,7 +17,7 @@ program
|
|
17
17
|
.parse(process.argv);
|
18
18
|
|
19
19
|
try {
|
20
|
-
console.log(
|
20
|
+
console.log(listSync(program.args[0], program.opts()));
|
21
21
|
} catch (pError) {
|
22
22
|
console.error(`ERROR: ${pError.message}`);
|
23
23
|
}
|
package/src/main.mjs
CHANGED
@@ -5,14 +5,14 @@ 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
|
9
|
-
export function
|
8
|
+
/** @type {import("../types/watskeburt").getSHASync} */
|
9
|
+
export function getSHASync() {
|
10
10
|
return getSHA1();
|
11
11
|
}
|
12
12
|
|
13
|
-
/** @type {import("../types/watskeburt
|
14
|
-
export function
|
15
|
-
const lOldRevision = pOldRevision ||
|
13
|
+
/** @type {import("../types/watskeburt").listSync} */
|
14
|
+
export function listSync(pOldRevision, pOptions) {
|
15
|
+
const lOldRevision = pOldRevision || getSHA1();
|
16
16
|
let lChanges = convertDiffLines(getDiffLines(lOldRevision));
|
17
17
|
const lOptions = pOptions || {};
|
18
18
|
|
package/src/version.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "0.
|
1
|
+
export const VERSION = "0.6.0";
|
package/types/watskeburt.d.ts
CHANGED
@@ -32,7 +32,7 @@ export type outputTypeType = "regex" | "json" | "object";
|
|
32
32
|
export interface IOptions {
|
33
33
|
/**
|
34
34
|
* The type of output to deliver. Defaults to "object" - in which case
|
35
|
-
* the
|
35
|
+
* the listSync function returns an IChange[] object
|
36
36
|
*/
|
37
37
|
outputType: outputTypeType;
|
38
38
|
/**
|
@@ -54,14 +54,14 @@ export interface IOptions {
|
|
54
54
|
* filter what is returned and
|
55
55
|
* @throws {Error}
|
56
56
|
*/
|
57
|
-
export
|
57
|
+
export type listSync = (
|
58
58
|
pOldRevision?: string,
|
59
59
|
pOptions?: IOptions
|
60
|
-
)
|
60
|
+
) => IChange[] | string;
|
61
61
|
|
62
62
|
/**
|
63
63
|
* Returns the SHA1 of the current HEAD
|
64
64
|
*
|
65
65
|
* @throws {Error}
|
66
66
|
*/
|
67
|
-
export
|
67
|
+
export type getSHASync = () => string;
|