1.安装Node.js:下载、解压、配置环境变量;
2.安装verdaccio:npm install -g verdaccio(命令);
3启动verdaccio:verdaccio(命令);
4.修改配置文件:listen: 0.0.0.0:4873(xml格式)、publish:
allow_offline: true
(xml格式)
;
5.服务指向本地:npm set registry http://localhost:4873(命令);
6.注册登录:npm adduser --registry http://localhost:4873(命令)、npm login(命令);
6.开放端口:firewall-cmd --add-port=4873/tcp --permanent(命令);
7.重载防火墙:firewall-cmd --reload(命令);
!!批量publish依赖,将以下代码创建.js文件,放到node_modules文件夹下,node xxx.js执行(注意切换npm源)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | zconst fs = require( 'fs' ); const path = require( 'path' ); const process = require( 'process' ); // 导入执行控制台命令的方法 const exec = require( 'child_process' ).execSync; // 保存根路径 const rootPath = __dirname; let result = fs.readdirSync(rootPath); const consoleLogPath = path.join(rootPath, 'log' ); result.forEach(fName => { const dPath = path.join(__dirname, fName); const stat = fs.statSync(dPath); if (stat.isDirectory()) { const modulePath = path.join(dPath, 'node_modules' ); if (!fs.existsSync(modulePath)) return ; const statModules = fs.statSync(modulePath); if (statModules.isDirectory()) { const res = fs.readdirSync(modulePath) getVersion(res, consoleLogPath, modulePath, fName) } } }) function getVersion(result, logPath, modulePath, fName) { result.forEach(item => { // 拼接当前包路径 const dPath = path.join(modulePath, item); // 获取路径的stat const stat = fs.statSync(dPath); // 判断该包路径是否为目录 if (stat.isDirectory()) { // 如果是目录,则执行下述操作 // 当前包目录下的package.json文件路径 const packageJsonPath = path.join(dPath, 'package.json' ); if (fs.existsSync(packageJsonPath)) { // 读取当前包目录下的package.json文件的内容,返回字符串 const packageJsonContentString = fs.readFileSync(packageJsonPath, 'utf8' ); // 解析package.json文件的内容成json格式的对象 const parsedPackJson = JSON.parse(packageJsonContentString); if (parsedPackJson.scripts && Object.keys(parsedPackJson.scripts).length !== 0) { parsedPackJson.scripts = {}; fs.writeFileSync(packageJsonPath, JSON.stringify(parsedPackJson)); } // 把当前的目录切换到当前包路径下 process.chdir(dPath); // 在包路径下执行cmd控制台命令 npm publish try { exec( 'npm publish' ); } catch { console.log(`包${fName}:${item}已发布`); } // 操作执行完成,则把当前路径切换到原来的根目录 process.chdir(rootPath); console.log(fName, parsedPackJson.name, parsedPackJson.version) // 如果解析好的json格式的对象存在scripts属性且该属性不为空对象,那么将其内容设置成空对象 fs.appendFileSync(logPath, `${fName} / ${parsedPackJson.name} /@${parsedPackJson.version}\n`); } } }) } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架