Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js脚本发布npm包 #36

Open
chiyan-lin opened this issue Jul 24, 2023 · 0 comments
Open

js脚本发布npm包 #36

chiyan-lin opened this issue Jul 24, 2023 · 0 comments

Comments

@chiyan-lin
Copy link
Owner

chiyan-lin commented Jul 24, 2023

const fs = require('fs')
const childProcess = require('child_process')
const util = require('util')

const exec = util.promisify(childProcess.exec)

const runTask = async function () {
	let version = ''
	const pkgStr = fs.readFileSync('./package.json', { encoding: 'utf8' })
	const latestPkgStr = pkgStr.replace(/"version": "([\d\.]+)"/, ($0, $1) => {
		version = $1
		return '"version": "latest"'
	})
	console.info('获取到当前的版本为', version)
	fs.writeFileSync('./package.json', latestPkgStr, 'utf8')
	console.info('替换为 latest, 执行发布')
	await exec(`cook up`, { cwd: __dirname })
	console.info('发布完成, 恢复原版本')
	fs.writeFileSync('./package.json', pkgStr, 'utf8')
}

runTask()

@chiyan-lin chiyan-lin changed the title 做一个发布 js发布 Oct 10, 2023
@chiyan-lin chiyan-lin changed the title js发布 js脚本发布npm包 Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant