Skip to content

Commit

Permalink
feat: support custom publish command
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban committed Apr 21, 2024
1 parent c03eed4 commit d87f5ae
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
9 changes: 0 additions & 9 deletions docs/pages/_app.js

This file was deleted.

14 changes: 8 additions & 6 deletions docs/pages/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { Callout } from "nextra/components";
changelog file.
</Callout>

| Key | Type | Default | Description |
| :--------------: | :-------: | :-------------: | :--------------------------------: |
| `disableRelease` | `boolean` | `undefined` | Do not create a release on GitHub. |
| `inFile` | `string` | `undefined` | Path to the changelog file. |
| `header` | `string` | `"# Changelog"` | Header of the changelog file. |
| Key | Type | Default | Description |
| :--------------: | :-------: | :----------------------------------------------------------: | :--------------------------------: |
| `disableRelease` | `boolean` | `undefined` | Do not create a release on GitHub. |
| `inFile` | `string` | `undefined` | Path to the changelog file. |
| `header` | `string` | `"# Changelog"` | Header of the changelog file. |
| `publishCommand` | `string` | `pnpm -r publish --access public --no-git-checks --tag $tag` | Command to publish the package. |

Example:

Expand All @@ -20,7 +21,8 @@ Example:
"plugins": {
"release-it-pnpm": {
"disableRelease": true,
"inFile": "CHANGELOG.md"
"inFile": "CHANGELOG.md",
"publishCommand": "vsce publish --no-dependencies"
}
}
}
Expand Down
47 changes: 28 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const prompts = {
},
}

const defaultPublishCommand = 'pnpm -r publish --access public --no-git-checks --tag $tag'

class ReleaseItPnpmPlugin extends Plugin {
static disablePlugin() {
return ['npm', 'version']
Expand Down Expand Up @@ -133,6 +135,8 @@ class ReleaseItPnpmPlugin extends Plugin {

async bump(newVersion) {
this.setContext({ newVersion })

const { publishCommand = defaultPublishCommand } = this.options
let needPublish = false

if (!this.options['dry-run']) {
Expand All @@ -144,38 +148,43 @@ class ReleaseItPnpmPlugin extends Plugin {
recursive: true,
release: newVersion,
})
if (updatedFiles.length > 0) {
for (const file of updatedFiles) {
const { private: isPrivate } = JSON.parse(fs.readFileSync(file, 'utf8'))
if (!isPrivate) {
needPublish = true
break
}
if (updatedFiles.length === 0)
return

// Only publish when some packages is not private
for (const file of updatedFiles) {
const { private: isPrivate } = JSON.parse(fs.readFileSync(file, 'utf8'))
if (!isPrivate) {
needPublish = true
break
}
}
}

this.debug(
'release-it-pnpm:bump',
{
newVersion,
parsed: semver.parse(newVersion),
},
)
// Using custom publish command
if (!publishCommand?.startsWith('pnpm'))
needPublish = true
}

const { prerelease } = semver.parse(newVersion)
const includePrerelease = prerelease.length > 0
const prereleaseTag = includePrerelease ? `--tag ${prerelease[0]}` : ''
this.setContext({ prereleaseTag })
const tag = prerelease[0] ?? 'latest'

this.debug(
'release-it-pnpm:bump',
{ prereleaseTag, needPublish },
{
needPublish,
publishCommand,
includePrerelease,
prerelease,
tag,
newVersion,
parsedNewVersion: semver.parse(newVersion),
},
)

if (needPublish) {
await this.step({
task: () => this.exec(`pnpm -r publish --access public --no-git-checks ${prereleaseTag}`),
task: () => this.exec(publishCommand.replace('$tag', tag)),
label: 'Publishing packages(s)',
prompt: 'publish',
})
Expand Down

0 comments on commit d87f5ae

Please sign in to comment.