Skip to content

Instantly share code, notes, and snippets.

@Gioyik
Created March 5, 2015 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gioyik/701b65ec164705c57a85 to your computer and use it in GitHub Desktop.
Save Gioyik/701b65ec164705c57a85 to your computer and use it in GitHub Desktop.
Script to auto publish npm packages
#!/usr/bin/env perl
use v5.14;
use warnings;
use Path::Class;
my ($ma, $mi, $ri) = file('package.json')->slurp =~ m/"version": "(\d+)\.(\d+)\.(\d+)"/;
say "Current version: $ma.$mi.$ri";
$ri++;
print "Next version [$ma.$mi.$ri]: ";
my $VERSION = (<> =~ s/\s+//rg) || "$ma.$mi.$ri";
for ('package.json') {
my $new = file($_)->slurp =~ s/"version": ".+?"/"version": "$VERSION"/r;
my $fh = file($_)->open('w');
print $fh $new;
close $fh;
}
print "Realy want to publish [$VERSION] to npm? [yN]: ";
if (<> =~ /y/i) {
say "Publishing...";
system('npm publish');
system("git add -u");
system("git commit -m '$VERSION'");
system("git tag $VERSION");
system("git push --tags");
system("git push");
} else {
say "Canceled";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment