基于快速应用开发问题的Git验证还记得这个打包是不是当前正在调试的代码吗?constsh=require('shelljs')constchalk=require('chalk')constuncommit=sh.exec('gitstatus--porcelain').stdoutconstlines=uncommit.toString().split('\n').filter(item=>item).lengthif(lines){console.log(chalk.red('注意:部分代码未提交或缓存,请谨慎发布!!!'))console.log('-------------------------------------------------')console.log('推荐:使用gitpush提交或者gitstash缓存然后发布版本。')process.exit(1)}process.exit(0)每个包没有日志,强制开发者上传或缓存来打包,使用Git做日志服务进行打包。constsh=require('shelljs')constchalk=require('chalk')constinquirer=require('inquirer')constlog=console.logasync函数权限(){constuncommit=sh.exec('gitstatus--瓷器').stdoutconstlines=uncommit.toString().split('\n').filter(item=>item).lengthif(lines){log(chalk.redBright(chalk.bold('note:')+'有代码未提交或缓存,请谨慎释放!!!'))log('------------------------------------------------')log(chalk.blueBright('recommend:')+'使用gitpush提交或者gitstashtocacheIssue.')const{isSkip}=(awaitinquirer.prompt({type:'expand',name:'isSkip',choices:[{key:'y',name:'Yes',value:true},{key:'n',name:'No',value:false}],message:'Areyougoingyourway?'}))if(isSkip){process.env.custom_uncommit_skip=isSkipprocess.退出(0)}过程。exit(1)}process.exit(0)}permission()使用场景"prerelease":"nodebin/index.js"自动版本号[简单版]constfs=require('fs')constpath=require('path')consthandleFile=path.resolve(process.cwd(),'src','manifest.json')constrawText=fs.readFileSync(handleFile)constmanifestJson=JSON.parse(rawText)console.log(manifestJson)manifestJson.versionCode++fs.writeFileSync(handleFile,JSON.stringify(manifestJson,'',2))JSON.stringify使用JSON.stringify()接受三个参数data:JSON数据函数:序列化函数——在执行序列化时,每个要序列化的属性都会被函数deal处理转换编号|String:指定空字符串用于缩进,美化输出——Number标识换行空格的个数;字符串标识\t,\n等使用场景"prerelease":"nodebin/git-uncommit.js&&nodebin/auto-version.js",提高自动版本号参考lerna版本选择版本更新级别通过命令行交互根据对应的版本级别用semver.inc升级版本constfs=require('fs')constpath=require('path')constsh=require('shelljs')constchalk=require('粉笔')constsemver=require('semver')constinquirer=require('inquirer')constterminal=inquirer。提示constquickJSONFile=path.resolve(process.cwd(),'src','manifest.json')constmanifestJson=JSON.parse(fs.readFileSync(quickJSONFile))functioncustomVersion(message,{filter,validate}={}){returnterminal([{type:"input",name:"input",message,filter,validate,},]).then(answers=>{returnanswers.input;});}/***@param{PackageGraphNode|Object}节点要处理的元数据*@property{String}currentVersion*@property{String}名称(仅用于独立mode)*@property{String}prereleaseId*/functionpromptVersion(currentVersion,name,prereleaseId){constpatch=semver.inc(currentVersion,"patch");}constminor=semver.inc(currentVersion,"minor");constmajor=semver.inc(currentVersion,"major");constprepatch=semver.inc(currentVersion,"prepatch",prereleaseId);constpreminor=semver.inc(currentVersion,"preminor",prereleaseId);constpremajor=semver.inc(currentVersion,"premajor",prereleaseId);constmessage=`选择一个新版本${name?`for${name}`:""}(currently${currentVersion})`;returnterminal({type:'list',message,name:'choice',choices:[{value:patch,name:`Patch(${patch})`},{value:minor,name:`次要(${minor})`},{value:major,name:`Major(${major})`},{value:prepatch,name:`Prepatch(${prepatch})`},{value:preminor,name:`Preminor(${preminor})`},{value:premajor,name:`Premajor(${premajor})`},{value:"PRERELEASE",name:"CustomPrerelease"},{value:"CUSTOM",name:"CustomVersion"},]}).then(({choice})=复制代码>{if(choice==="CUSTOM"){returncustomVersion("Enteracustomversion",{filter:semver.valid,//semver.valid()总是返回无效输入的nullvalidate:v=>v!==null||“必须是有效的semver版本”,});}if(choice==="PRERELEASE"){constdefaultVersion=semver.inc(currentVersion,"prerelease",prereleaseId);constprompt=`(默认值:“${prereleaseId}”,产生${defaultVersion})`;returncustomVersion(`输入预发布标识符${prompt}`,{filter:v=>semver.inc(currentVersion,"prerelease",v||prereleaseId),});}returnchoice;});}promptVersion(manifestJson.versionName).then(nextVersion=>{尝试{manifestJson.versionName=nextVersionmanifestJson.versionCode++fs.writeFileSync(quickJSONFile,JSON.stringify(manifestJson,'',2))console.log(chalk.whiteBright(`------------路径:${quickJSONFile}-------------------`))console.log(`${chalk.whiteBright(chalk.bold('已配置新版本:'))}${chalk.blueBright(nextVersion)}`)console.log(chalk.whiteBright(`------------释放-释放-释放-------------------`))if(!process.env.custom_uncommit_skip){sh.exec('gitcommit--amend--no-edit')}process.exit(0)}catch(e){console.log(chalk.redBright(JSON.stringify(e)))process.exit(1)}})自动生成更新日志第三方工具standard-version:执行npxstandard-version,会执行以下步骤:在packageFilesfileNo.根据当前版本号&commit(type)升级bumpFiles&packageFiles中的版本号生成commitlog(底层使用conventional-changelog)生成新的commit生成新的tagbumpFilesvs.packageFiles介绍概念:可以通过文章后续自定义来理解,简单来说,packageFiles是输入,packageFiles+bumpFiles是输出用法基本用法npxstandard-version指定Tag前缀默认为'v-*'standard-version-t
