0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Warn on missing pages directory (#1902)

* Warn on missing pages directory

* skip hostname flag test

* kill process at end of config test

* fix hostname test

* cleanup console logs
This commit is contained in:
Jonathan Neal 2021-11-22 15:11:13 -05:00 committed by GitHub
parent f930270aed
commit 26de205b98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 9 deletions

View file

@ -36,6 +36,7 @@ function resolveArgs(flags: Arguments): CLIState {
sitemap: typeof flags.sitemap === 'boolean' ? flags.sitemap : undefined,
port: typeof flags.port === 'number' ? flags.port : undefined,
config: typeof flags.config === 'string' ? flags.config : undefined,
hostname: typeof flags.hostname === 'string' ? flags.hostname : undefined,
};
if (flags.version) {

View file

@ -48,7 +48,7 @@ class AstroBuilder {
const port = config.devOptions.port; // no need to save this (dont rely on port in builder)
this.logging = options.logging;
this.origin = config.buildOptions.site ? new URL(config.buildOptions.site).origin : `http://localhost:${port}`;
this.manifest = createRouteManifest({ config });
this.manifest = createRouteManifest({ config }, this.logging);
}
async build() {

View file

@ -76,7 +76,7 @@ export class AstroDevServer {
this.site = config.buildOptions.site ? new URL(config.buildOptions.site) : undefined;
this.devRoot = this.site ? this.site.pathname : '/';
this.url = new URL(this.devRoot, this.origin);
this.manifest = createRouteManifest({ config });
this.manifest = createRouteManifest({ config }, this.logging);
}
async start() {
@ -250,7 +250,7 @@ export class AstroDevServer {
return;
}
this.routeCache = {};
this.manifest = createRouteManifest({ config: this.config });
this.manifest = createRouteManifest({ config: this.config }, this.logging);
});
viteServer.watcher.on('unlink', (file) => {
// Only rebuild routes if deleted file is a page.
@ -258,7 +258,7 @@ export class AstroDevServer {
return;
}
this.routeCache = {};
this.manifest = createRouteManifest({ config: this.config });
this.manifest = createRouteManifest({ config: this.config }, this.logging);
});
viteServer.watcher.on('change', () => {
// No need to rebuild routes on file content changes.

View file

@ -83,7 +83,7 @@ interface Item {
}
/** Create manifest of all static routes */
export function createRouteManifest({ config, cwd }: { config: AstroConfig; cwd?: string }): ManifestData {
export function createRouteManifest({ config, cwd }: { config: AstroConfig; cwd?: string }, logging: LogOptions): ManifestData {
const components: string[] = [];
const routes: RouteData[] = [];
@ -194,7 +194,13 @@ export function createRouteManifest({ config, cwd }: { config: AstroConfig; cwd?
});
}
if (fs.existsSync(config.pages)) {
walk(fileURLToPath(config.pages), [], []);
} else {
const pagesDirRootRelative = config.pages.href.slice(config.projectRoot.href.length);
warn(logging, 'astro', `Missing pages directory: ${pagesDirRootRelative}`);
}
return {
routes,

View file

@ -21,12 +21,15 @@ describe('config', () => {
const proc = devCLI(cwdURL, args);
proc.stdout.setEncoding('utf8');
for await (const chunk of proc.stdout) {
if (/Local:/.test(chunk)) {
expect(chunk).to.include('127.0.0.1');
break;
}
}
proc.kill();
});
});
@ -36,14 +39,17 @@ describe('config', () => {
const cwdURL = new URL(cwd, import.meta.url);
const configPath = new URL('./config/my-config.mjs', cwdURL).pathname;
const args = ['--config', configPath];
const process = devCLI(cwdURL, args);
const proc = devCLI(cwdURL, args);
process.stdout.setEncoding('utf8');
for await (const chunk of process.stdout) {
proc.stdout.setEncoding('utf8');
for await (const chunk of proc.stdout) {
if (/Server started/.test(chunk)) {
break;
}
}
proc.kill();
});
});