@@ -5,8 +5,12 @@ import { fileURLToPath } from 'node:url';
55import { spawnSync } from 'node:child_process' ;
66import readline from 'node:readline' ;
77
8+ const __filename = fileURLToPath ( import . meta. url ) ;
9+ const __dirname = path . dirname ( __filename ) ;
10+ const iconsDir = __dirname ;
11+
812function parseArgs ( argv ) {
9- const args = { version : '' , skipConfirm : false } ;
13+ const args = { version : '' , skipConfirm : false , registry : '' , auth : '' } ;
1014 for ( let i = 2 ; i < argv . length ; i += 1 ) {
1115 const key = argv [ i ] ;
1216 const val = argv [ i + 1 ] ;
@@ -15,6 +19,10 @@ function parseArgs(argv) {
1519 i += 1 ;
1620 } else if ( key === '--skip-confirm' || key === '-y' ) {
1721 args . skipConfirm = true ;
22+ } else if ( key === '--registry' || key === '-r' ) {
23+ args . registry = val || '' ;
24+ } else if ( key === '--auth' || key === '-a' ) {
25+ args . auth = val || '' ;
1826 }
1927 }
2028 return args ;
@@ -124,31 +132,10 @@ async function confirmPublish() {
124132 } ) ;
125133}
126134
127- function updatePackagePublishVersion ( iconsDir , version ) {
128- const pubPkgPath = path . join ( iconsDir , 'package_publish.json' ) ;
129- try {
130- const pubPkgContent = readJson ( pubPkgPath ) ;
131- pubPkgContent . version = version ;
132- writeJson ( pubPkgPath , pubPkgContent ) ;
133- console . log ( `✅ 已更新 package_publish.json 版本号为: ${ version } ` ) ;
134- } catch ( err ) {
135- console . warn ( `⚠️ 更新 package_publish.json 版本号失败: ${ err . message } ` ) ;
136- }
137- }
138-
139135async function main ( ) {
140- const { version, skipConfirm } = parseArgs ( process . argv ) ;
141- if ( ! version ) {
142- console . error ( '请通过 --version 或 -v 指定版本号,例如:' ) ;
143- console . error (
144- ' node packages/icons/publish-icons.mjs --version 0.0.1-rc.3'
145- ) ;
146- process . exit ( 1 ) ;
147- }
136+ const { skipConfirm, registry, auth } = parseArgs ( process . argv ) ;
148137
149- const __filename = fileURLToPath ( import . meta. url ) ;
150- const __dirname = path . dirname ( __filename ) ;
151- const iconsDir = __dirname ;
138+ const version = readJson ( path . join ( iconsDir , 'package.json' ) ) . version ;
152139
153140 const pubPkg = path . join ( iconsDir , 'package_publish.json' ) ;
154141 ensureFileExists ( pubPkg , '发布用 package_publish.json' ) ;
@@ -158,12 +145,11 @@ async function main() {
158145 const originalVersion = originalPubPkgContent . version ;
159146
160147 const tmpBase = path . join ( __dirname , '..' ) ;
161- const tmpDir = fs . mkdtempSync (
162- path . join ( tmpBase , 'actiontech-icons-publish-' )
163- ) ;
148+ const tmpDir = path . join ( tmpBase , 'actiontech-icons-publish' ) ;
164149
165150 try {
166151 console . log ( `[1/7] 创建临时目录: ${ tmpDir } ` ) ;
152+ fs . mkdirSync ( tmpDir , { recursive : true } ) ;
167153
168154 console . log ( '[2/7] 复制整个 icons 包到临时目录' ) ;
169155 // 复制整个包目录,但排除一些不需要的文件
@@ -226,12 +212,14 @@ async function main() {
226212 return ;
227213 }
228214 }
229-
230- console . log ( '[6/7] 执行发布: npm publish' ) ;
231- runCmd ( 'npm' , [ 'publish' ] , tmpDir ) ;
232-
233- console . log ( '[7/7] 更新 package_publish.json 版本号' ) ;
234- updatePackagePublishVersion ( iconsDir , version ) ;
215+ console . log ( '[6/7] 配置认证' ) ;
216+ runCmd ( 'pnpm' , [ 'config' , 'set' , auth ] , tmpDir ) ;
217+ console . log ( '[7/7] 执行发布: pnpm publish' ) ;
218+ runCmd (
219+ 'pnpm' ,
220+ [ 'publish' , '--registry' , registry , '--no-git-checks' ] ,
221+ tmpDir
222+ ) ;
235223
236224 console . log ( '✅ 发布完成' ) ;
237225 } catch ( err ) {
@@ -250,7 +238,7 @@ async function main() {
250238 console . warn ( `⚠️ 还原版本号失败: ${ restoreErr . message } ` ) ;
251239 }
252240 } finally {
253- console . log ( '[8 /7] 清理临时目录' ) ;
241+ console . log ( '[7 /7] 清理临时目录' ) ;
254242 try {
255243 if ( fs . existsSync ( tmpDir ) ) {
256244 fs . rmSync ( tmpDir , { recursive : true , force : true } ) ;
0 commit comments