4df1347156
* chore: use monorepo * chore: scaffold astro-scripts * chore: move tests inside packages/astro * chore: refactor tests, add scripts * chore: move parser to own module * chore: move runtime to packages/astro * fix: move parser to own package * test: fix prettier-plugin-astro tests * fix: tests * chore: update package-lock * chore: add changesets * fix: cleanup examples * fix: starter example * chore: update changeset config * chore: update changeset config * chore: setup changeset release workflow * chore: bump lockfiles * chore: prism => astro-prism * fix: tsc --emitDeclarationOnly * chore: final cleanup, switch to yarn * chore: add lerna * chore: update workflows to yarn * chore: update workflows * chore: remove lint workflow * chore: add astro-dev script * chore: add symlinked README
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
import * as fs from 'fs';
|
|
import { resolve } from 'path';
|
|
import decompress from 'decompress';
|
|
import { fileURLToPath, URL } from 'url';
|
|
import { join } from 'node:path';
|
|
|
|
const log = (...args) => console.log(' ', ...args);
|
|
export default async function createAstro(argv) {
|
|
const [name] = argv.slice(2);
|
|
const templateRoot = fileURLToPath(new URL('../create-astro/templates', import.meta.url));
|
|
if (!name) {
|
|
log();
|
|
log(`npm init astro <dest>`);
|
|
log(`Provide a destination!`);
|
|
process.exit(0);
|
|
}
|
|
|
|
log();
|
|
const dest = resolve(process.cwd(), name);
|
|
const relDest = name.slice(0, 2) === './' ? name : `./${name}`;
|
|
if (isEmpty(relDest)) {
|
|
await decompress(fs.readFileSync(join(templateRoot, 'starter.tar.gz')), dest);
|
|
log(`Your Astro project has been scaffolded at "${relDest}"`);
|
|
log();
|
|
log(`Next steps:`);
|
|
log();
|
|
log(` cd ${relDest}`);
|
|
log(` npm install`);
|
|
log(` npm run start`);
|
|
}
|
|
}
|
|
|
|
function isEmpty(path) {
|
|
try {
|
|
const files = fs.readdirSync(resolve(process.cwd(), path));
|
|
if (files.length > 0) {
|
|
log(`It looks like "${path}" isn't empty!`);
|
|
return false;
|
|
} else {
|
|
log(`Scaffolding Astro project at "${path}"`);
|
|
return true;
|
|
}
|
|
} catch (err) {
|
|
if (err.code !== 'ENOENT') throw err;
|
|
}
|
|
return true;
|
|
}
|