mirror of
https://github.com/withastro/astro.git
synced 2025-01-13 22:11:20 -05:00
add shortcut link command from studio web ui
This commit is contained in:
parent
c9ce9d2309
commit
25c09d3ef4
1 changed files with 8 additions and 6 deletions
|
@ -6,24 +6,26 @@ import { PROJECT_ID_FILE, getSessionIdFromFile } from '../../../tokens.js';
|
||||||
import { getAstroStudioUrl } from '../../../utils.js';
|
import { getAstroStudioUrl } from '../../../utils.js';
|
||||||
import { MISSING_SESSION_ID_ERROR } from '../../../errors.js';
|
import { MISSING_SESSION_ID_ERROR } from '../../../errors.js';
|
||||||
|
|
||||||
export async function cmd({ }: { config: AstroConfig; flags: Arguments }) {
|
export async function cmd({ flags }: { config: AstroConfig; flags: Arguments }) {
|
||||||
const linkUrl = new URL(getAstroStudioUrl() + '/auth/cli/link');
|
const linkUrl = new URL(getAstroStudioUrl() + '/auth/cli/link');
|
||||||
const sessionToken = await getSessionIdFromFile();
|
const sessionToken = await getSessionIdFromFile();
|
||||||
if (!sessionToken) {
|
if (!sessionToken) {
|
||||||
console.error(MISSING_SESSION_ID_ERROR);
|
console.error(MISSING_SESSION_ID_ERROR);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
let body = {id: flags._[4]} as {id?: string; projectIdName?: string; workspaceIdName?: string};
|
||||||
const workspaceIdName = await promptWorkspaceName();
|
if (!body.id) {
|
||||||
const projectIdName = await promptProjectName();
|
const workspaceIdName = await promptWorkspaceName();
|
||||||
|
const projectIdName = await promptProjectName();
|
||||||
|
body = {projectIdName, workspaceIdName};
|
||||||
|
}
|
||||||
const response = await fetch(linkUrl, {
|
const response = await fetch(linkUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${await getSessionIdFromFile()}`,
|
Authorization: `Bearer ${await getSessionIdFromFile()}`,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({projectIdName, workspaceIdName})
|
body: JSON.stringify(body)
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error(`Failed to link project: ${response.status} ${response.statusText}`);
|
console.error(`Failed to link project: ${response.status} ${response.statusText}`);
|
||||||
|
|
Loading…
Add table
Reference in a new issue