🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

git-pull-run

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-pull-run - npm Package Compare versions

Comparing version

to
1.4.0

@@ -8,3 +8,3 @@ #!/usr/bin/env node

import { gitPullRun } from './index.js';
const debug = debugLog('git-pull-run');
const debug = debugLog('git-pull-run:cli');
const packageJsonPath = path.join(fileURLToPath(import.meta.url), '../../package.json');

@@ -11,0 +11,0 @@ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());

import debugLog from 'debug';
import { parse, resolve } from 'path';
const debug = debugLog.debug('git-pull-run:getAbsolutePath');
const debug = debugLog('git-pull-run:getAbsolutePath');
export function getAbsolutePath(baseDir, path) {

@@ -5,0 +5,0 @@ const { dir: relativeDir, base: file } = parse(path);

@@ -11,6 +11,6 @@ import { runGit } from './runGit.js';

debug('Changed files:', files);
const matches = micromatch(files, pattern);
debug(`Match files with pattern '${pattern}':`, matches);
return matches;
const changes = micromatch(files, pattern);
debug(`Changes that match pattern '${pattern}':`, changes);
return changes;
}
//# sourceMappingURL=getChanges.js.map

@@ -7,6 +7,6 @@ import debugLog from 'debug';

const cmd = 'git rev-parse --show-toplevel';
const result = await runGit(cmd);
debug('Git directory:', result);
return result;
const gitDir = await runGit(cmd);
debug('Git directory:', gitDir);
return gitDir;
}
//# sourceMappingURL=getGitDirectory.js.map

@@ -1,3 +0,3 @@

import debugLog from 'debug';
import { echoMessage } from './echoMessage.js';
import { dim, green } from 'colorette';
import { Listr } from 'listr2';
import { getAbsolutePath } from './getAbsolutePath.js';

@@ -8,36 +8,52 @@ import { getChanges } from './getChanges.js';

import { runScript } from './runScript.js';
debugLog.enable('git-pull-run');
const info = debugLog.debug('git-pull-run');
info.log = console.log.bind(console);
export { info };
export async function gitPullRun({ pattern, message, command, script }) {
try {
const gitDir = await getGitDirectory();
const changes = await getChanges(pattern);
if (changes.length === 0) {
info(`No relevant changes for pattern '${pattern}'`);
return;
}
else {
info(`Found ${changes.length} ${changes.length === 1 ? 'change' : 'changes'} for pattern '${pattern}'`);
}
if (message) {
echoMessage(message);
}
for (const change of changes) {
const { directory } = getAbsolutePath(gitDir, change);
if (command) {
info(`Running command '${command}' for change '${change}' in directory ${directory}...`);
await runCommand(command, directory);
}
if (script) {
info(`Running script '${script}' for change '${change}' in directory ${directory}...`);
await runScript(script, directory);
}
}
}
catch (error) {
console.log('error', error);
}
const runner = new Listr([
{
title: 'Preparing git-pull-run...',
task: async (ctx, task) => {
task.output = 'Preparing git-pull-run...';
ctx.gitDir = await getGitDirectory();
task.output = `Collecting changes for ${green(pattern)}...`;
ctx.changes = await getChanges(pattern);
task.output = ctx.changes.length > 0
? `Found ${ctx.changes.length} ${ctx.changes.length === 1 ? 'change' : 'changes'} for ${green(pattern)}`
: `No relevant changes for ${green(pattern)}`;
},
options: { persistentOutput: true },
},
{
title: message,
task: async (ctx, task) => { },
options: { persistentOutput: true },
enabled: (ctx) => !!message && message.length > 0 && ctx.changes && ctx.changes.length > 0,
},
{
title: 'Running tasks...',
task: (ctx, task) => {
const subtasks = ctx.changes.map(change => {
const { directory } = getAbsolutePath(ctx.gitDir, change);
return {
title: `${dim(directory)}`,
task: async (ctx, task) => task.newListr([
{
title: `${green(command)}`,
task: () => runCommand(command, directory),
enabled: () => !!command,
},
{
title: `npm run ${green(script)}`,
task: () => runScript(script, directory),
enabled: () => !!script,
},
])
};
});
return task.newListr([...subtasks], { concurrent: true, rendererOptions: { collapse: false } });
},
enabled: (ctx) => (!!command || !!script) && ctx.changes && ctx.changes.length > 0,
options: { persistentOutput: true },
},
], { concurrent: false });
await runner.run();
}
//# sourceMappingURL=index.js.map
{
"name": "git-pull-run",
"version": "1.3.0",
"version": "1.4.0",
"description": "Run commands and scripts after git pull",

@@ -39,3 +39,2 @@ "bin": "./dist/cli.js",

"@gmrchk/cli-testing-library": "^0.1.2",
"@tsconfig/node14": "^1.0.1",
"@tsconfig/node16": "^1.0.2",

@@ -52,2 +51,3 @@ "@tsconfig/node16-strictest-esm": "^1.0.3",

"eslint-plugin-prettier": "^4.0.0",
"git-pull-run": "^1.3.0",
"jest": "^29.2.2",

@@ -54,0 +54,0 @@ "prettier": "^2.5.1",

@@ -1,2 +0,4 @@

[![npm version](https://badge.fury.io/js/git-pull-run.svg)](https://badge.fury.io/js/git-pull-run)
![npm](https://img.shields.io/npm/v/git-pull-run?label=git-pull-run)
![npm](https://img.shields.io/npm/dt/git-pull-run)
# Run Commands on Changes after Git Pull

@@ -3,0 +5,0 @@ Automatically run commands like **npm install** when fetching changes from git, but only if certain files have changed.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet