blob: 7f446c8695cba6a25e92dca3c98fd739bcf85dda (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
import type { Context } from './context.js';
import dns from 'node:dns/promises';
import { color } from '@astrojs/cli-kit';
import { verifyTemplate } from '@bluwy/giget-core';
import { bannerAbort, error, info, log } from '../messages.js';
import { getTemplateTarget } from './template.js';
export async function verify(
ctx: Pick<Context, 'version' | 'dryRun' | 'template' | 'ref' | 'exit'>,
) {
if (!ctx.dryRun) {
const online = await isOnline();
if (!online) {
bannerAbort();
log('');
error('error', `Unable to connect to the internet.`);
ctx.exit(1);
}
}
if (ctx.template) {
const target = getTemplateTarget(ctx.template, ctx.ref);
const ok = await verifyTemplate(target);
if (!ok) {
bannerAbort();
log('');
error('error', `Template ${color.reset(ctx.template)} ${color.dim('could not be found!')}`);
await info('check', 'https://astro.build/examples');
ctx.exit(1);
}
}
}
function isOnline(): Promise<boolean> {
return dns.lookup('github.com').then(
() => true,
() => false,
);
}
|