1+ #!/usr/bin/env node
2+
3+ /**
4+ * 독립적인 패키지 배포 스크립트
5+ * 각 패키지를 개별적으로 빌드하고 배포합니다.
6+ * 하나가 실패해도 다른 패키지는 계속 진행됩니다.
7+ */
8+
9+ const { execSync } = require ( 'child_process' ) ;
10+ const fs = require ( 'fs' ) ;
11+ const path = require ( 'path' ) ;
12+
13+ // 패키지 목록
14+ const packages = [
15+ {
16+ name : 'vue-pivottable' ,
17+ path : '.' ,
18+ buildCmd : 'pnpm build' ,
19+ npmToken : 'NPM_TOKEN'
20+ } ,
21+ {
22+ name : '@vue-pivottable/lazy-table-renderer' ,
23+ path : 'packages/lazy-table-renderer' ,
24+ buildCmd : 'pnpm -F @vue-pivottable/lazy-table-renderer build' ,
25+ npmToken : 'NPM_TOKEN'
26+ } ,
27+ {
28+ name : '@vue-pivottable/plotly-renderer' ,
29+ path : 'packages/plotly-renderer' ,
30+ buildCmd : 'pnpm -F @vue-pivottable/plotly-renderer build' ,
31+ npmToken : 'NPM_TOKEN_SUMIN'
32+ }
33+ ] ;
34+
35+ // 색상 출력을 위한 헬퍼
36+ const colors = {
37+ green : ( text ) => `\x1b[32m${ text } \x1b[0m` ,
38+ red : ( text ) => `\x1b[31m${ text } \x1b[0m` ,
39+ yellow : ( text ) => `\x1b[33m${ text } \x1b[0m` ,
40+ blue : ( text ) => `\x1b[34m${ text } \x1b[0m`
41+ } ;
42+
43+ // 각 패키지 처리
44+ async function releasePackages ( ) {
45+ const results = [ ] ;
46+
47+ for ( const pkg of packages ) {
48+ console . log ( colors . blue ( `\n🚀 Processing ${ pkg . name } ...` ) ) ;
49+
50+ // 빌드 시도
51+ try {
52+ console . log ( colors . yellow ( ` Building ${ pkg . name } ...` ) ) ;
53+ execSync ( pkg . buildCmd , { stdio : 'inherit' } ) ;
54+ console . log ( colors . green ( ` ✅ Build successful` ) ) ;
55+ } catch ( error ) {
56+ console . log ( colors . red ( ` ❌ Build failed for ${ pkg . name } ` ) ) ;
57+ results . push ( { package : pkg . name , status : 'build failed' } ) ;
58+ continue ; // 다음 패키지로 진행
59+ }
60+
61+ // 배포 시도
62+ try {
63+ console . log ( colors . yellow ( ` Publishing ${ pkg . name } ...` ) ) ;
64+
65+ // 올바른 NPM 토큰 설정
66+ const npmToken = process . env [ pkg . npmToken ] ;
67+ if ( ! npmToken ) {
68+ throw new Error ( `${ pkg . npmToken } not found in environment` ) ;
69+ }
70+
71+ // changeset publish 실행
72+ const publishCmd = `cd ${ pkg . path } && NPM_TOKEN=${ npmToken } pnpm changeset publish` ;
73+ execSync ( publishCmd , {
74+ stdio : 'inherit' ,
75+ env : { ...process . env , NPM_TOKEN : npmToken }
76+ } ) ;
77+
78+ console . log ( colors . green ( ` ✅ Published successfully` ) ) ;
79+ results . push ( { package : pkg . name , status : 'success' } ) ;
80+ } catch ( error ) {
81+ console . log ( colors . red ( ` ❌ Publish failed for ${ pkg . name } ` ) ) ;
82+ results . push ( { package : pkg . name , status : 'publish failed' } ) ;
83+ }
84+ }
85+
86+ // 결과 요약
87+ console . log ( colors . blue ( '\n📊 Release Summary:' ) ) ;
88+ results . forEach ( result => {
89+ const icon = result . status === 'success' ? '✅' : '❌' ;
90+ const color = result . status === 'success' ? colors . green : colors . red ;
91+ console . log ( ` ${ icon } ${ result . package } : ${ color ( result . status ) } ` ) ;
92+ } ) ;
93+
94+ // 하나라도 실패했으면 exit code 1 반환 (optional)
95+ const hasFailures = results . some ( r => r . status !== 'success' ) ;
96+ if ( hasFailures ) {
97+ console . log ( colors . yellow ( '\n⚠️ Some packages failed, but others were published successfully' ) ) ;
98+ // process.exit(1); // CI에서 실패로 표시하려면 주석 해제
99+ }
100+ }
101+
102+ // 실행
103+ releasePackages ( ) . catch ( error => {
104+ console . error ( colors . red ( 'Unexpected error:' ) , error ) ;
105+ process . exit ( 1 ) ;
106+ } ) ;
0 commit comments