@@ -6,7 +6,6 @@ import {checkToken, getToken} from '../../lib/token.js';
66import Spinner from 'ink-spinner' ;
77import fs from 'fs' ;
88import { $ } from 'execa' ;
9- import { cwd } from 'process' ;
109
1110export default function Publish ( { cli} : { cli : Result < Flags > } ) {
1211 const [ isInProjectDir , setIsInProjectDir ] = useState ( false ) ;
@@ -18,6 +17,10 @@ export default function Publish({cli}: {cli: Result<Flags>}) {
1817 const [ isPublishingError , setIsPublishingError ] = useState ( false ) ;
1918 const [ isPublished , setIsPublished ] = useState ( false ) ;
2019
20+ const [ failureMessage , setFailureMessage ] = useState < string | undefined > (
21+ undefined ,
22+ ) ;
23+
2124 useEffect ( ( ) => {
2225 // Check if the current dir contains pulse.config.ts
2326 const currentDir = process . cwd ( ) ;
@@ -32,7 +35,7 @@ export default function Publish({cli}: {cli: Result<Flags>}) {
3235 async function checkAuth ( ) {
3336 const token = getToken ( ) ;
3437 if ( token ) {
35- const isValid = await checkToken ( token ) ;
38+ const isValid = await checkToken ( token , cli . flags . dev ) ;
3639 if ( isValid ) {
3740 setIsAuthenticated ( true ) ;
3841 }
@@ -77,7 +80,9 @@ export default function Publish({cli}: {cli: Result<Flags>}) {
7780
7881 // Send the file to the server
7982 const res = await fetch (
80- 'https://pulse-editor.com/api/extension/publish' ,
83+ cli . flags . dev
84+ ? 'http://localhost:3000/api/extension/publish'
85+ : 'https://pulse-editor.com/api/extension/publish' ,
8186 {
8287 method : 'POST' ,
8388 headers : {
@@ -91,6 +96,12 @@ export default function Publish({cli}: {cli: Result<Flags>}) {
9196 setIsPublished ( true ) ;
9297 } else {
9398 setIsPublishingError ( true ) ;
99+ const msg = await res . json ( ) ;
100+ if ( msg . error ) {
101+ setFailureMessage ( msg . error ) ;
102+ } else {
103+ setFailureMessage ( 'Unknown error occurred while publishing.' ) ;
104+ }
94105 }
95106 } catch ( error ) {
96107 console . error ( 'Error uploading the file:' , error ) ;
@@ -138,7 +149,12 @@ export default function Publish({cli}: {cli: Result<Flags>}) {
138149 </ Box >
139150 ) }
140151 { isPublishingError && (
141- < Text color = { 'redBright' } > ❌ Failed to publish extension.</ Text >
152+ < >
153+ < Text color = { 'redBright' } > ❌ Failed to publish extension.</ Text >
154+ { failureMessage && (
155+ < Text color = { 'redBright' } > Error: { failureMessage } </ Text >
156+ ) }
157+ </ >
142158 ) }
143159 { isPublished && (
144160 < Text color = { 'greenBright' } >
0 commit comments