-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add minimal create-astro CLI * docs: update readme
- Loading branch information
1 parent
9c980a1
commit 61ccd59
Showing
9 changed files
with
516 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
src/parser/parse/**/*.ts | ||
vscode/**/*.ts | ||
create-astro/**/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env node | ||
import cli from './index.js'; | ||
|
||
cli(process.argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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}`; | ||
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; | ||
} |
Oops, something went wrong.