-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrelease-package.js
More file actions
108 lines (103 loc) · 2.71 KB
/
release-package.js
File metadata and controls
108 lines (103 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const { readdirSync } = require("fs");
const { prompt } = require("enquirer");
const execa = require("execa");
const Listr = require("listr");
const IGNORED_DIRECTORIES = [
".git",
"node_modules",
"brjs-app-converter",
"module-source-converter"
];
const choices = readdirSync(".", { withFileTypes: true })
.filter(
dirent =>
dirent.isDirectory() &&
IGNORED_DIRECTORIES.includes(dirent.name) === false
)
.map(dirent => dirent.name);
const packageNamePrompt = {
type: "autocomplete",
name: "packageName",
message: "Pick the package to release",
limit: 20,
choices
};
const versionPrompt = {
type: "select",
name: "version",
message: "Pick a version number increment",
choices: ["patch", "minor", "major"]
};
prompt([packageNamePrompt, versionPrompt])
.then(releasePackage)
.catch(console.error);
async function releasePackage({ packageName, version }) {
const options = { cwd: packageName };
const tasks = new Listr([
{
title: `Bump version in ${packageName} package.json`,
task: async ctx => {
const { stdout } = await execa(
"yarn",
["version", `--${version}`, "--no-git-tag-version"],
options
);
ctx.newVersion = stdout.match(/New version: (.*)/)[1];
}
},
{
title: `Update ${packageName} CHANGELOG.md`,
task: () =>
execa("yarn", [
"conventional-changelog",
"--preset",
"angular",
"--infile",
`${packageName}/CHANGELOG.md`,
"--same-file",
"--commit-path",
packageName,
"--pkg",
packageName,
"--lerna-package",
packageName
])
},
{
title: `Publishing new ${packageName} version`,
task: ctx =>
execa("yarn", ["publish", "--new-version", ctx.newVersion], options)
},
{
title: `Adding ${packageName} CHANGELOG.md and package.json to git index`,
task: () =>
execa("git", [
"add",
`${packageName}/CHANGELOG.md`,
`${packageName}/package.json`
])
},
{
title: `Commiting ${packageName} CHANGELOG.md and package.json`,
task: ctx =>
execa("git", [
"commit",
"-m",
`chore(${packageName}): Release ${packageName}@${ctx.newVersion}`
])
},
{
title: `Tagging new ${packageName} version`,
task: ctx => execa("git", ["tag", `${packageName}@${ctx.newVersion}`])
},
{
title: `Pushing ${packageName} release commit`,
task: () => execa("git", ["push"])
},
{
title: `Pushing ${packageName} release tag`,
task: () => execa("git", ["push", "--tags"])
}
]);
await tasks.run();
}