mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
improve error messaging around studio config missing
This commit is contained in:
parent
e4aca2de5f
commit
3799970607
6 changed files with 30 additions and 15 deletions
|
@ -4,7 +4,7 @@ import deepDiff from 'deep-diff';
|
|||
import { drizzle } from 'drizzle-orm/sqlite-proxy';
|
||||
import type { Arguments } from 'yargs-parser';
|
||||
import type { AstroConfigWithDB } from '../../../types.js';
|
||||
import { appTokenError } from '../../../errors.js';
|
||||
import { APP_TOKEN_ERROR } from '../../../errors.js';
|
||||
import {
|
||||
createCurrentSnapshot,
|
||||
createEmptySnapshot,
|
||||
|
@ -41,7 +41,7 @@ export async function cmd({ config, flags }: { config: AstroConfig; flags: Argum
|
|||
process.exit(1);
|
||||
}
|
||||
if (!appToken) {
|
||||
console.error(appTokenError);
|
||||
console.error(APP_TOKEN_ERROR);
|
||||
process.exit(1);
|
||||
}
|
||||
// get all migrations from the filesystem
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { AstroConfig } from 'astro';
|
||||
import { sql } from 'drizzle-orm';
|
||||
import type { Arguments } from 'yargs-parser';
|
||||
import { appTokenError } from '../../../errors.js';
|
||||
import { APP_TOKEN_ERROR } from '../../../errors.js';
|
||||
import { getAstroStudioEnv, getRemoteDatabaseUrl } from '../../../utils.js';
|
||||
import { createRemoteDatabaseClient } from '../../../../runtime/db-client.js';
|
||||
|
||||
|
@ -9,7 +9,7 @@ export async function cmd({ flags }: { config: AstroConfig; flags: Arguments })
|
|||
const query = flags.query;
|
||||
const appToken = flags.token ?? getAstroStudioEnv().ASTRO_STUDIO_APP_TOKEN;
|
||||
if (!appToken) {
|
||||
console.error(appTokenError);
|
||||
console.error(APP_TOKEN_ERROR);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
import type { AstroConfig } from 'astro';
|
||||
import type { Arguments } from 'yargs-parser';
|
||||
import { STUDIO_CONFIG_MISSING_CLI_ERROR } from '../errors.js';
|
||||
|
||||
export async function cli({ flags, config }: { flags: Arguments; config: AstroConfig }) {
|
||||
const command = flags._[3] as string;
|
||||
|
||||
if (!config.db?.studio) {
|
||||
console.log(STUDIO_CONFIG_MISSING_CLI_ERROR);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
switch (command) {
|
||||
case 'shell': {
|
||||
const { cmd: shellCommand } = await import('./commands/shell/index.js');
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
import { red } from 'kleur/colors';
|
||||
import { cyan, bold, red } from 'kleur/colors';
|
||||
|
||||
export const appTokenError = `${red(
|
||||
export const APP_TOKEN_ERROR = `${red(
|
||||
'⚠️ App token invalid or expired.'
|
||||
)} Please generate a new one from your the Studio dashboard under project settings.`;
|
||||
|
||||
export const STUDIO_CONFIG_MISSING_WRITABLE_COLLECTIONS_ERROR = (collectionName: string) =>
|
||||
red(`⚠️ Writable collection ${bold(collectionName)} requires Astro Studio.`) +
|
||||
` Visit ${cyan('https://astro.build/studio')} to create your account` +
|
||||
` and then set ${bold('studio: true')} in your astro.config.js file to enable.`;
|
||||
|
||||
export const STUDIO_CONFIG_MISSING_CLI_ERROR =
|
||||
red('⚠️ This command requires Astro Studio.') +
|
||||
` Visit ${cyan('https://astro.build/studio')} to create your account` +
|
||||
` and then set ${bold('studio: true')} in your astro.config.js file to enable.`;
|
||||
|
|
|
@ -8,7 +8,7 @@ import { DB_PATH } from '../consts.js';
|
|||
import { createLocalDatabaseClient } from '../../runtime/db-client.js';
|
||||
import { astroConfigWithDbSchema } from '../types.js';
|
||||
import { getAstroStudioEnv, type VitePlugin } from '../utils.js';
|
||||
import { appTokenError } from '../errors.js';
|
||||
import { APP_TOKEN_ERROR, STUDIO_CONFIG_MISSING_WRITABLE_COLLECTIONS_ERROR } from '../errors.js';
|
||||
import { errorMap } from './error-map.js';
|
||||
import { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
@ -31,20 +31,18 @@ function astroDBIntegration(): AstroIntegration {
|
|||
setCollectionsMeta(collections);
|
||||
|
||||
const studio = configWithDb.db?.studio ?? false;
|
||||
if (!studio && Object.values(collections).some((c) => c.writable)) {
|
||||
logger.warn(
|
||||
`Writable collections should only be used with Astro Studio. Did you set the ${bold(
|
||||
'studio'
|
||||
)} flag in your astro config?`
|
||||
);
|
||||
const foundWritableCollection = Object.entries(collections).find(([, c]) => c.writable);
|
||||
if (!studio && foundWritableCollection) {
|
||||
logger.error(STUDIO_CONFIG_MISSING_WRITABLE_COLLECTIONS_ERROR(foundWritableCollection[0]));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let dbPlugin: VitePlugin;
|
||||
if (studio && command === 'build') {
|
||||
const appToken = getAstroStudioEnv().ASTRO_STUDIO_APP_TOKEN;
|
||||
if (!appToken) {
|
||||
logger.error(appTokenError);
|
||||
process.exit(0);
|
||||
logger.error(APP_TOKEN_ERROR);
|
||||
process.exit(1);
|
||||
}
|
||||
dbPlugin = vitePluginDb({
|
||||
connectToStudio: true,
|
||||
|
|
|
@ -17,6 +17,7 @@ const Themes = defineWritableCollection({
|
|||
export default defineConfig({
|
||||
integrations: [db()],
|
||||
db: {
|
||||
studio: true,
|
||||
collections: { Author, Themes },
|
||||
data({ seed }) {
|
||||
seed(Author, [
|
||||
|
|
Loading…
Reference in a new issue