diff --git a/.changeset/large-glasses-sneeze.md b/.changeset/large-glasses-sneeze.md new file mode 100644 index 000000000..9005544ec --- /dev/null +++ b/.changeset/large-glasses-sneeze.md @@ -0,0 +1,5 @@ +--- +'create-astro': minor +--- + +Redesigned create-astro internals diff --git a/.changeset/short-pillows-study.md b/.changeset/short-pillows-study.md new file mode 100644 index 000000000..cf0e16be5 --- /dev/null +++ b/.changeset/short-pillows-study.md @@ -0,0 +1,5 @@ +--- +'create-astro': minor +--- + +New UI diff --git a/LICENSE b/LICENSE index fd80dc320..417b4ded9 100644 --- a/LICENSE +++ b/LICENSE @@ -22,8 +22,7 @@ SOFTWARE. """ - -This license applies to parts of the `src/compiler` subdirectory originating from the +This license applies to parts of the `packages/astro-parser` subdirectory originating from the https://github.com/sveltejs/svelte repository: @@ -34,5 +33,18 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +""" + """ +This license applies to parts of the `packages/create-astro` subdirectory originating from the +https://github.com/sveltejs/kit repository: + +Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +""" diff --git a/contributing.md b/contributing.md index ef6bcb392..9c6ba6b86 100644 --- a/contributing.md +++ b/contributing.md @@ -1,5 +1,12 @@ # Contributing +## Setting Up the Monorepo + +```shell +# git clone && cd ... +yarn install +``` + ## Making Pull Requests When making a pull request, add a changeset which helps with releases. diff --git a/examples/astro-markdown/package.json b/examples/astro-markdown/package.json index fe5cebb05..9071e0a64 100644 --- a/examples/astro-markdown/package.json +++ b/examples/astro-markdown/package.json @@ -1,15 +1,13 @@ { - "name": "@example/astro-markdown", + "name": "@astrojs/markdown-example", "version": "0.0.1", "private": true, "scripts": { "start": "astro dev", - "build": "astro build", - "astro-dev": "nodemon --delay 0.5 -w ../../packages/astro/dist -x '../../packages/astro/astro.mjs dev'" + "build": "astro build" }, "devDependencies": { - "astro": "0.12.9", - "nodemon": "^2.0.7" + "astro": "^0.12.9" }, "snowpack": { "workspaceRoot": "../.." diff --git a/packages/create-astro/src/templates/blog/_gitignore b/examples/blog/.gitignore similarity index 100% rename from packages/create-astro/src/templates/blog/_gitignore rename to examples/blog/.gitignore diff --git a/examples/blog/README.md b/examples/blog/README.md index 2a20654f2..87c48761c 100644 --- a/examples/blog/README.md +++ b/examples/blog/README.md @@ -1,5 +1,7 @@ # Astro Blog Example +> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun! + Features: - ✅ SEO-friendly setup with canonical URLs and OpenGraph data @@ -7,24 +9,39 @@ Features: - ✅ RSS 2.0 generation - ✅ Sitemap.xml generation -## Setup +## 🚀 Project Structure + +Inside of your Astro project, you'll see the following folders and files: ``` -yarn +/ +├── public/ +│ ├── robots.txt +│ └── favicon.ico +├── src/ +│ ├── components/ +│ │ └── Tour.astro +│ └── pages/ +│ └── index.astro +└── package.json ``` -## Dev +Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name. -``` -yarn start -``` +There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components. -Preview at `http://localhost:3000` +Any static assets, like images, can be placed in the `public/` directory. -## Build +## 🧞 Commands -``` -yarn build -``` +All commands are run from the root of the project, from a terminal: -Will output static site at `./dist` +| Command | Action | +|:----------------|:--------------------------------------------| +| `npm install` | Installs dependencies | +| `npm run start` | Starts local dev server at `localhost:3000` | +| `npm run build` | Build your production site to `./dist/` | + +## 👀 Want to learn more? + +Feel free to check [our documentation](https://github.com/snowpackjs/astro) or jump into our [Discord server](https://discord.gg/EsGdSGen). diff --git a/examples/blog/astro.config.mjs b/examples/blog/astro.config.mjs index 9933e9571..c7583a774 100644 --- a/examples/blog/astro.config.mjs +++ b/examples/blog/astro.config.mjs @@ -1,10 +1,14 @@ export default { - projectRoot: '.', - pages: './src/pages', - public: './public', - dist: './dist', + // projectRoot: '.', // Where to resolve all URLs relative to. Useful if you have a monorepo project. + // pages: './src/pages', // Path to Astro components, pages, and data + // dist: './dist', // When running `astro build`, path to final static output + // public: './public', // A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that don’t need processing. buildOptions: { - sitemap: true, - site: 'https://mysite.dev/', // change + // site: '', // Your public domain, e.g.: https://my-site.dev/. Used to generate sitemaps and canonical URLs. + // sitemap: true, // Generate sitemap (set to "false" to disable) + }, + devOptions: { + // port: 3000, // The port to run the dev server on. + // tailwindConfig: '', // Path to tailwind.config.js if used, e.g. './tailwind.config.js' }, }; diff --git a/packages/create-astro/src/templates/blog/meta.json b/examples/blog/meta.json similarity index 100% rename from packages/create-astro/src/templates/blog/meta.json rename to examples/blog/meta.json diff --git a/examples/blog/package.json b/examples/blog/package.json index 5d8d17115..c6faac56a 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -1,11 +1,10 @@ { - "name": "@example/blog", + "name": "@astrojs/example-blog", "version": "0.0.1", "private": true, "scripts": { "start": "astro dev", - "build": "astro build", - "astro-dev": "nodemon --delay 0.5 -w ../../packages/astro/dist -x '../../packages/astro/astro.mjs dev'" + "build": "astro build" }, "devDependencies": { "astro": "^0.12.9", diff --git a/examples/doc/public/favicon.svg b/examples/blog/public/favicon.svg similarity index 100% rename from examples/doc/public/favicon.svg rename to examples/blog/public/favicon.svg diff --git a/examples/doc/package.json b/examples/doc/package.json deleted file mode 100644 index 61d247ff8..000000000 --- a/examples/doc/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "@example/doc", - "version": "0.0.1", - "private": true, - "scripts": { - "start": "astro dev", - "build": "astro build", - "astro-dev": "nodemon --delay 0.5 -w ../../packages/astro/dist -x '../../packages/astro/astro.mjs dev'" - }, - "devDependencies": { - "astro": "^0.12.9", - "nodemon": "^2.0.7" - }, - "snowpack": { - "workspaceRoot": "../.." - } -} diff --git a/packages/create-astro/src/templates/starter/_gitignore b/examples/docs/.gitignore similarity index 100% rename from packages/create-astro/src/templates/starter/_gitignore rename to examples/docs/.gitignore diff --git a/examples/doc/astro.config.mjs b/examples/docs/astro.config.mjs similarity index 100% rename from examples/doc/astro.config.mjs rename to examples/docs/astro.config.mjs diff --git a/examples/docs/package.json b/examples/docs/package.json new file mode 100644 index 000000000..cb587286d --- /dev/null +++ b/examples/docs/package.json @@ -0,0 +1,15 @@ +{ + "name": "@astrojs/docs-template", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "astro dev", + "build": "astro build" + }, + "devDependencies": { + "astro": "^0.12.9" + }, + "snowpack": { + "workspaceRoot": "../.." + } +} diff --git a/examples/doc/public/code.css b/examples/docs/public/code.css similarity index 100% rename from examples/doc/public/code.css rename to examples/docs/public/code.css diff --git a/packages/create-astro/src/templates/blog/public/favicon.svg b/examples/docs/public/favicon.svg similarity index 100% rename from packages/create-astro/src/templates/blog/public/favicon.svg rename to examples/docs/public/favicon.svg diff --git a/examples/doc/public/index.css b/examples/docs/public/index.css similarity index 100% rename from examples/doc/public/index.css rename to examples/docs/public/index.css diff --git a/examples/doc/public/theme.css b/examples/docs/public/theme.css similarity index 100% rename from examples/doc/public/theme.css rename to examples/docs/public/theme.css diff --git a/examples/doc/public/theme.js b/examples/docs/public/theme.js similarity index 100% rename from examples/doc/public/theme.js rename to examples/docs/public/theme.js diff --git a/examples/doc/src/components/ArticleFooter.astro b/examples/docs/src/components/ArticleFooter.astro similarity index 100% rename from examples/doc/src/components/ArticleFooter.astro rename to examples/docs/src/components/ArticleFooter.astro diff --git a/examples/doc/src/components/AvatarList.astro b/examples/docs/src/components/AvatarList.astro similarity index 100% rename from examples/doc/src/components/AvatarList.astro rename to examples/docs/src/components/AvatarList.astro diff --git a/examples/doc/src/components/DocSidebar.tsx b/examples/docs/src/components/DocSidebar.tsx similarity index 100% rename from examples/doc/src/components/DocSidebar.tsx rename to examples/docs/src/components/DocSidebar.tsx diff --git a/examples/doc/src/components/EditOnGithub.tsx b/examples/docs/src/components/EditOnGithub.tsx similarity index 100% rename from examples/doc/src/components/EditOnGithub.tsx rename to examples/docs/src/components/EditOnGithub.tsx diff --git a/examples/doc/src/components/Note.astro b/examples/docs/src/components/Note.astro similarity index 100% rename from examples/doc/src/components/Note.astro rename to examples/docs/src/components/Note.astro diff --git a/examples/doc/src/components/SiteSidebar.astro b/examples/docs/src/components/SiteSidebar.astro similarity index 100% rename from examples/doc/src/components/SiteSidebar.astro rename to examples/docs/src/components/SiteSidebar.astro diff --git a/examples/doc/src/components/ThemeToggle.tsx b/examples/docs/src/components/ThemeToggle.tsx similarity index 100% rename from examples/doc/src/components/ThemeToggle.tsx rename to examples/docs/src/components/ThemeToggle.tsx diff --git a/examples/doc/src/config.ts b/examples/docs/src/config.ts similarity index 100% rename from examples/doc/src/config.ts rename to examples/docs/src/config.ts diff --git a/examples/doc/src/layouts/Main.astro b/examples/docs/src/layouts/Main.astro similarity index 100% rename from examples/doc/src/layouts/Main.astro rename to examples/docs/src/layouts/Main.astro diff --git a/examples/doc/src/pages/example.md b/examples/docs/src/pages/example.md similarity index 100% rename from examples/doc/src/pages/example.md rename to examples/docs/src/pages/example.md diff --git a/examples/doc/src/pages/index.astro b/examples/docs/src/pages/index.astro similarity index 100% rename from examples/doc/src/pages/index.astro rename to examples/docs/src/pages/index.astro diff --git a/examples/kitchen-sink/package.json b/examples/kitchen-sink/package.json index 630007124..ea89cbe3b 100644 --- a/examples/kitchen-sink/package.json +++ b/examples/kitchen-sink/package.json @@ -1,15 +1,13 @@ { - "name": "@example/kitchen-sink", + "name": "@astrojs/kitchen-sink-example", "private": true, "version": "1.0.0", "scripts": { "start": "astro dev", - "build": "astro build", - "astro-dev": "nodemon --delay 0.5 -w ../../packages/astro/dist -x '../../packages/astro/astro.mjs dev'" + "build": "astro build" }, "devDependencies": { - "astro": "^0.12.9", - "nodemon": "^2.0.7" + "astro": "^0.12.9" }, "snowpack": { "workspaceRoot": "../.." diff --git a/examples/portfolio/.gitignore b/examples/portfolio/.gitignore new file mode 100644 index 000000000..d436c6dad --- /dev/null +++ b/examples/portfolio/.gitignore @@ -0,0 +1,18 @@ +# build output +dist + +# dependencies +node_modules/ +.snowpack/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index 6e2ecfac6..008c624db 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -1,11 +1,10 @@ { - "name": "@example/portfolio", + "name": "@astrojs/portfolio-template", "private": true, "version": "0.0.1", "scripts": { "start": "astro dev", - "build": "astro build", - "astro-dev": "nodemon --delay 0.5 -w ../../packages/astro/dist -x '../../packages/astro/astro.mjs dev'" + "build": "astro build" }, "devDependencies": { "astro": "^0.12.9" diff --git a/examples/starter/.gitignore b/examples/starter/.gitignore new file mode 100644 index 000000000..d436c6dad --- /dev/null +++ b/examples/starter/.gitignore @@ -0,0 +1,18 @@ +# build output +dist + +# dependencies +node_modules/ +.snowpack/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store diff --git a/packages/create-astro/src/templates/starter/README.md b/examples/starter/README.md similarity index 100% rename from packages/create-astro/src/templates/starter/README.md rename to examples/starter/README.md diff --git a/packages/create-astro/src/templates/starter/astro.config.mjs b/examples/starter/astro.config.mjs similarity index 100% rename from packages/create-astro/src/templates/starter/astro.config.mjs rename to examples/starter/astro.config.mjs diff --git a/packages/create-astro/src/templates/starter/meta.json b/examples/starter/meta.json similarity index 100% rename from packages/create-astro/src/templates/starter/meta.json rename to examples/starter/meta.json diff --git a/packages/create-astro/src/templates/blog/package.json b/examples/starter/package.json similarity index 62% rename from packages/create-astro/src/templates/blog/package.json rename to examples/starter/package.json index fee6c2add..00dfc15e6 100644 --- a/packages/create-astro/src/templates/blog/package.json +++ b/examples/starter/package.json @@ -1,11 +1,12 @@ { - "name": "TODO", + "name": "@astrojs/starter-kit", "version": "0.0.1", + "private": true, "scripts": { "start": "astro dev", "build": "astro build" }, "devDependencies": { - "astro": "latest" + "astro": "^0.12.9" } } diff --git a/packages/create-astro/src/templates/starter/public/assets/logo.svg b/examples/starter/public/assets/logo.svg similarity index 100% rename from packages/create-astro/src/templates/starter/public/assets/logo.svg rename to examples/starter/public/assets/logo.svg diff --git a/packages/create-astro/src/templates/starter/public/favicon.svg b/examples/starter/public/favicon.svg similarity index 100% rename from packages/create-astro/src/templates/starter/public/favicon.svg rename to examples/starter/public/favicon.svg diff --git a/packages/create-astro/src/templates/starter/public/robots.txt b/examples/starter/public/robots.txt similarity index 100% rename from packages/create-astro/src/templates/starter/public/robots.txt rename to examples/starter/public/robots.txt diff --git a/packages/create-astro/src/templates/starter/public/style/global.css b/examples/starter/public/style/global.css similarity index 100% rename from packages/create-astro/src/templates/starter/public/style/global.css rename to examples/starter/public/style/global.css diff --git a/packages/create-astro/src/templates/starter/public/style/home.css b/examples/starter/public/style/home.css similarity index 100% rename from packages/create-astro/src/templates/starter/public/style/home.css rename to examples/starter/public/style/home.css diff --git a/packages/create-astro/src/templates/starter/src/components/Tour.astro b/examples/starter/src/components/Tour.astro similarity index 100% rename from packages/create-astro/src/templates/starter/src/components/Tour.astro rename to examples/starter/src/components/Tour.astro diff --git a/packages/create-astro/src/templates/starter/src/pages/index.astro b/examples/starter/src/pages/index.astro similarity index 100% rename from packages/create-astro/src/templates/starter/src/pages/index.astro rename to examples/starter/src/pages/index.astro diff --git a/examples/tailwindcss/package.json b/examples/tailwindcss/package.json index 2bea3a777..edf0cd0bd 100644 --- a/examples/tailwindcss/package.json +++ b/examples/tailwindcss/package.json @@ -1,15 +1,14 @@ { - "name": "@example/tailwindcss", + "name": "@astrojs/tailwind-example", "version": "0.0.1", "private": true, "scripts": { "start": "astro dev", - "build": "astro build", - "astro-dev": "nodemon --delay 0.5 -w ../../packages/astro/dist -x '../../packages/astro/astro.mjs dev'" + "build": "astro build" }, "devDependencies": { - "astro": "^0.12.9", - "tailwindcss": "^2.1.2" + "tailwindcss": "^2.1.2", + "astro": "^0.12.9" }, "snowpack": { "workspaceRoot": "../.." diff --git a/package.json b/package.json index 5532f0277..171dd94d6 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,8 @@ "release": "yarn build && yarn changeset publish", "benchmark": "yarn workspace astro run benchmark", "build": "yarn build:core", + "build:all": "lerna run build", + "build:one": "lerna run build --scope", "build:core": "lerna run build --scope astro --scope @astrojs/parser --scope @astrojs/markdown-support", "build:vscode": "lerna run build --scope astro-languageserver --scope astro-vscode --scope @astrojs/parser", "dev:vscode": "lerna run dev --scope astro-languageserver --scope astro-vscode --scope @astrojs/parser --parallel --stream", @@ -15,16 +17,13 @@ "test:core": "yarn workspace astro run test" }, "workspaces": [ - "packages/!(create-astro)*", "packages/renderers/*", + "packages/*", "examples/*", "tools/*", "scripts", "www" ], - "engines": { - "vscode": "^1.22.0" - }, "volta": { "node": "14.16.1", "npm": "7.11.2", diff --git a/packages/create-astro/.gitignore b/packages/create-astro/.gitignore deleted file mode 100644 index 8ee01d321..000000000 --- a/packages/create-astro/.gitignore +++ /dev/null @@ -1 +0,0 @@ -yarn.lock diff --git a/packages/create-astro/CHANGELOG.md b/packages/create-astro/CHANGELOG.md deleted file mode 100644 index 4c34c6558..000000000 --- a/packages/create-astro/CHANGELOG.md +++ /dev/null @@ -1,35 +0,0 @@ -# create-astro - -## 0.2.0 - -### Minor Changes - -- ✨ New template: Blog - -### Patch Changes - -- Bugfix: Template selection spacing -- Bugfix: Getting Started template font display in Firefox -- Bugfix: CLI contrast improvement -- All templates: more readable Astro config - -## 0.1.2 - -### Patch Changes - -- Rename the `--run` option to `--skip-install` for clarity. -- Bugfix: `npm init astro` on npm v7 - -## 0.1.1 - -### Patch Changes - -- Update template dependencies - -## 0.1.0 - -### Minor Changes - -- ed63132: Added **interactive mode** with a fesh new UI. - - Included a new **blank** starter to get up and running even faster. diff --git a/packages/create-astro/README.md b/packages/create-astro/README.md index ff0c9993b..0c3982ed5 100644 --- a/packages/create-astro/README.md +++ b/packages/create-astro/README.md @@ -18,22 +18,13 @@ yarn create astro ```bash # npm 6.x -npm init astro my-astro-project --template blank +npm init astro my-astro-project --template starter # npm 7+, extra double-dash is needed: -npm init astro my-astro-project -- --template blank +npm init astro my-astro-project -- --template starter # yarn -yarn create astro my-astro-project --template blank +yarn create astro my-astro-project --template starter ``` -To see all available options, use the `--help` flag. - -### Templates - -The following templates are included: - -- `starter` -- `blank` - -Feel free to [open a PR](https://github.com/snowpackjs/astro/pulls) to add additional templates. +[Check out the full list](https://github.com/snowpackjs/astro/tree/main/examples) of example starter templates, available on GitHub. diff --git a/packages/create-astro/create-astro.js b/packages/create-astro/create-astro.js deleted file mode 100755 index e527ff6da..000000000 --- a/packages/create-astro/create-astro.js +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node -import cli from './dist/index.js'; -cli(process.argv); diff --git a/packages/create-astro/create-astro.mjs b/packages/create-astro/create-astro.mjs new file mode 100755 index 000000000..d29f568b2 --- /dev/null +++ b/packages/create-astro/create-astro.mjs @@ -0,0 +1,14 @@ +#!/usr/bin/env node +'use strict'; + +const currentVersion = process.versions.node; +const requiredMajorVersion = parseInt(currentVersion.split('.')[0], 10); +const minimumMajorVersion = 10; + +if (requiredMajorVersion < minimumMajorVersion) { + console.error(`Node.js v${currentVersion} is out of date and unsupported!`); + console.error(`Please use Node.js v${minimumMajorVersion} or higher.`); + process.exit(1); +} + +import('./dist/index.js').then(({main}) => main()); diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json index af70ed056..200ac3757 100644 --- a/packages/create-astro/package.json +++ b/packages/create-astro/package.json @@ -6,11 +6,10 @@ ".": "./create-astro.js" }, "bin": { - "create-astro": "./create-astro.js" + "create-astro": "./create-astro.mjs" }, "scripts": { - "build": "ENV=production ../../scripts/index.js build src/index.tsx", - "postbuild": "../../scripts/index.js copy \"src/templates/**\" --tgz", + "build": "astro-scripts build \"src/*.ts\"", "prepare": "yarn build", "test": "uvu" }, @@ -19,13 +18,12 @@ "create-astro.js" ], "dependencies": { - "decamelize": "^5.0.0", - "decompress": "^4.2.1", - "ink": "^3.0.8", - "ink-select-input": "^4.2.0", - "ink-text-input": "^4.0.1", - "react": "^16.14.0", - "source-map-support": "^0.5.19" + "@types/degit": "^2.8.2", + "@types/prompts": "^2.0.12", + "degit": "^2.8.4", + "kleur": "^4.1.1", + "prompts": "^2.4.1", + "yargs-parser": "^20.2.7" }, "devDependencies": { "uvu": "^0.5.1" diff --git a/packages/create-astro/src/components/App.tsx b/packages/create-astro/src/components/App.tsx deleted file mode 100644 index 4cf9f3852..000000000 --- a/packages/create-astro/src/components/App.tsx +++ /dev/null @@ -1,108 +0,0 @@ -import React, { FC, useEffect } from 'react'; -import { prepareTemplate, isEmpty, emptyDir } from '../utils'; -import Header from './Header'; -import Install from './Install'; -import ProjectName from './ProjectName'; -import Template from './Template'; -import Confirm from './Confirm'; -import Finalize from './Finalize'; - -interface Context { - use: 'npm' | 'yarn'; - skipInstall?: boolean; - projectExists?: boolean; - force?: boolean; - projectName?: string; - template?: string; - templates: string[]; - ready?: boolean; -} - -const getStep = ({ projectName, projectExists: exists, template, force, ready, skipInstall }: Context) => { - switch (true) { - case !projectName: - return { - key: 'projectName', - Component: ProjectName, - }; - case projectName && exists === true && typeof force === 'undefined': - return { - key: 'force', - Component: Confirm, - }; - case (exists === false || force) && !template: - return { - key: 'template', - Component: Template, - }; - case !ready && !skipInstall: - return { - key: 'install', - Component: Install, - }; - case ready: - return { - key: 'final', - Component: Finalize, - }; - default: - return { - key: 'empty', - Component: () => <>, - }; - } -}; - -const App: FC<{ context: Context }> = ({ context }) => { - const [state, setState] = React.useState(context); - const step = React.useRef(getStep(context)); - const onSubmit = (value: string | boolean) => { - const { key } = step.current; - const newState = { ...state, [key]: value }; - step.current = getStep(newState); - setState(newState); - }; - - useEffect(() => { - let isSubscribed = true; - if (state.projectName && typeof state.projectExists === 'undefined') { - const newState = { ...state, projectExists: !isEmpty(state.projectName) }; - step.current = getStep(newState); - if (isSubscribed) { - setState(newState); - } - } - - if (state.projectName && (state.projectExists === false || state.force) && state.template) { - if (state.force) emptyDir(state.projectName); - prepareTemplate({ - use: context.use, - templateName: state.template, - projectName: state.projectName, - skipInstall: state.skipInstall, - }).then(() => { - if (isSubscribed) { - setState((v) => { - const newState = { ...v, ready: true }; - step.current = getStep(newState); - return newState; - }); - } - }); - } - - return () => { - isSubscribed = false; - }; - }, [state]); - const { Component } = step.current; - - return ( - <> -
- - - ); -}; - -export default App; diff --git a/packages/create-astro/src/components/Confirm.tsx b/packages/create-astro/src/components/Confirm.tsx deleted file mode 100644 index 6f755ee61..000000000 --- a/packages/create-astro/src/components/Confirm.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import React, { FC } from 'react'; -import { Box, Text, useApp } from 'ink'; -import { relative } from 'path'; -import Spacer from './Spacer'; -import Select from './Select'; - -const Confirm: FC<{ message?: any; context: any; onSubmit: (value: boolean) => void }> = ({ message, context: { projectName }, onSubmit }) => { - const { exit } = useApp(); - const handleSubmit = (v: boolean) => { - if (!v) return exit(); - onSubmit(v); - }; - - return ( - <> - - {!message ? ( - <> - {'[uh-oh]'} - - {' '} - It appears ./{relative(process.cwd(), projectName)} is not empty. Overwrite? - - - ) : ( - message - )} - - - - - - - ); -}; - -export default ProjectName; diff --git a/packages/create-astro/src/components/Select.tsx b/packages/create-astro/src/components/Select.tsx deleted file mode 100644 index c31cad75d..000000000 --- a/packages/create-astro/src/components/Select.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import SelectInput from 'ink-select-input'; -import React, { FC } from 'react'; -import { Text, Box } from 'ink'; -// @ts-expect-error -const { default: Select } = SelectInput; - -interface Props { - isSelected?: boolean; - label: string; - description?: string; -} -const Indicator: FC = ({ isSelected }) => (isSelected ? [ : {' '}); -const Item: FC = ({ isSelected = false, label, description }) => ( - - - {label} - - {isSelected && description && typeof description === 'string' && {description}} - {isSelected && description && typeof description !== 'string' && {description}} - -); - -interface SelectProps { - items: { value: string | number | boolean; label: string; description?: any }[]; - onSelect(value: string | number | boolean): void; -} -const CustomSelect: FC = ({ items, onSelect }) => { - const handleSelect = ({ value }) => onSelect(value); - return - - - ); -}; - -export default Template; diff --git a/packages/create-astro/src/components/Version.tsx b/packages/create-astro/src/components/Version.tsx deleted file mode 100644 index 340952dc0..000000000 --- a/packages/create-astro/src/components/Version.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import React, { FC } from 'react'; -import { Text } from 'ink'; -import pkg from '../../package.json'; - -const Version: FC = () => v{pkg.version}; -export default Version; diff --git a/packages/create-astro/src/config.ts b/packages/create-astro/src/config.ts deleted file mode 100644 index 8da0720e6..000000000 --- a/packages/create-astro/src/config.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type * as arg from 'arg'; -import decamelize from 'decamelize'; - -export interface ARG { - type: any; - description: string; - enum?: string[]; - alias?: string; -} - -export const ARGS: Record = { - template: { - type: String, - description: 'specifies template to use', - }, - use: { - type: String, - enum: ['npm', 'yarn'], - description: 'specifies package manager to use', - }, - skipInstall: { - type: Boolean, - description: 'should installing dependencies be skipped?', - }, - force: { - type: Boolean, - alias: 'f', - description: 'should existing files be overwritten?', - }, - version: { - type: Boolean, - alias: 'v', - description: 'prints current version', - }, - help: { - type: Boolean, - alias: 'h', - description: 'prints this message', - }, -}; - -export const args = Object.entries(ARGS).reduce((acc, [name, info]) => { - const key = `--${decamelize(name, { separator: '-' })}`; - const spec = { ...acc, [key]: info.type }; - - if (info.alias) { - spec[`-${info.alias}`] = key; - } - return spec; -}, {} as arg.Spec); diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts new file mode 100644 index 000000000..5bf16e490 --- /dev/null +++ b/packages/create-astro/src/index.ts @@ -0,0 +1,87 @@ +import fs from 'fs'; +import path from 'path'; +import { bold, cyan, gray, green, red } from 'kleur/colors'; +import prompts from 'prompts'; +import degit from 'degit'; +import yargs from 'yargs-parser'; +import { TEMPLATES } from './templates'; +const args = yargs(process.argv); +prompts.override(args); + +export function mkdirp(dir: string) { + try { + fs.mkdirSync(dir, { recursive: true }); + } catch (e) { + if (e.code === 'EEXIST') return; + throw e; + } +} + + +const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8')); + +export async function main() { + 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(green(`>`) + gray(` Prepare for liftoff.`)); + console.log(green(`>`) + gray(` Gathering mission details...`)); + + const cwd = args['_'][2] || '.'; + if (fs.existsSync(cwd)) { + 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([ + { + type: 'select', + name: 'template', + message: 'Which app template would you like to use?', + choices: TEMPLATES + }, + ])); + + const emitter = degit(`snowpackjs/astro/examples/${options.template}`, { + cache: false, + force: true, + verbose: false, + }); + + 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'))); + + console.log('\nNext steps:'); + let i = 1; + + const relative = path.relative(process.cwd(), cwd); + 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'); +} \ No newline at end of file diff --git a/packages/create-astro/src/index.tsx b/packages/create-astro/src/index.tsx deleted file mode 100644 index 631079083..000000000 --- a/packages/create-astro/src/index.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import 'source-map-support/register.js'; -import React from 'react'; -import App from './components/App'; -import Version from './components/Version'; -import Exit from './components/Exit'; -import { render } from 'ink'; -import { getTemplates, addProcessListeners } from './utils'; -import { args as argsConfig } from './config'; -import arg from 'arg'; -import Help from './components/Help'; - -/** main `create-astro` CLI */ -export default async function createAstro() { - const args = arg(argsConfig); - const projectName = args._[0]; - if (args['--version']) { - return render(); - } - const templates = await getTemplates(); - if (args['--help']) { - return render(); - } - - const pkgManager = /yarn/.test(process.env.npm_execpath) ? 'yarn' : 'npm'; - const use = (args['--use'] ?? pkgManager) as 'npm' | 'yarn'; - const template = args['--template']; - const force = args['--force']; - const skipInstall = args['--skip-install']; - - const app = render(); - - const onError = () => { - if (app) app.clear(); - render(); - }; - const onExit = () => { - if (app) app.clear(); - render(); - }; - addProcessListeners([ - ['uncaughtException', onError], - ['exit', onExit], - ['SIGINT', onExit], - ['SIGTERM', onExit], - ]); -} diff --git a/packages/create-astro/src/templates.ts b/packages/create-astro/src/templates.ts new file mode 100644 index 000000000..63254a311 --- /dev/null +++ b/packages/create-astro/src/templates.ts @@ -0,0 +1,16 @@ +export const TEMPLATES = [, + { + title: 'Starter Kit (Generic)', + value: 'starter' + }, { + title: 'Blog', + value: 'blog' + }, + { + title: 'Documentation', + value: 'docs' + }, + { + title: 'Portfolio', + value: 'portfolio' + }]; \ No newline at end of file diff --git a/packages/create-astro/src/templates/blog/README.md b/packages/create-astro/src/templates/blog/README.md deleted file mode 100644 index 87c48761c..000000000 --- a/packages/create-astro/src/templates/blog/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Astro Blog Example - -> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun! - -Features: - -- ✅ SEO-friendly setup with canonical URLs and OpenGraph data -- ✅ Full Markdown support -- ✅ RSS 2.0 generation -- ✅ Sitemap.xml generation - -## 🚀 Project Structure - -Inside of your Astro project, you'll see the following folders and files: - -``` -/ -├── public/ -│ ├── robots.txt -│ └── favicon.ico -├── src/ -│ ├── components/ -│ │ └── Tour.astro -│ └── pages/ -│ └── index.astro -└── package.json -``` - -Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name. - -There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components. - -Any static assets, like images, can be placed in the `public/` directory. - -## 🧞 Commands - -All commands are run from the root of the project, from a terminal: - -| Command | Action | -|:----------------|:--------------------------------------------| -| `npm install` | Installs dependencies | -| `npm run start` | Starts local dev server at `localhost:3000` | -| `npm run build` | Build your production site to `./dist/` | - -## 👀 Want to learn more? - -Feel free to check [our documentation](https://github.com/snowpackjs/astro) or jump into our [Discord server](https://discord.gg/EsGdSGen). diff --git a/packages/create-astro/src/templates/blog/astro.config.mjs b/packages/create-astro/src/templates/blog/astro.config.mjs deleted file mode 100644 index d72db6491..000000000 --- a/packages/create-astro/src/templates/blog/astro.config.mjs +++ /dev/null @@ -1,14 +0,0 @@ -export default { - // projectRoot: '.', // Where to resolve all URLs relative to. Useful if you have a monorepo project. - // pages: './src/pages', // Path to Astro components, pages, and data - // dist: './dist', // When running `astro build`, path to final static output - // public: './public', // A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that don’t need processing. - buildOptions: { - site: 'http://example.com', // Your public domain, e.g.: https://my-site.dev/. Used to generate sitemaps and canonical URLs. - // sitemap: true, // Generate sitemap (set to "false" to disable) - }, - devOptions: { - // port: 3000, // The port to run the dev server on. - // tailwindConfig: '', // Path to tailwind.config.js if used, e.g. './tailwind.config.js' - }, -}; diff --git a/packages/create-astro/src/templates/blog/public/authors/don.jpg b/packages/create-astro/src/templates/blog/public/authors/don.jpg deleted file mode 100644 index 4419679de..000000000 Binary files a/packages/create-astro/src/templates/blog/public/authors/don.jpg and /dev/null differ diff --git a/packages/create-astro/src/templates/blog/public/authors/sancho.jpg b/packages/create-astro/src/templates/blog/public/authors/sancho.jpg deleted file mode 100644 index 2c2b0c6bd..000000000 Binary files a/packages/create-astro/src/templates/blog/public/authors/sancho.jpg and /dev/null differ diff --git a/packages/create-astro/src/templates/blog/public/global.scss b/packages/create-astro/src/templates/blog/public/global.scss deleted file mode 100644 index d5891f6b4..000000000 --- a/packages/create-astro/src/templates/blog/public/global.scss +++ /dev/null @@ -1,25 +0,0 @@ -body { - font-family: 'Spectral', serif; - line-height: 1.4; -} - -p { - line-height: 2; -} - -a { - color: crimson; -} - -img { - max-width: 100%; - height: auto; -} - -.wrapper { - max-width: 60rem; - margin-left: auto; - margin-right: auto; - padding-left: 2rem; - padding-right: 2rem; -} diff --git a/packages/create-astro/src/templates/blog/public/images/chapter-01.jpg b/packages/create-astro/src/templates/blog/public/images/chapter-01.jpg deleted file mode 100644 index a848d3059..000000000 Binary files a/packages/create-astro/src/templates/blog/public/images/chapter-01.jpg and /dev/null differ diff --git a/packages/create-astro/src/templates/blog/public/images/chapter-02.jpg b/packages/create-astro/src/templates/blog/public/images/chapter-02.jpg deleted file mode 100644 index 0a18c689d..000000000 Binary files a/packages/create-astro/src/templates/blog/public/images/chapter-02.jpg and /dev/null differ diff --git a/packages/create-astro/src/templates/blog/public/images/chapter-03.jpg b/packages/create-astro/src/templates/blog/public/images/chapter-03.jpg deleted file mode 100644 index e3b6823ce..000000000 Binary files a/packages/create-astro/src/templates/blog/public/images/chapter-03.jpg and /dev/null differ diff --git a/packages/create-astro/src/templates/blog/src/components/MainHead.astro b/packages/create-astro/src/templates/blog/src/components/MainHead.astro deleted file mode 100644 index 86f750ddc..000000000 --- a/packages/create-astro/src/templates/blog/src/components/MainHead.astro +++ /dev/null @@ -1,39 +0,0 @@ ---- -// props -export let title: string; -export let description: string; -export let image: string | undefined; -export let type: string | undefined; -export let next: string | undefined; -export let prev: string | undefined; -export let canonicalURL: string | undefined; ---- - - - -{title} - - - - - - - - - - - -{next && } -{prev && } - - - - -{image && ()} - - - - - - -{image && ()} diff --git a/packages/create-astro/src/templates/blog/src/components/Nav.astro b/packages/create-astro/src/templates/blog/src/components/Nav.astro deleted file mode 100644 index 5949adb0d..000000000 --- a/packages/create-astro/src/templates/blog/src/components/Nav.astro +++ /dev/null @@ -1,59 +0,0 @@ ---- -export let title; ---- - - - - diff --git a/packages/create-astro/src/templates/blog/src/components/Pagination.astro b/packages/create-astro/src/templates/blog/src/components/Pagination.astro deleted file mode 100644 index 7b01e59b5..000000000 --- a/packages/create-astro/src/templates/blog/src/components/Pagination.astro +++ /dev/null @@ -1,40 +0,0 @@ ---- -export let prevUrl: string; -export let nextUrl: string; ---- - - - -
- -
diff --git a/packages/create-astro/src/templates/blog/src/components/PostPreview.astro b/packages/create-astro/src/templates/blog/src/components/PostPreview.astro deleted file mode 100644 index 59c54e8fa..000000000 --- a/packages/create-astro/src/templates/blog/src/components/PostPreview.astro +++ /dev/null @@ -1,63 +0,0 @@ ---- -export let post; -export let author; - -function formatDate(date) { - return new Date(date).toUTCString().replace(/(\d\d\d\d) .*/, '$1'); // remove everything after YYYY -} ---- - - - -
- -
-

{post.title}

- {author.name} - -

- {post.description} - Read -

-
-
diff --git a/packages/create-astro/src/templates/blog/src/data/authors.json b/packages/create-astro/src/templates/blog/src/data/authors.json deleted file mode 100644 index e958e7cd1..000000000 --- a/packages/create-astro/src/templates/blog/src/data/authors.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "don": { - "name": "Don Quixote", - "image": "/authors/don.jpg" - }, - "sancho": { - "name": "Sancho Panza", - "image": "/authors/sancho.jpg" - } -} diff --git a/packages/create-astro/src/templates/blog/src/layouts/post.astro b/packages/create-astro/src/templates/blog/src/layouts/post.astro deleted file mode 100644 index 5149528a0..000000000 --- a/packages/create-astro/src/templates/blog/src/layouts/post.astro +++ /dev/null @@ -1,79 +0,0 @@ ---- -import MainHead from '../components/MainHead.astro'; -import Nav from '../components/Nav.astro'; - -export let content; - -import authorData from '../data/authors.json'; ---- - - - - {content.title} - - - - - -