Recently, Rainy Creek released version 3.2. The smaller version is already 3.2.4. This article to learn how to release vuejs university, learn the source code for their own use.
reference
Juejin. Cn/post / 699794…
www.yuque.com/ruochuan12/…
www.yuque.com/ruochuan12/…
With Vue-next open, open-source projects can generally find contribution guidelines at readme. md or.github/contributing.
Only YARN can be used to install dependencies
NPM life cycle, there are so many original, eye-opening, thanks to Chuan Brother
Preinstall: periodic command to be executed before installation
//package.json
{
"private": true."version": "3.2.4."."workspaces": [
"packages/*"]."scripts": {
// -- THE dry parameter was added by me and is also recommended if you are debugging code
// Do not test, compile, push git, etc
// This is an example of an empty run
"release": "node scripts/release.js --dry"."preinstall": "node ./scripts/checkYarn.js",}}Copy the code
// scripts/checkYarn.js
if (!/yarn\.js$/.test(process.env.npm_execpath || ' ')) {
console.warn(
'\u001b[33mThis repository requires Yarn 1.x for scripts to work properly.\u001b[39m\n'
)
process.exit(1)}Copy the code
Enter the debug
Vscode debug documentation
Go to vuE-next /package.json and open it, and then above scripts, you’ll see the Debug button, click on it, and select Release.
Enter the scripts/release. Js
Recognize the dependencies required for publication
Minimist: Parses command-line arguments
Chalk: This is used for terminal display multi-color output.
Semver: semantic version
Version format: Major version number. The second version number. The increment rule is as follows:
Major: when you make an incompatible API change, minor: when you make a backward-compatible feature addition, Revision: when you make a backward-compatible problem fix. The prior version number and version build information can be added to the major version number. Second version number. Revision number “is followed as an extension.
Enquirer: Interactive query cli
Execa: Execute terminal commands, which in the first phase were executed using childProcess
Code parsing
const args = require('minimist')(process.argv.slice(2))
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const semver = require('semver')
const { prompt } = require('enquirer')
const execa = require('execa')
const currentVersion = require('.. /package.json').version
// Corresponding YARN Run release --preid=beta
// beta
const preId =
args.preid ||
(semver.prerelease(currentVersion) && semver.prerelease(currentVersion)[0])
// Corresponding YARN Run release --dry
// true
const isDryRun = args.dry
// Correspond to YARN Run release --skipTests
// true skips the test
const skipTests = args.skipTests
// Corresponding yarn Run Release --skipBuild
// true
const skipBuild = args.skipBuild
// Read packages folder, filter out not.ts file end and not. Folder at the beginning
const packages = fs
.readdirSync(path.resolve(__dirname, '.. /packages'))
.filter(p= >! p.endsWith('.ts') && !p.startsWith('. '))
// Skip the package
const skippedPackages = []
// Version increment
const versionIncrements = [
'patch'.'minor'.'major'. (preId ? ['prepatch'.'preminor'.'premajor'.'prerelease'] : [])]const inc = i= > semver.inc(currentVersion, i, preId)
Semver. inc('3.2.4', 'prerelease', 'beta') Inc is a build
/ / 3.2.5 - beta. 0
// Get the bin command
const bin = name= > path.resolve(__dirname, '.. /node_modules/.bin/' + name)
// Execute commands and print only command information
const run = (bin, args, opts = {}) = >
execa(bin, args, { stdio: 'inherit'. opts })const dryRun = (bin, args, opts = {}) = >
console.log(chalk.blue(`[dryrun] ${bin} ${args.join(' ')}`), opts)
/ / whether - dry
const runIfNotDry = isDryRun ? dryRun : run
// Get the package path
const getPkgRoot = pkg= > path.resolve(__dirname, '.. /packages/' + pkg)
// Console output
const step = msg= > console.log(chalk.cyan(msg))
async function main() {
let targetVersion = args._[0]
// Do not know the version, give several version suggestions
if(! targetVersion) {// no explicit version, offer suggestions
const { release } = await prompt({
type: 'select'.name: 'release'.message: 'Select release type'.choices: versionIncrements.map(i= > `${i} (${inc(i)}) `).concat(['custom'])})// Select custom,
if (release === 'custom') {
targetVersion = (await prompt({
type: 'input'.name: 'version'.message: 'Input custom version'.initial: currentVersion
})).version
} else {
targetVersion = release.match(/ / / ((. *) \)) [1]}}// Verify the version number specification
if(! semver.valid(targetVersion)) {throw new Error(`invalid target version: ${targetVersion}`)}// Confirm publication
const { yes } = await prompt({
type: 'confirm'.name: 'yes'.message: `Releasing v${targetVersion}. Confirm? `
})
if(! yes) {return
}
// run test example bin('jest') to get the command, run to execute
// run tests before release
step('\nRunning tests... ')
if(! skipTests && ! isDryRun) {await run(bin('jest'),'--clearCache'])
await run('yarn'['test'.'--bail'])}else {
console.log(`(skipped)`)}// Update dependencies
// update all package versions and inter-dependencies
step('\nUpdating cross dependencies... ')
updateVersions(targetVersion)
// Take a look at build.js sometime
// build all packages with types
step('\nBuilding all packages... ')
if(! skipBuild && ! isDryRun) {await run('yarn'['build'.'--release'])
// test generated dts files
step('\nVerifying type declarations... ')
await run('yarn'['test-dts-only'])}else {
console.log(`(skipped)`)}/ / generated changelog
// generate changelog
await run(`yarn`['changelog'])
//diff checks if there are any file changes, and commits if there are
const { stdout } = await run('git'['diff'] and {stdio: 'pipe' })
if (stdout) {
step('\nCommitting changes... ')
NPM run push description (NPM run push description, NPM run push description
await runIfNotDry('git'['add'.'-A'])
await runIfNotDry('git'['commit'.'-m'.`release: v${targetVersion}`])}else {
console.log('No changes to commit.')}/ / release package
// publish packages
step('\nPublishing packages... ')
for (const pkg of packages) {
await publishPackage(pkg, targetVersion, runIfNotDry)
}
// Derive Github, hit TAB, push tag, push
// push to GitHub
step('\nPushing to GitHub... ')
await runIfNotDry('git'['tag'.`v${targetVersion}`])
await runIfNotDry('git'['push'.'origin'.`refs/tags/v${targetVersion}`])
await runIfNotDry('git'['push'])
if (isDryRun) {
console.log(`\nDry run finished - run git diff to see package changes.`)}if (skippedPackages.length) {
console.log(
chalk.yellow(
`The following packages are skipped and NOT published:\n- ${skippedPackages.join(
'\n- '
)}`))}console.log()
}
function updateVersions(version) {
// 1. Update root package.json to vue/next
updatePackage(path.resolve(__dirname, '.. '), version)
// 2. update all packages
packages.forEach(p= > updatePackage(getPkgRoot(p), version))
}
// Update version and dependencies in package.json
function updatePackage(pkgRoot, version) {
const pkgPath = path.resolve(pkgRoot, 'package.json')
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
pkg.version = version
updateDeps(pkg, 'dependencies', version)
updateDeps(pkg, 'peerDependencies', version)
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null.2) + '\n')}// packages refers to packages below /*
function updateDeps(pkg, depType, version) {
const deps = pkg[depType]
if(! deps)return
Object.keys(deps).forEach(dep= > {
if (
dep === 'vue' ||
(dep.startsWith('@vue') && packages.includes(dep.replace(/^@vue\//.' ')))) {console.log(
chalk.yellow(`${pkg.name} -> ${depType} -> ${dep}@${version}`)
)
deps[dep] = version
}
})
}
async function publishPackage(pkgName, version, runIfNotDry) {
if (skippedPackages.includes(pkgName)) {
return
}
const pkgRoot = getPkgRoot(pkgName)
const pkgPath = path.resolve(pkgRoot, 'package.json')
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
if (pkg.private) {
return
}
// for now (alpha/beta phase), every package except "vue" can be published as
// `latest`, whereas "vue" will be published under the "next" tag.
const releaseTag = args.tag || (pkgName === 'vue' ? 'next' : null)
// TODO use demographics release channel after Official 3.0 release
// const releaseTag = semver.prerelease(version)[0] || null
step(`Publishing ${pkgName}. `)
try {
await runIfNotDry(
'yarn'['publish'.'--new-version', version, ... (releaseTag ? ['--tag', releaseTag] : []),
'--access'.'public'] and {cwd: pkgRoot,
stdio: 'pipe'})console.log(chalk.green(`Successfully published ${pkgName}@${version}`))}catch (e) {
if (e.stderr.match(/previously published/)) {
console.log(chalk.red(`Skipping already published: ${pkgName}`))}else {
throw e
}
}
}
main().catch(err= > {
console.error(err)
})
Copy the code
Summarize the process
Check the version to be released 2. Execute the test case 3. Update the dependent version 3.1 updatePackage Update the version of package package.json 3.2 updateDeps Update the dependent version 4. 5. Generate Changelog 6. Commit code add,commit 7. Publish 8. Publish to github tag,push tag,pushCopy the code
Other sichuan dialect
Vuejs releases a lot of code that we can just copy and paste and modify to optimize our own release process. For example, write small programs, relatively likely to be released frequently, you can use this code, with miniprogram-CI, plus some customization, to optimize.
You can also use open source release-it.
At the same time, we can:
Introduce Git flow and manage git branches. Git flow is supported by Windows Git bash by default.
Introduce husky and Lint-staged commits using ESLint and other code to verify that they pass detection.
Introduce unit test JEST, test key tool functions, etc.
Introduce the but – changelog
Introduce git-cz interactive Git commit.
And so on to standardize the process of their own projects. If a candidate, by looking at vuejs published source code, actively optimize their own project. I think the interviewers will see this candidate as a plus.
About debugging
See how to debug code in this tutorial for hands-on practice, and node.js is similar. Mp.weixin.qq.com/s/VOoDHqIo4…
Moocs debugging course: www.imooc.com/learn/1164
Nuggets Chrome free booklet: juejin.cn/book/684473…
Moocs nodeJS debugging introduction www.imooc.com/learn/1093
Vscode nodejs debugging code.visualstudio.com/docs/nodejs…
Vscode also has a lot of debugging documentation, which is recommended