11#!/usr/bin/env node
22import { readFileSync } from "node:fs" ;
3+ import { mkdtempSync , rmSync } from "node:fs" ;
34import { spawnSync } from "node:child_process" ;
5+ import { tmpdir } from "node:os" ;
6+ import { join } from "node:path" ;
47
58const args = new Set ( process . argv . slice ( 2 ) ) ;
69const publish = args . has ( "--publish" ) ;
@@ -64,16 +67,39 @@ if (publish) {
6467 }
6568}
6669
70+ const packDir = mkdtempSync ( join ( tmpdir ( ) , "mautic-control-clawpack-" ) ) ;
71+ const packResult = run ( "npm" , [
72+ "exec" ,
73+ "--yes" ,
74+ "clawhub" ,
75+ "--" ,
76+ "package" ,
77+ "pack" ,
78+ "." ,
79+ "--pack-destination" ,
80+ packDir ,
81+ "--json" ,
82+ ] ) ;
83+
84+ let packed ;
85+ try {
86+ packed = JSON . parse ( requireSuccess ( packResult , "clawhub package pack" ) ) ;
87+ } catch ( error ) {
88+ rmSync ( packDir , { recursive : true , force : true } ) ;
89+ if ( error instanceof SyntaxError ) {
90+ throw new Error ( `clawhub package pack returned invalid JSON:\n${ packResult . stdout || "" } ${ packResult . stderr || "" } ` ) ;
91+ }
92+ throw error ;
93+ }
94+
6795const command = [
6896 "exec" ,
6997 "--yes" ,
7098 "clawhub" ,
7199 "--" ,
72100 "package" ,
73101 "publish" ,
74- "." ,
75- "--family" ,
76- "code-plugin" ,
102+ packed . path ,
77103 "--source-repo" ,
78104 sourceRepo ,
79105 "--source-commit" ,
@@ -92,4 +118,5 @@ if (owner) command.push("--owner", owner);
92118if ( changelog ) command . push ( "--changelog" , changelog ) ;
93119
94120const result = run ( "npm" , command , { stdio : "inherit" } ) ;
121+ rmSync ( packDir , { recursive : true , force : true } ) ;
95122process . exit ( result . status ?? 1 ) ;
0 commit comments