watskeburt
Advanced tools
Comparing version 0.11.6 to 0.12.0
@@ -1,63 +0,3 @@ | ||
import { EOL } from "node:os"; | ||
import { parseArgs } from "node:util"; | ||
import { list } from "./main.js"; | ||
import { VERSION } from "./version.js"; | ||
const HELP_MESSAGE = `Usage: watskeburt [options] [old-revision] [new-revision] | ||
lists files & their statuses since [old-revision] or between [old-revision] and [new-revision]. | ||
-> When you don't pass a revision at all old-revision defaults to the current one. | ||
Options: | ||
-T, --outputType <type> what format to emit (choices: "json", "regex", default: "regex") | ||
--trackedOnly only take tracked files into account (default: false) | ||
-V, --version output the version number | ||
-h, --help display help for command${EOL}`; | ||
export async function cli(pArguments = process.argv.slice(2), pOutStream = process.stdout, pErrorStream = process.stderr) { | ||
try { | ||
const lArguments = getArguments(pArguments); | ||
if (lArguments.values.help) { | ||
pOutStream.write(HELP_MESSAGE); | ||
return; | ||
} | ||
if (lArguments.values.version) { | ||
pOutStream.write(`${VERSION}${EOL}`); | ||
return; | ||
} | ||
if (!outputTypeIsValid(lArguments.values.outputType)) { | ||
pErrorStream.write(`error: option '-T, --outputType <type>' argument '${lArguments.values.outputType}' is invalid. Allowed choices are json, regex.${EOL}`); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
const lResult = await list(lArguments.positionals[0], lArguments.positionals[1], lArguments.values); | ||
pOutStream.write(`${lResult}${EOL}`); | ||
} | ||
catch (pError) { | ||
pErrorStream.write(`${EOL}ERROR: ${pError.message}${EOL}${EOL}`); | ||
process.exitCode = 1; | ||
} | ||
} | ||
function getArguments(pArguments) { | ||
return parseArgs({ | ||
args: pArguments, | ||
options: { | ||
outputType: { | ||
type: "string", | ||
short: "T", | ||
default: "regex", | ||
}, | ||
trackedOnly: { | ||
type: "boolean", | ||
default: false, | ||
}, | ||
help: { type: "boolean", short: "h", default: false }, | ||
version: { type: "boolean", short: "V", default: false }, | ||
}, | ||
strict: true, | ||
allowPositionals: true, | ||
tokens: false, | ||
}); | ||
} | ||
function outputTypeIsValid(pOutputType) { | ||
return ["json", "regex"].includes(pOutputType); | ||
} | ||
#!/usr/bin/env node | ||
import { cli } from "./execute-cli.js"; | ||
await cli(); |
import { convertDiffLines, convertStatusLines, } from "./convert-to-change-object.js"; | ||
import * as primitivesSync from "./git-primitives-sync.js"; | ||
import * as primitives from "./git-primitives.js"; | ||
@@ -18,16 +17,4 @@ import format from "./formatters/format.js"; | ||
} | ||
export function listSync(pOldRevision, pNewRevision, pOptions) { | ||
const lOldRevision = pOldRevision || primitivesSync.getSHASync(); | ||
const lOptions = pOptions || {}; | ||
let lChanges = convertDiffLines(primitivesSync.getDiffLinesSync(lOldRevision, pNewRevision)); | ||
if (!lOptions.trackedOnly) { | ||
lChanges = lChanges.concat(convertStatusLines(primitivesSync.getStatusShortSync()).filter(({ changeType }) => changeType === "untracked")); | ||
} | ||
return format(lChanges, lOptions.outputType); | ||
} | ||
export function getSHA() { | ||
return primitives.getSHA(); | ||
} | ||
export function getSHASync() { | ||
return primitivesSync.getSHASync(); | ||
} |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "0.11.6"; | ||
export const VERSION = "0.12.0"; |
{ | ||
"name": "watskeburt", | ||
"version": "0.11.6", | ||
"version": "0.12.0", | ||
"description": "List files changed since a git revision", | ||
@@ -22,4 +22,4 @@ "keywords": [ | ||
"license": "MIT", | ||
"bin": "bin/cli.js", | ||
"main": "dist/cjs-bundle.cjs", | ||
"bin": "dist/esm/cli.js", | ||
"main": "dist/esm/main.js", | ||
"module": "dist/esm/main.js", | ||
@@ -31,6 +31,5 @@ "type": "module", | ||
{ | ||
"import": "./dist/esm/main.js", | ||
"require": "./dist/cjs-bundle.cjs" | ||
"import": "./dist/esm/main.js" | ||
}, | ||
"./dist/cjs-bundle.cjs" | ||
"./dist/esm/main.js" | ||
] | ||
@@ -40,3 +39,2 @@ }, | ||
"files": [ | ||
"bin", | ||
"dist", | ||
@@ -50,3 +48,2 @@ "!**/*.DS_Store", | ||
"devDependencies": { | ||
"@types/mocha": "10.0.1", | ||
"@types/node": "20.4.1", | ||
@@ -56,3 +53,2 @@ "@typescript-eslint/eslint-plugin": "6.0.0", | ||
"dependency-cruiser": "13.1.0", | ||
"esbuild": "0.18.11", | ||
"eslint": "8.44.0", | ||
@@ -68,3 +64,2 @@ "eslint-config-moving-meadow": "4.0.2", | ||
"eslint-plugin-unicorn": "47.0.0", | ||
"mocha": "10.2.0", | ||
"npm-run-all": "4.1.5", | ||
@@ -83,25 +78,24 @@ "prettier": "3.0.0", | ||
"build:clean": "rm -rf dist/*", | ||
"build:dist": "npm-run-all build:dist:*", | ||
"build:dist:cjs": "esbuild src/main.ts --format=cjs --target=node14 --platform=node --bundle --global-name=wkbtcjs --minify --outfile=dist/cjs-bundle.cjs", | ||
"build:dist:esm": "tsc", | ||
"build:dist": "tsc", | ||
"check": "npm-run-all --parallel --aggregate-output lint depcruise test:cover", | ||
"clean": "rm -rf dist", | ||
"test": "NODE_OPTIONS=--no-warnings mocha", | ||
"test:cover": "NODE_OPTIONS=--no-warnings c8 mocha", | ||
"depcruise": "depcruise bin dist src types", | ||
"depcruise:graph": "depcruise bin src types --include-only '^(bin|dist|src|types)' --output-type dot | dot -T svg | tee docs/dependency-graph.svg | depcruise-wrap-stream-in-html > docs/dependency-graph.html", | ||
"depcruise:graph:archi": "depcruise bin src --include-only '^(bin|dist|src|types)' --output-type archi | dot -T svg | depcruise-wrap-stream-in-html > docs/high-level-dependency-graph.html", | ||
"depcruise:graph:dev": "depcruise bin dist src types --include-only '^(bin|dist|src|types)' --prefix vscode://file/$(pwd)/ --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser", | ||
"depcruise:graph:diff:dev": "depcruise bin dist src types --include-only '^(bin|dist|src|types)' --highlight \"$(node bin/cli.js main -T regex)\" --prefix vscode://file/$(pwd)/ --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser", | ||
"depcruise:graph:diff:mermaid": "depcruise bin dist src types --include-only '^(bin|dist|src|types)' --output-type mermaid --output-to - --highlight \"$(node bin/cli.js $SHA -T regex)\"", | ||
"depcruise:html": "depcruise bin src types --progress --output-type err-html --output-to dependency-violation-report.html", | ||
"depcruise:text": "depcruise bin src types --progress --output-type text", | ||
"depcruise:focus": "depcruise bin src types --progress --output-type text --focus", | ||
"depcruise:reaches": "depcruise bin src types --progress --output-type text --reaches", | ||
"format": "prettier --write \"{bin,src,tools}/**/*.{js,ts}\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"", | ||
"format:check": "prettier --loglevel warn --check \"{bin,src,tools}/**/*.ts\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"", | ||
"test": "node --no-warnings --loader 'ts-node/esm' --test-reporter dot --test src/*.spec.ts src/**/*.spec.ts", | ||
"test:cover": "c8 npm test", | ||
"test:only-for-node-16-without-the-test-reporter": "node --no-warnings --loader 'ts-node/esm' --test src/*.spec.ts src/**/*.spec.ts", | ||
"depcruise": "depcruise dist src types", | ||
"depcruise:graph": "depcruise src types --include-only '^(dist|src|types)' --output-type dot | dot -T svg | tee docs/dependency-graph.svg | depcruise-wrap-stream-in-html > docs/dependency-graph.html", | ||
"depcruise:graph:archi": "depcruise src --include-only '^(dist|src|types)' --output-type archi | dot -T svg | depcruise-wrap-stream-in-html > docs/high-level-dependency-graph.html", | ||
"depcruise:graph:dev": "depcruise dist src types --include-only '^(dist|src|types)' --prefix vscode://file/$(pwd)/ --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser", | ||
"depcruise:graph:diff:dev": "depcruise dist src types --include-only '^(dist|src|types)' --highlight \"$(node dist/esm/cli.js main -T regex)\" --prefix vscode://file/$(pwd)/ --output-type dot | dot -T svg | depcruise-wrap-stream-in-html | browser", | ||
"depcruise:graph:diff:mermaid": "depcruise dist src types --include-only '^(dist|src|types)' --output-type mermaid --output-to - --highlight \"$(node dist/esm/cli.js $SHA -T regex)\"", | ||
"depcruise:html": "depcruise src types --progress --output-type err-html --output-to dependency-violation-report.html", | ||
"depcruise:text": "depcruise src types --progress --output-type text", | ||
"depcruise:focus": "depcruise src types --progress --output-type text --focus", | ||
"depcruise:reaches": "depcruise src types --progress --output-type text --reaches", | ||
"format": "prettier --write \"{src,tools}/**/*.{js,ts}\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"", | ||
"format:check": "prettier --log-level warn --check \"{src,tools}/**/*.ts\" \"types/**/*.ts\" \"*.{json,yml,md,js}\"", | ||
"lint": "npm-run-all --parallel --aggregate-output format:check lint:eslint lint:types", | ||
"lint:fix": "npm-run-all --parallel --aggregate-output format lint:eslint:fix", | ||
"lint:eslint": "eslint bin src types tools --cache --cache-location node_modules/.cache/eslint/", | ||
"lint:eslint:fix": "eslint bin src types tools --fix --cache --cache-location node_modules/.cache/eslint/", | ||
"lint:eslint": "eslint src types tools --cache --cache-location node_modules/.cache/eslint/", | ||
"lint:eslint:fix": "eslint src types tools --fix --cache --cache-location node_modules/.cache/eslint/", | ||
"lint:types": "tsc --noEmit", | ||
@@ -108,0 +102,0 @@ "scm:stage": "git add .", |
@@ -27,8 +27,7 @@ # watskeburt | ||
```javascript | ||
// const { listSync, getSHASync } = require("watskeburt"); // in commonjs contexts you can also require it | ||
import { list, getSHA, listSync, getSHASync } from "watskeburt"; | ||
// const { list, getSHA } = require("watskeburt"); // in commonjs contexts you can also require it | ||
import { list, getSHA } from "watskeburt"; | ||
// print the SHA1 of the current HEAD | ||
console.log(await getSHA()); | ||
console.log(getSHASync()); | ||
@@ -39,4 +38,2 @@ // list all files that differ between 'main' and the current revision (including | ||
const lChangedFiles = await list("main"); | ||
// or with the synchronous interface: | ||
// const lChangedFiles = listSync("main"); | ||
@@ -47,4 +44,2 @@ // list all files that differ between 'v0.6.1' and 'v0.7.1' (by definition | ||
const lChangedFiles = await list("v0.6.1", "v0.7.1"); | ||
// or with the synchronous interface: | ||
// const lChangedFiles = listSync("v0.6.1", "v0.7.1"); | ||
@@ -59,7 +54,2 @@ // As a third parameter you can pass some options | ||
}); | ||
// or with the synchronous interface: | ||
// const lChangedFiles = listSync("main", null, { | ||
// trackedOnly: false, // when set to true leaves out files not under revision control | ||
// outputType: "object", // other options: "json" and "regex" (as used in the CLI) | ||
// }); | ||
``` | ||
@@ -66,0 +56,0 @@ |
@@ -65,39 +65,2 @@ export type changeTypeType = | ||
/** | ||
* returns a list of files changed since pOldRevision. | ||
* | ||
* @param pOldRevision The revision against which to compare. E.g. a commit-hash, | ||
* a branch or a tag. When not passed defaults to the _current_ | ||
* commit hash (if there's any) | ||
* @param pNewRevision Newer revision against which to compare. Leave out or pass | ||
* null when you want to compare against the working tree | ||
* @param pOptions Options that influence how the changes are returned and that | ||
* filter what is returned and | ||
* @throws {Error} | ||
*/ | ||
export function listSync( | ||
pOldRevision?: string, | ||
pNewRevision?: string, | ||
pOptions?: IInternalOptions, | ||
): IChange[]; | ||
/** | ||
* returns a list of files changed since pOldRevision formatted into a string | ||
* as pOptions.outputType | ||
* | ||
* @param pOldRevision The revision against which to compare. E.g. a commit-hash, | ||
* a branch or a tag. When not passed defaults to the _current_ | ||
* commit hash (if there's any) | ||
* @param pNewRevision Newer revision against which to compare. Leave out or pass | ||
* null when you want to compare against the working tree | ||
* @param pOptions Options that influence how the changes are returned and that | ||
* filter what is returned and | ||
* @throws {Error} | ||
*/ | ||
export function listSync( | ||
pOldRevision?: string, | ||
pNewRevision?: string, | ||
pOptions?: IFormatOptions, | ||
): string; | ||
/** | ||
* returns promise of a list of files changed since pOldRevision. | ||
@@ -144,9 +107,2 @@ * | ||
*/ | ||
export function getSHASync(): string; | ||
/** | ||
* Returns the SHA1 of the current HEAD | ||
* | ||
* @throws {Error} | ||
*/ | ||
export function getSHA(): Promise<string>; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
19
1
1
0
22252
13
366
111