generated from ryansonshine/typescript-npm-package-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable no-process-exit */ | ||
import fs from 'fs'; | ||
import childProcess, { execSync } from 'child_process'; | ||
import type { PackageJson } from 'type-fest'; | ||
|
||
const packageJson: PackageJson = JSON.parse( | ||
fs.readFileSync('package.json').toString() | ||
); | ||
|
||
const checkedPackageJson = childProcess.spawnSync('npm', [ | ||
'view', | ||
`${packageJson.name}@${packageJson.version}`, | ||
]); | ||
|
||
if (checkedPackageJson.stdout.toString() !== '') { | ||
console.log('Package version already exists in npm registry - skip release'); | ||
process.exit(0); | ||
} | ||
|
||
if (!packageJson.version) { | ||
console.log('No version in package.json'); | ||
process.exit(1); | ||
} | ||
|
||
const branchName = execSync('git rev-parse --abbrev-ref HEAD') | ||
.toString('utf-8') | ||
.trim(); | ||
|
||
const tag = | ||
packageJson.version.includes('alpha') && branchName.startsWith('alpha') | ||
? 'alpha' | ||
: packageJson.version.includes('beta') && branchName.startsWith('beta') | ||
? 'beta' | ||
: packageJson.version.includes('canary') && | ||
branchName.startsWith('canary') | ||
? 'canary' | ||
: packageJson.version.includes('next') && branchName.startsWith('next') | ||
? 'next' | ||
: packageJson.version.includes('rc') && branchName.startsWith('rc') | ||
? 'rc' | ||
: branchName === 'main' | ||
? 'latest' | ||
: ''; | ||
|
||
console.log( | ||
`Publishing ${packageJson.name}@${packageJson.version} with tag ${tag}` | ||
); | ||
childProcess.execSync(`npm publish --tag ${tag}`); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters