[ci] format
This commit is contained in:
parent
0bf0758fb8
commit
814327f409
4 changed files with 84 additions and 44 deletions
5
packages/astro/types.d.ts
vendored
5
packages/astro/types.d.ts
vendored
|
@ -4,7 +4,10 @@ import { AstroBuiltinAttributes } from './dist/@types/astro';
|
||||||
/** Any supported HTML or SVG element name, as defined by the HTML specification */
|
/** Any supported HTML or SVG element name, as defined by the HTML specification */
|
||||||
export type HTMLTag = keyof astroHTML.JSX.DefinedIntrinsicElements;
|
export type HTMLTag = keyof astroHTML.JSX.DefinedIntrinsicElements;
|
||||||
/** The built-in attributes for any known HTML or SVG element name */
|
/** The built-in attributes for any known HTML or SVG element name */
|
||||||
export type HTMLAttributes<Tag extends HTMLTag> = Omit<astroHTML.JSX.IntrinsicElements[Tag], keyof AstroBuiltinAttributes>;
|
export type HTMLAttributes<Tag extends HTMLTag> = Omit<
|
||||||
|
astroHTML.JSX.IntrinsicElements[Tag],
|
||||||
|
keyof AstroBuiltinAttributes
|
||||||
|
>;
|
||||||
|
|
||||||
// TODO: Enable generic/polymorphic types once compiler output stabilizes in the Language Server
|
// TODO: Enable generic/polymorphic types once compiler output stabilizes in the Language Server
|
||||||
// type PolymorphicAttributes<P extends { as: HTMLTag }> = Omit<(P & HTMLAttributes<P['as']>), 'as'> & { as?: P['as'] };
|
// type PolymorphicAttributes<P extends { as: HTMLTag }> = Omit<(P & HTMLAttributes<P['as']>), 'as'> & { as?: P['as'] };
|
||||||
|
|
|
@ -1,20 +1,28 @@
|
||||||
/* eslint no-console: 'off' */
|
/* eslint no-console: 'off' */
|
||||||
|
import { color, generateProjectName, label, say } from '@astrojs/cli-kit';
|
||||||
|
import { random } from '@astrojs/cli-kit/utils';
|
||||||
import { assign, parse, stringify } from 'comment-json';
|
import { assign, parse, stringify } from 'comment-json';
|
||||||
import { downloadTemplate } from 'giget';
|
|
||||||
import { execa, execaCommand } from 'execa';
|
import { execa, execaCommand } from 'execa';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { say, label, color, generateProjectName } from '@astrojs/cli-kit';
|
import { downloadTemplate } from 'giget';
|
||||||
import { random } from '@astrojs/cli-kit/utils';
|
import { bold, dim, green, reset, yellow } from 'kleur/colors';
|
||||||
import { bold, dim, green, red, reset, yellow } from 'kleur/colors';
|
|
||||||
import ora from 'ora';
|
import ora from 'ora';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import prompts from 'prompts';
|
import prompts from 'prompts';
|
||||||
import detectPackageManager from 'which-pm-runs';
|
import detectPackageManager from 'which-pm-runs';
|
||||||
import yargs from 'yargs-parser';
|
import yargs from 'yargs-parser';
|
||||||
import { loadWithRocketGradient, rocketAscii } from './gradient.js';
|
import { loadWithRocketGradient, rocketAscii } from './gradient.js';
|
||||||
import { defaultLogLevel, logger } from './logger.js';
|
import { logger } from './logger.js';
|
||||||
|
import {
|
||||||
|
banner,
|
||||||
|
getName,
|
||||||
|
getVersion,
|
||||||
|
info,
|
||||||
|
nextSteps,
|
||||||
|
typescriptByDefault,
|
||||||
|
welcome,
|
||||||
|
} from './messages.js';
|
||||||
import { TEMPLATES } from './templates.js';
|
import { TEMPLATES } from './templates.js';
|
||||||
import { getName, getVersion, welcome, banner, typescriptByDefault, nextSteps, info } from './messages.js';
|
|
||||||
|
|
||||||
// NOTE: In the v7.x version of npm, the default behavior of `npm init` was changed
|
// NOTE: In the v7.x version of npm, the default behavior of `npm init` was changed
|
||||||
// to no longer require `--` to pass args and instead pass `--` directly to us. This
|
// to no longer require `--` to pass args and instead pass `--` directly to us. This
|
||||||
|
@ -83,9 +91,15 @@ export async function main() {
|
||||||
logger.debug('Verbose logging turned on');
|
logger.debug('Verbose logging turned on');
|
||||||
if (!args.skipHouston) {
|
if (!args.skipHouston) {
|
||||||
await say([
|
await say([
|
||||||
['Welcome', 'to', label('astro', color.bgGreen, color.black), color.green(`v${version}`) + ',', `${username}!`],
|
[
|
||||||
|
'Welcome',
|
||||||
|
'to',
|
||||||
|
label('astro', color.bgGreen, color.black),
|
||||||
|
color.green(`v${version}`) + ',',
|
||||||
|
`${username}!`,
|
||||||
|
],
|
||||||
random(welcome),
|
random(welcome),
|
||||||
]);
|
]);
|
||||||
await banner(version);
|
await banner(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +239,7 @@ export async function main() {
|
||||||
installSpinner.text = green('Packages installed!');
|
installSpinner.text = green('Packages installed!');
|
||||||
installSpinner.succeed();
|
installSpinner.succeed();
|
||||||
} else {
|
} else {
|
||||||
await info('No problem!', 'Remember to install dependencies after setup.')
|
await info('No problem!', 'Remember to install dependencies after setup.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const gitResponse = await prompts(
|
const gitResponse = await prompts(
|
||||||
|
@ -251,7 +265,10 @@ export async function main() {
|
||||||
await execaCommand('git init', { cwd });
|
await execaCommand('git init', { cwd });
|
||||||
ora().succeed('Git repository created!');
|
ora().succeed('Git repository created!');
|
||||||
} else {
|
} else {
|
||||||
await info('Sounds good!', `You can come back and run ${color.reset(`git init`)}${color.dim(' later.')}`)
|
await info(
|
||||||
|
'Sounds good!',
|
||||||
|
`You can come back and run ${color.reset(`git init`)}${color.dim(' later.')}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tsResponse = await prompts(
|
const tsResponse = await prompts(
|
||||||
|
@ -315,7 +332,7 @@ export async function main() {
|
||||||
});
|
});
|
||||||
ora().succeed('TypeScript settings applied!');
|
ora().succeed('TypeScript settings applied!');
|
||||||
}
|
}
|
||||||
|
|
||||||
let projectDir = path.relative(process.cwd(), cwd);
|
let projectDir = path.relative(process.cwd(), cwd);
|
||||||
const devCmd = pkgManager === 'npm' ? 'npm run dev' : `${pkgManager} dev`;
|
const devCmd = pkgManager === 'npm' ? 'npm run dev' : `${pkgManager} dev`;
|
||||||
await nextSteps({ projectDir, devCmd });
|
await nextSteps({ projectDir, devCmd });
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
/* eslint no-console: 'off' */
|
/* eslint no-console: 'off' */
|
||||||
import { exec } from 'node:child_process';
|
|
||||||
import { get } from 'node:https';
|
|
||||||
import { color, label } from '@astrojs/cli-kit';
|
import { color, label } from '@astrojs/cli-kit';
|
||||||
import { sleep } from '@astrojs/cli-kit/utils';
|
import { sleep } from '@astrojs/cli-kit/utils';
|
||||||
|
import { exec } from 'node:child_process';
|
||||||
|
import { get } from 'node:https';
|
||||||
import stripAnsi from 'strip-ansi';
|
import stripAnsi from 'strip-ansi';
|
||||||
|
|
||||||
export const welcome = [
|
export const welcome = [
|
||||||
`Let's claim your corner of the internet.`,
|
`Let's claim your corner of the internet.`,
|
||||||
`I'll be your assistant today.`,
|
`I'll be your assistant today.`,
|
||||||
`Let's build something awesome!`,
|
`Let's build something awesome!`,
|
||||||
`Let's build something great!`,
|
`Let's build something great!`,
|
||||||
`Let's build something fast!`,
|
`Let's build something fast!`,
|
||||||
`Let's make the web weird!`,
|
`Let's make the web weird!`,
|
||||||
`Let's make the web a better place!`,
|
`Let's make the web a better place!`,
|
||||||
`Let's create a new project!`,
|
`Let's create a new project!`,
|
||||||
`Let's create something unqiue!`,
|
`Let's create something unqiue!`,
|
||||||
`Time to build a new website.`,
|
`Time to build a new website.`,
|
||||||
`Time to build a faster website.`,
|
`Time to build a faster website.`,
|
||||||
`Time to build a sweet new website.`,
|
`Time to build a sweet new website.`,
|
||||||
`We're glad to have you on board.`,
|
`We're glad to have you on board.`,
|
||||||
`Keeping the internet weird since 2021.`,
|
`Keeping the internet weird since 2021.`,
|
||||||
`Initiating launch sequence...`,
|
`Initiating launch sequence...`,
|
||||||
`Initiating launch sequence... right... now!`,
|
`Initiating launch sequence... right... now!`,
|
||||||
`Awaiting further instructions.`,
|
`Awaiting further instructions.`,
|
||||||
]
|
];
|
||||||
|
|
||||||
export function getName() {
|
export function getName() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
@ -44,11 +44,10 @@ export function getName() {
|
||||||
let v: string;
|
let v: string;
|
||||||
export function getVersion() {
|
export function getVersion() {
|
||||||
return new Promise<string>((resolve) => {
|
return new Promise<string>((resolve) => {
|
||||||
if (v)
|
if (v) return resolve(v);
|
||||||
return resolve(v);
|
|
||||||
get('https://registry.npmjs.org/astro/latest', (res) => {
|
get('https://registry.npmjs.org/astro/latest', (res) => {
|
||||||
let body = '';
|
let body = '';
|
||||||
res.on('data', chunk => body += chunk);
|
res.on('data', (chunk) => (body += chunk));
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
const { version } = JSON.parse(body);
|
const { version } = JSON.parse(body);
|
||||||
v = version;
|
v = version;
|
||||||
|
@ -59,7 +58,11 @@ export function getVersion() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function banner(version: string) {
|
export async function banner(version: string) {
|
||||||
return console.log(`\n${label('astro', color.bgGreen, color.black)} ${color.green(color.bold(`v${version}`))} ${color.bold('Launch sequence initiated.')}\n`);
|
return console.log(
|
||||||
|
`\n${label('astro', color.bgGreen, color.black)} ${color.green(
|
||||||
|
color.bold(`v${version}`)
|
||||||
|
)} ${color.bold('Launch sequence initiated.')}\n`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function info(prefix: string, text: string) {
|
export async function info(prefix: string, text: string) {
|
||||||
|
@ -83,25 +86,40 @@ export async function error(prefix: string, text: string) {
|
||||||
|
|
||||||
export async function typescriptByDefault() {
|
export async function typescriptByDefault() {
|
||||||
await info(`Cool!`, 'Astro comes with TypeScript support enabled by default.');
|
await info(`Cool!`, 'Astro comes with TypeScript support enabled by default.');
|
||||||
console.log(`${' '.repeat(3)}${color.dim(`We'll default to the most relaxed settings for you.`)}`);
|
console.log(
|
||||||
|
`${' '.repeat(3)}${color.dim(`We'll default to the most relaxed settings for you.`)}`
|
||||||
|
);
|
||||||
await sleep(300);
|
await sleep(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function nextSteps({ projectDir, devCmd }: { projectDir: string; devCmd: string; }) {
|
export async function nextSteps({ projectDir, devCmd }: { projectDir: string; devCmd: string }) {
|
||||||
const max = process.stdout.columns;
|
const max = process.stdout.columns;
|
||||||
const prefix = max < 80 ? ' ' : ' '.repeat(9);
|
const prefix = max < 80 ? ' ' : ' '.repeat(9);
|
||||||
await sleep(200);
|
await sleep(200);
|
||||||
console.log(`\n ${color.bgCyan(` ${color.black('next')} `)} ${color.bold('Liftoff confirmed. Explore your project!')}`);
|
console.log(
|
||||||
|
`\n ${color.bgCyan(` ${color.black('next')} `)} ${color.bold(
|
||||||
|
'Liftoff confirmed. Explore your project!'
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
await sleep(100);
|
await sleep(100);
|
||||||
if (projectDir !== '') {
|
if (projectDir !== '') {
|
||||||
const enter = [`\n${prefix}Enter your project directory using`, color.cyan(`cd ./${projectDir}`, '')];
|
const enter = [
|
||||||
|
`\n${prefix}Enter your project directory using`,
|
||||||
|
color.cyan(`cd ./${projectDir}`, ''),
|
||||||
|
];
|
||||||
const len = enter[0].length + stripAnsi(enter[1]).length;
|
const len = enter[0].length + stripAnsi(enter[1]).length;
|
||||||
console.log(enter.join((len > max) ? '\n' + prefix : ' '));
|
console.log(enter.join(len > max ? '\n' + prefix : ' '));
|
||||||
}
|
}
|
||||||
console.log(`${prefix}Run ${color.cyan(devCmd)} to start the dev server. ${color.cyan('CTRL+C')} to stop.`);
|
console.log(
|
||||||
|
`${prefix}Run ${color.cyan(devCmd)} to start the dev server. ${color.cyan('CTRL+C')} to stop.`
|
||||||
|
);
|
||||||
await sleep(100);
|
await sleep(100);
|
||||||
console.log(`${prefix}Add frameworks like ${color.cyan(`react`)} or ${color.cyan('tailwind')} using ${color.cyan('astro add')}.`);
|
console.log(
|
||||||
|
`${prefix}Add frameworks like ${color.cyan(`react`)} or ${color.cyan(
|
||||||
|
'tailwind'
|
||||||
|
)} using ${color.cyan('astro add')}.`
|
||||||
|
);
|
||||||
await sleep(100);
|
await sleep(100);
|
||||||
console.log(`\n${prefix}Stuck? Join us at ${color.cyan(`https://astro.build/chat`)}`);
|
console.log(`\n${prefix}Stuck? Join us at ${color.cyan(`https://astro.build/chat`)}`);
|
||||||
await sleep(200);
|
await sleep(200);
|
||||||
|
|
|
@ -42,7 +42,9 @@ export const PROMPT_MESSAGES = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export function setup(args = []) {
|
export function setup(args = []) {
|
||||||
const { stdout, stdin } = execa('../create-astro.mjs', [...args, '--skip-houston', '--dryrun'], { cwd: testDir });
|
const { stdout, stdin } = execa('../create-astro.mjs', [...args, '--skip-houston', '--dryrun'], {
|
||||||
|
cwd: testDir,
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
stdin,
|
stdin,
|
||||||
stdout,
|
stdout,
|
||||||
|
|
Loading…
Reference in a new issue