Skip to content

Commit c76ecaa

Browse files
authored
Merge pull request #22 from ClayPulse/dev
Add CLI dev mode and connect extension marketplace
2 parents db38c4a + 47a66df commit c76ecaa

File tree

8 files changed

+499
-383
lines changed

8 files changed

+499
-383
lines changed

npm-packages/cli/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm-packages/cli/source/components/commands/login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default function Login({cli}: {cli: Result<Flags>}) {
6666
useEffect(() => {
6767
// Only check token validity when it is set
6868
if (loginMethod === 'token' && token.length > 0) {
69-
checkToken(token).then(isValid => {
69+
checkToken(token, cli.flags.dev).then(isValid => {
7070
setIsAuthenticated(isValid);
7171
setIsCheckingAuth(false);
7272
});

npm-packages/cli/source/components/commands/publish.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {checkToken, getToken} from '../../lib/token.js';
66
import Spinner from 'ink-spinner';
77
import fs from 'fs';
88
import {$} from 'execa';
9-
import {cwd} from 'process';
109

1110
export 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'}>

npm-packages/cli/source/lib/cli-flags.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export const flags = defineFlags({
2222
type: 'string',
2323
shortFlag: 'f',
2424
},
25+
dev: {
26+
type: 'boolean',
27+
default: false,
28+
},
2529
});
2630

2731
export type Flags = typeof flags;

npm-packages/cli/source/lib/token.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,19 @@ export function isTokenInEnv() {
5151
return false;
5252
}
5353

54-
export async function checkToken(token: string) {
55-
const res = await fetch('https://pulse-editor.com/api/api-keys/check', {
56-
body: JSON.stringify({token}),
57-
headers: {
58-
'Content-Type': 'application/json',
54+
export async function checkToken(token: string, devMode: boolean) {
55+
const res = await fetch(
56+
devMode
57+
? 'http://localhost:3000/api/api-keys/check'
58+
: 'https://pulse-editor.com/api/api-keys/check',
59+
{
60+
body: JSON.stringify({token}),
61+
headers: {
62+
'Content-Type': 'application/json',
63+
},
64+
method: 'POST',
5965
},
60-
method: 'POST',
61-
});
66+
);
6267

6368
if (res.status === 200) {
6469
return true;

0 commit comments

Comments
 (0)