Skip to content

Commit

Permalink
config fix
Browse files Browse the repository at this point in the history
  • Loading branch information
azuradara committed Oct 11, 2023
1 parent 4e11b51 commit fbe80a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions packages/app/lib/cli/commands/app/dev.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Env, Filesystem, Http, Path, Session, Tasks } from '@youcan/cli-kit';
import { AppCommand } from '@/util/theme-command';
import type { AppConfig, InitialAppConfig } from '@/types';
import type { InitialAppConfig } from '@/types';

class Dev extends AppCommand {
async run(): Promise<any> {
Expand All @@ -11,6 +11,10 @@ class Dev extends AppCommand {
{
title: 'Loading app configuration..',
async task(context, _) {
if (!await Filesystem.exists(path)) {
throw new Error('Could not find the app\'s configuration file.');
}

context.config = await Filesystem.readJsonFile<InitialAppConfig>(path);
},
},
Expand All @@ -20,11 +24,21 @@ class Dev extends AppCommand {
return ctx.config!.id != null;
},
async task(context, _) {
context.config = await Http.post<AppConfig>(`${Env.apiHostname()}/apps/draft/create`, {
const res = await Http.post<Record<string, any>>(`${Env.apiHostname()}/apps/draft/create`, {
headers: { Authorization: `Bearer ${session.access_token}` },
body: JSON.stringify({ name: context.config!.name }),
});

context.config = {
name: res.name,
id: res.id,
url: res.url,
oauth: {
scopes: res.scopes,
client_id: res.client_id,
},
};

await Filesystem.writeJsonFile(path, context.config);
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-kit/lib/node/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { exit } from 'process';
import { Loader } from '@/internal/node/ui';

export interface Task<T = unknown> {
Expand Down Expand Up @@ -33,8 +34,7 @@ export async function run<T = unknown>(tasks: Task<T>[]) {
}
catch (err) {
loader.error(String(err));

throw err;
exit(1);
}
});
}
Expand Down

0 comments on commit fbe80a0

Please sign in to comment.