UNPKG

1.71 kBJavaScriptView Raw
1#! /usr/bin/env node
2
3const execAsync = require("./execAsync"),
4 release = require("grizzly"),
5 shell = require("shelljs"),
6 token = shell.env.GITHUB_TOKEN,
7 {name, repository, version} = JSON.parse(shell.cat("package.json"));
8
9// shell.config.silent = true;
10
11const user = repository.url.split("github.com/")[1].split("/")[0];
12const repo = repository.url.split("github.com/")[1].split("/")[1].split(".")[0];
13
14let minor = version.split(".");
15const prerelease = parseFloat(minor[0]) === 0;
16minor = minor.slice(0, minor.length - 1).join(".");
17
18let body = "";
19execAsync("git log --pretty=format:'* %s (%h)' `git describe --tags --abbrev=0`...HEAD")
20 .then(stdout => {
21 body = stdout.length ? stdout : `${name}@${version}`;
22 return execAsync("npm publish --access public ./");
23 })
24 .then(() => {
25 shell.echo("published to npm");
26 return execAsync("git add --all");
27 })
28 .then(() => execAsync(`git commit -m \"compiles ${name}@${version}\"`))
29 .then(() => {
30 shell.echo("git commit");
31 return execAsync(`git tag ${name}@${version}`);
32 })
33 .then(() => execAsync("git push origin --follow-tags"))
34 .then(() => {
35 release(token, {
36 user, repo,
37 tag: `${name}@${version}`,
38 name: `${name}@${version}`,
39 body, prerelease
40 }, error => {
41 if (error) {
42 shell.echo(`package: ${name}`);
43 shell.echo(`version: ${version}`);
44 shell.echo(`body: ${body}`);
45 shell.echo(`prerelease: ${prerelease}`);
46 shell.echo(error.message);
47 shell.exit(1);
48 }
49 else {
50 shell.echo("release pushed");
51 shell.exit(0);
52
53 }
54 });
55 })
56 .catch(err => {
57 shell.echo(err);
58 shell.exit(1);
59 });