Skip to content

Commit ade64d3

Browse files
committed
Improve release-it
1 parent d419304 commit ade64d3

3 files changed

Lines changed: 75 additions & 1 deletion

File tree

frontend/packages/volto-pythonbrasil-site/.release-it.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"plugins": {
3-
"../../core/packages/scripts/prepublish.js": {}
3+
"./scripts/prepublish.mjs": {}
44
},
55
"hooks": {
66
"after:bump": [
@@ -15,6 +15,9 @@
1515
"npm": {
1616
"publish": false
1717
},
18+
"plonePrePublish": {
19+
"publish": false
20+
},
1821
"git": {
1922
"changelog": "pipx run towncrier build --draft --yes --version 0.0.0",
2023
"requireUpstream": false,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update .release-it.json to support new command line option. @ericof
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Plugin } from 'release-it';
2+
3+
const NPM_BASE_URL = 'https://www.npmjs.com';
4+
const NPM_PUBLIC_PATH = 'package';
5+
6+
class PrePublishReleaseItPlugin extends Plugin {
7+
constructor(...args) {
8+
super(...args);
9+
10+
this.registerPrompts({
11+
prePublishPrompt: {
12+
type: 'confirm',
13+
message: (context) =>
14+
`Are you sure you want to publish ${context.npm.name}${
15+
context.isPreRelease ? `@${context.preReleaseId}` : '@latest'
16+
} to npm?`,
17+
default: true,
18+
},
19+
});
20+
}
21+
22+
disablePlugin() {
23+
return 'npm';
24+
}
25+
26+
getName() {
27+
return 'plonePrePublish';
28+
}
29+
30+
getPackageUrl() {
31+
const baseUrl = NPM_BASE_URL;
32+
const publicPath = NPM_PUBLIC_PATH;
33+
return `${baseUrl}/${publicPath}/${this.getName()}`;
34+
}
35+
36+
async beforeRelease() {
37+
const context = this.config.getContext();
38+
const tag = context.isPreRelease ? context.preReleaseId : 'latest';
39+
const dryRunArg = this.config.isDryRun ? '--dry-run' : '';
40+
const pluginOptions = this.config.options?.plonePrePublish;
41+
const publish = pluginOptions ? pluginOptions.publish ?? true : true;
42+
if (publish) {
43+
await this.step({
44+
enabled: true,
45+
task: () =>
46+
this.exec(
47+
`pnpm publish${tag ? ` --tag ${tag}` : ''}${dryRunArg ? ` ${dryRunArg}` : ''} --no-git-checks`,
48+
{
49+
options: { write: false },
50+
},
51+
).then(() => {
52+
this.setContext({ isReleased: true });
53+
}),
54+
label: 'Publishing to npm...',
55+
prompt: 'prePublishPrompt',
56+
});
57+
} else {
58+
this.setContext({ isReleased: true });
59+
}
60+
}
61+
62+
afterRelease() {
63+
const { isReleased } = this.getContext();
64+
if (isReleased) {
65+
this.log.log(`🔗 ${this.getPackageUrl()}`);
66+
}
67+
}
68+
}
69+
70+
export default PrePublishReleaseItPlugin;

0 commit comments

Comments
 (0)