[ci] yarn format
This commit is contained in:
parent
6bca7c83a7
commit
a7594cfcdf
3 changed files with 85 additions and 83 deletions
|
@ -9,79 +9,78 @@ const args = yargs(process.argv);
|
||||||
prompts.override(args);
|
prompts.override(args);
|
||||||
|
|
||||||
export function mkdirp(dir: string) {
|
export function mkdirp(dir: string) {
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(dir, { recursive: true });
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code === 'EEXIST') return;
|
if (e.code === 'EEXIST') return;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
||||||
|
|
||||||
export async function main() {
|
export async function main() {
|
||||||
console.log('\n' + bold('Welcome to Astro!') + gray(` (create-astro v${version})`));
|
console.log('\n' + bold('Welcome to Astro!') + gray(` (create-astro v${version})`));
|
||||||
console.log(`If you encounter a problem, visit ${cyan('https://github.com/snowpack/astro/issues')} to search or file a new issue.\n`);
|
console.log(`If you encounter a problem, visit ${cyan('https://github.com/snowpack/astro/issues')} to search or file a new issue.\n`);
|
||||||
|
|
||||||
console.log(green(`>`) + gray(` Prepare for liftoff.`));
|
|
||||||
console.log(green(`>`) + gray(` Gathering mission details...`));
|
|
||||||
|
|
||||||
const cwd = args['_'][2] || '.';
|
console.log(green(`>`) + gray(` Prepare for liftoff.`));
|
||||||
if (fs.existsSync(cwd)) {
|
console.log(green(`>`) + gray(` Gathering mission details...`));
|
||||||
if (fs.readdirSync(cwd).length > 0) {
|
|
||||||
const response = await prompts({
|
|
||||||
type: 'confirm',
|
|
||||||
name: 'forceOverwrite',
|
|
||||||
message: 'Directory not empty. Continue?',
|
|
||||||
initial: false
|
|
||||||
});
|
|
||||||
if (!response.forceOverwrite) {
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mkdirp(cwd);
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = /** @type {import('./types/internal').Options} */ (await prompts([
|
const cwd = args['_'][2] || '.';
|
||||||
{
|
if (fs.existsSync(cwd)) {
|
||||||
type: 'select',
|
if (fs.readdirSync(cwd).length > 0) {
|
||||||
name: 'template',
|
const response = await prompts({
|
||||||
message: 'Which app template would you like to use?',
|
type: 'confirm',
|
||||||
choices: TEMPLATES
|
name: 'forceOverwrite',
|
||||||
},
|
message: 'Directory not empty. Continue?',
|
||||||
]));
|
initial: false,
|
||||||
|
});
|
||||||
|
if (!response.forceOverwrite) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mkdirp(cwd);
|
||||||
|
}
|
||||||
|
|
||||||
const emitter = degit(`snowpackjs/astro/examples/${options.template}`, {
|
const options = /** @type {import('./types/internal').Options} */ await prompts([
|
||||||
cache: false,
|
{
|
||||||
force: true,
|
type: 'select',
|
||||||
verbose: false,
|
name: 'template',
|
||||||
});
|
message: 'Which app template would you like to use?',
|
||||||
|
choices: TEMPLATES,
|
||||||
try {
|
},
|
||||||
// emitter.on('info', info => { console.log(info.message) });
|
]);
|
||||||
await emitter.clone(cwd);
|
|
||||||
} catch (err) {
|
|
||||||
// degit is compiled, so the stacktrace is pretty noisy. Just report the message.
|
|
||||||
console.error(red(err.message));
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(bold(green('✔ Copied project files')));
|
const emitter = degit(`snowpackjs/astro/examples/${options.template}`, {
|
||||||
|
cache: false,
|
||||||
|
force: true,
|
||||||
|
verbose: false,
|
||||||
|
});
|
||||||
|
|
||||||
console.log('\nNext steps:');
|
try {
|
||||||
let i = 1;
|
// emitter.on('info', info => { console.log(info.message) });
|
||||||
|
await emitter.clone(cwd);
|
||||||
|
} catch (err) {
|
||||||
|
// degit is compiled, so the stacktrace is pretty noisy. Just report the message.
|
||||||
|
console.error(red(err.message));
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
const relative = path.relative(process.cwd(), cwd);
|
console.log(bold(green('✔ Copied project files')));
|
||||||
if (relative !== '') {
|
|
||||||
console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(` ${i++}: ${bold(cyan('npm install'))} (or pnpm install, yarn, etc)`);
|
console.log('\nNext steps:');
|
||||||
console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional step)`);
|
let i = 1;
|
||||||
console.log(` ${i++}: ${bold(cyan('npm start'))} (or pnpm, yarn, etc)`);
|
|
||||||
|
|
||||||
console.log(`\nTo close the dev server, hit ${bold(cyan('Ctrl-C'))}`);
|
const relative = path.relative(process.cwd(), cwd);
|
||||||
console.log('\nStuck? Visit us at https://astro.build/chat\n');
|
if (relative !== '') {
|
||||||
}
|
console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(` ${i++}: ${bold(cyan('npm install'))} (or pnpm install, yarn, etc)`);
|
||||||
|
console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional step)`);
|
||||||
|
console.log(` ${i++}: ${bold(cyan('npm start'))} (or pnpm, yarn, etc)`);
|
||||||
|
|
||||||
|
console.log(`\nTo close the dev server, hit ${bold(cyan('Ctrl-C'))}`);
|
||||||
|
console.log('\nStuck? Visit us at https://astro.build/chat\n');
|
||||||
|
}
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
export const TEMPLATES = [,
|
export const TEMPLATES = [
|
||||||
{
|
,
|
||||||
title: 'Starter Kit (Generic)',
|
{
|
||||||
value: 'starter'
|
title: 'Starter Kit (Generic)',
|
||||||
}, {
|
value: 'starter',
|
||||||
title: 'Blog',
|
},
|
||||||
value: 'blog'
|
{
|
||||||
},
|
title: 'Blog',
|
||||||
{
|
value: 'blog',
|
||||||
title: 'Documentation',
|
},
|
||||||
value: 'docs'
|
{
|
||||||
},
|
title: 'Documentation',
|
||||||
{
|
value: 'docs',
|
||||||
title: 'Portfolio',
|
},
|
||||||
value: 'portfolio'
|
{
|
||||||
}];
|
title: 'Portfolio',
|
||||||
|
value: 'portfolio',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { suite } from 'uvu';
|
||||||
import execa from 'execa';
|
import execa from 'execa';
|
||||||
import del from 'del';
|
import del from 'del';
|
||||||
import * as assert from 'uvu/assert';
|
import * as assert from 'uvu/assert';
|
||||||
import {TEMPLATES} from '../dist/templates.js';
|
import { TEMPLATES } from '../dist/templates.js';
|
||||||
|
|
||||||
const CreateAstro = suite('npm init astro');
|
const CreateAstro = suite('npm init astro');
|
||||||
|
|
||||||
|
@ -17,14 +17,14 @@ CreateAstro.before(async () => {
|
||||||
await fs.promises.mkdir(fixturesDir);
|
await fs.promises.mkdir(fixturesDir);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const {value: template} of TEMPLATES) {
|
for (const { value: template } of TEMPLATES) {
|
||||||
// TODO: Unskip once repo is made public. Because the repo is private, the templates can't yet be downloaded.
|
// TODO: Unskip once repo is made public. Because the repo is private, the templates can't yet be downloaded.
|
||||||
CreateAstro.skip(template, async () => {
|
CreateAstro.skip(template, async () => {
|
||||||
const testDirectory = path.join(fixturesDir, template);
|
const testDirectory = path.join(fixturesDir, template);
|
||||||
const { stdout } = await execa('../../create-astro.mjs', [testDirectory, '--template', template, '--force-overwrite'], { cwd: path.join(cwd, 'fixtures') });
|
const { stdout } = await execa('../../create-astro.mjs', [testDirectory, '--template', template, '--force-overwrite'], { cwd: path.join(cwd, 'fixtures') });
|
||||||
|
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
// test: path should formatted as './{dirName}'
|
// test: path should formatted as './{dirName}'
|
||||||
assert.not.match(stdout, '././');
|
assert.not.match(stdout, '././');
|
||||||
|
|
||||||
const DOES_HAVE = ['.gitignore', 'package.json', 'public', 'src'];
|
const DOES_HAVE = ['.gitignore', 'package.json', 'public', 'src'];
|
||||||
|
|
Loading…
Reference in a new issue