mateodelnorte/meta-npm

new command suggestion

DarkPark opened this issue · 1 comments

In meta repo I have many repos that are my npm packages. Sometime I publish them but mostly I commit some minor changes. It would be nice to exec command like meta npm check to get all the repos with commited changes but not published.
Here is my code for this (though cjs-async maybe better remove):

var tasks  = [],
    serial = require('cjs-async/serial');

Object.keys(repos).forEach(function ( orgName ) {
    Object.keys(repos[orgName]).forEach(function ( repoName ) {
        // only packages
        if ( repos[orgName][repoName].name ) {
            tasks.push(function ( callback ) {
                var info = require(path.join(root, orgName, repoName, 'package.json')),
                    gitRevision, npmRevision;

                exec('git', ['rev-parse', 'HEAD'], {cwd: path.join(root, orgName, repoName)}, function ( error, stdout, stderr ) {
                    if ( error ) {
                        console.error(error);
                        process.exitCode = 1;
                    } else {
                        //console.log(info.name);
                        gitRevision = stdout.trim();

                        exec('npm', ['--registry', 'http://npm.lpo.priv:4873', 'info', info.name, 'gitHead'], function ( error, stdout, stderr ) {
                            if ( error ) {
                                console.error(error);
                                process.exitCode = 1;
                            } else {
                                //stderr && console.log(stderr);
                                //console.log(stdout + '\n');
                                npmRevision = stdout.trim();

                                if ( gitRevision === npmRevision ) {
                                    console.log('\n\u001b[32mup-to-date\u001b[0m\t%s\t%s\t%s\t%s',
                                        npmRevision, gitRevision, info.version, info.name);
                                } else {
                                    console.log('\n\u001b[31mout-of-date\u001b[0m\t%s\t%s\t%s\t%s',
                                        npmRevision, gitRevision, info.version, info.name);

                                    try {
                                        console.log(execSync(
                                            'git',
                                            ['log', '--pretty=format:%s', npmRevision + '..HEAD'],
                                            {cwd: path.join(root, orgName, repoName)}
                                        ).toString());
                                    } catch ( error ) {
                                        //console.log(error.toString());
                                    }
                                }
                            }
                            callback();
                        });
                    }
                });
            });
        }
    });
});

// run
serial(tasks, function ( error ) {
    if ( error ) {
        console.log(error);
    }
});
stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.