1 | #! /usr/bin/env node
|
2 |
|
3 | const 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 |
|
10 |
|
11 | const user = repository.url.split("github.com/")[1].split("/")[0];
|
12 | const repo = repository.url.split("github.com/")[1].split("/")[1].split(".")[0];
|
13 |
|
14 | let minor = version.split(".");
|
15 | const prerelease = parseFloat(minor[0]) === 0;
|
16 | minor = minor.slice(0, minor.length - 1).join(".");
|
17 |
|
18 | let body = "";
|
19 | execAsync("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 | });
|