Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
Added a —parallel option
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed Oct 12, 2018
1 parent 8d9d5f0 commit 23f9d6f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/configuration.md
Expand Up @@ -13,6 +13,7 @@ const push = require ( 'autogit-plugin-push' );
module.exports = {
dry: true, // Enable dry mode by default, where plugins only simulate doing the work
exitOnError: true, // Exit at the first error thrown
parallel: 1, // Maximum number of commands to run in parallel
pick: true, // Always manually pick repositories
verbose: false, // Disable verbose output by default
commands: { // Your custom commands
Expand Down
4 changes: 3 additions & 1 deletion src/cli.ts
Expand Up @@ -30,6 +30,7 @@ async function CLI () {

command.option ( '--include <glob>', 'Only include repositories matching this glob', app.REPEATABLE, '**/*' )
.option ( '--exclude <glob>', 'Exclude repositories matching this glob', app.REPEATABLE, '**/.*, ...' )
.option ( '--parallel [number]', 'Maximum number of commands to run in parallel', undefined, 1 )
.option ( '--pick', 'Manually pick repositories', undefined, false )
.option ( '--dry', 'Simulate the command', undefined, false )
.option ( '--no-dry', 'Don\'t simulate the command', undefined, true )
Expand Down Expand Up @@ -81,7 +82,8 @@ async function CLI () {

const command = app['_defaultCommand'];
const helpLines = [
`autogit shell 'pwd'`,
`autogit shell pwd`,
`autogit shell 'pwd && sleep 1' --parallel 5`,
`autogit my-command ${chalk.green ( '--dry' )}`,
`autogit my-command ${chalk.green ( '--include' )} ${chalk.blue ( 'vscode-*' )} ${chalk.green ( '--no-verbose' )}`,
];
Expand Down
5 changes: 2 additions & 3 deletions src/command.ts
Expand Up @@ -3,7 +3,6 @@

import * as _ from 'lodash';
import chalk from 'chalk';
import * as Listr from 'listr';
import compose from 'listr-compose';
import * as path from 'path';
import * as simpleGit from 'simple-git/promise';
Expand All @@ -29,12 +28,12 @@ const Command = {

plugins = plugins.map ( plugin => Plugin.parse ( plugin, repository ) );

return Utils.listr.patch ( new Listr ([{
return {
title: await Command.getTitle ( repository ),
enabled: await Command.getEnabled ( repository, command ),
skip: await Command.getSkip ( repository, command ),
task: () => Utils.listr.patch ( compose ( ...plugins ) )
}]));
};

},

Expand Down
24 changes: 24 additions & 0 deletions src/commands.ts
@@ -0,0 +1,24 @@

/* IMPORT */

import Command from './command';

/* COMMANDS */

const Commands = {

get ( commandName, repositories ) {

return Promise.all ( repositories.map ( repository => {

return Command.get ( commandName, repository );

}));

}

};

/* EXPORT */

export default Commands;
4 changes: 3 additions & 1 deletion src/config.ts
Expand Up @@ -52,6 +52,7 @@ const Config = {
return {
dry: false,
exitOnError: false,
parallel: 1,
pick: false,
verbose: true,
commands: {
Expand Down Expand Up @@ -99,10 +100,11 @@ const Config = {

dynamic () {

const {dry, v, verbose, include, exclude, pick} = argv;
const {dry, v, verbose, include, exclude, parallel, pick} = argv;

return {
dry,
parallel: _.isNumber ( parallel ) ? parallel : 1,
pick,
verbose: [verbose, v].find ( _.isBoolean ),
repositories: {
Expand Down
14 changes: 10 additions & 4 deletions src/index.ts
@@ -1,10 +1,13 @@

/* IMPORT */

import * as _ from 'lodash';
import * as Listr from 'listr';
import Config from './config';
import Command from './command';
import Commands from './commands';
import Prompt from './prompt';
import fetchRepositories from './repositories';
import Utils from './utils';

/* AUTOGIT */

Expand All @@ -16,13 +19,16 @@ async function autogit ( commandName?, repositories? ) {

}

for ( let repository of repositories ) {
const commands = await Commands.get ( commandName, repositories ),
chunks = _.chunk ( commands, Config.parallel );

const command = await Command.get ( commandName, repository );
for ( let chunk of chunks ) {

const listr = Utils.listr.patch ( new Listr ( chunk, { concurrent: Infinity, exitOnError: false } ) );

try {

await command.run ();
await listr.run ();

} catch ( err ) {

Expand Down

0 comments on commit 23f9d6f

Please sign in to comment.