0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

feat(db): add support for pass-through astro db command

This commit is contained in:
Nate Moore 2024-01-18 15:51:30 -06:00
parent 4b4954e890
commit b8d19f93a1
7 changed files with 20 additions and 12 deletions

View file

@ -183,6 +183,7 @@
}, },
"devDependencies": { "devDependencies": {
"@astrojs/check": "^0.3.1", "@astrojs/check": "^0.3.1",
"@astrojs/db": "workspace:*",
"@playwright/test": "1.40.0", "@playwright/test": "1.40.0",
"@types/aria-query": "^5.0.4", "@types/aria-query": "^5.0.4",
"@types/babel__generator": "^7.6.7", "@types/babel__generator": "^7.6.7",

View file

@ -30,6 +30,7 @@ async function printAstroHelp() {
['add', 'Add an integration.'], ['add', 'Add an integration.'],
['build', 'Build your project and write it to disk.'], ['build', 'Build your project and write it to disk.'],
['check', 'Check your project for errors.'], ['check', 'Check your project for errors.'],
['db', 'Manage your Astro database.'],
['dev', 'Start the development server.'], ['dev', 'Start the development server.'],
['docs', 'Open documentation in your web browser.'], ['docs', 'Open documentation in your web browser.'],
['info', 'List info about your current Astro setup.'], ['info', 'List info about your current Astro setup.'],

View file

@ -20,7 +20,8 @@ export async function getPackage<T>(
): Promise<T | undefined> { ): Promise<T | undefined> {
let packageImport; let packageImport;
try { try {
await tryResolve(packageName, options.cwd ?? process.cwd()); // TODO: uncomment this when `@astrojs/db` works
// await tryResolve(packageName, options.cwd ?? process.cwd());
// The `require.resolve` is required as to avoid Node caching the failed `import` // The `require.resolve` is required as to avoid Node caching the failed `import`
packageImport = await import(packageName); packageImport = await import(packageName);

View file

@ -31,14 +31,14 @@
] ]
} }
}, },
"bin": {
"studio": "./dist/cli/bin.js"
},
"files": [ "files": [
"index.d.ts", "index.d.ts",
"dist", "dist",
"components" "components"
], ],
"bin": {
"studio": "./dist/cli/index.js"
},
"scripts": { "scripts": {
"build": "astro-scripts build \"src/**/*.ts\" && tsc", "build": "astro-scripts build \"src/**/*.ts\" && tsc",
"build:ci": "astro-scripts build \"src/**/*.ts\"", "build:ci": "astro-scripts build \"src/**/*.ts\"",

View file

@ -0,0 +1,9 @@
#!/usr/bin/env node
import { cli } from './index.js';
async function main() {
const [command, ...args] = process.argv.slice(2);
await cli(command, args);
}
await main();

View file

@ -1,13 +1,10 @@
#!/usr/bin/env node
import { red } from 'kleur/colors'; import { red } from 'kleur/colors';
import { astroConfigWithDbSchema } from '../config.js'; import { astroConfigWithDbSchema } from '../config.js';
import { errorMap } from '../error-map.js'; import { errorMap } from '../error-map.js';
import { loadAstroConfig } from '../load-astro-config.js'; import { loadAstroConfig } from '../load-astro-config.js';
async function main() { export async function cli(command: string, _args: string[] = []) {
const cmd = process.argv[2]; switch (command) {
switch (cmd) {
case 'sync': { case 'sync': {
const { sync } = await import('./sync/index.js'); const { sync } = await import('./sync/index.js');
const astroConfig = await getAstroConfigOrExit(); const astroConfig = await getAstroConfigOrExit();
@ -18,7 +15,7 @@ async function main() {
} }
default: { default: {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(`Unknown command: ${cmd}`); console.error(`Unknown command: ${command}`);
return; return;
} }
} }
@ -37,5 +34,3 @@ async function getAstroConfigOrExit(root: string = process.cwd()) {
); );
process.exit(0); process.exit(0);
} }
await main();

View file

@ -1,3 +1,4 @@
export { defineCollection, defineWritableCollection, field } from './config.js'; export { defineCollection, defineWritableCollection, field } from './config.js';
export { cli } from './cli/index.js';
export { integration as default } from './integration.js'; export { integration as default } from './integration.js';