diff options
author | 2021-07-06 15:14:22 -0400 | |
---|---|---|
committer | 2021-07-06 15:14:22 -0400 | |
commit | d8ceff5facbbe7d7b358c718e73c2cfaa31cae5a (patch) | |
tree | 6d28a563a60853c7b75ad06673597240b2e0aaee /packages/create-astro | |
parent | 2ab625bee86f752ca963a572ee28b93cd94e8643 (diff) | |
download | astro-d8ceff5facbbe7d7b358c718e73c2cfaa31cae5a.tar.gz astro-d8ceff5facbbe7d7b358c718e73c2cfaa31cae5a.tar.zst astro-d8ceff5facbbe7d7b358c718e73c2cfaa31cae5a.zip |
Implements templates from external repos (#603)
* Implements templates from external repos
* Adds a changeset
Diffstat (limited to 'packages/create-astro')
-rw-r--r-- | packages/create-astro/README.md | 6 | ||||
-rw-r--r-- | packages/create-astro/src/index.ts | 7 | ||||
-rw-r--r-- | packages/create-astro/test/create-astro.test.js | 6 | ||||
-rw-r--r-- | packages/create-astro/test/external.test.js | 29 | ||||
-rw-r--r-- | packages/create-astro/test/helpers.js | 13 |
5 files changed, 55 insertions, 6 deletions
diff --git a/packages/create-astro/README.md b/packages/create-astro/README.md index 4a90b7eb4..d8c6213de 100644 --- a/packages/create-astro/README.md +++ b/packages/create-astro/README.md @@ -28,6 +28,12 @@ yarn create astro my-astro-project --template starter ``` [Check out the full list][examples] of example starter templates, available on GitHub. +You can also use any GitHub repo as a template: + +```bash +npm init astro my-astro-project -- --template cassidoo/shopify-react-astro +``` + ### CLI Flags May be provided in place of prompts diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index c63cca9ea..e3487e8d4 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -55,7 +55,12 @@ export async function main() { ]); const hash = args.commit ? `#${args.commit}` : ''; - const emitter = degit(`snowpackjs/astro/examples/${options.template}${hash}`, { + + const templateTarget = options.template.includes('/') ? + options.template : + `snowpackjs/astro/examples/${options.template}`; + + const emitter = degit(`${templateTarget}${hash}`, { cache: false, force: true, verbose: false, diff --git a/packages/create-astro/test/create-astro.test.js b/packages/create-astro/test/create-astro.test.js index 30f466d30..d095b2da9 100644 --- a/packages/create-astro/test/create-astro.test.js +++ b/packages/create-astro/test/create-astro.test.js @@ -1,15 +1,11 @@ import fs from 'fs'; import path from 'path'; -import { fileURLToPath } from 'url'; import http from 'http'; import { green, red } from 'kleur/colors'; import execa from 'execa'; import glob from 'tiny-glob'; import { TEMPLATES } from '../dist/templates.js'; - -// config -const GITHUB_SHA = process.env.GITHUB_SHA || execa.sync('git', ['rev-parse', 'HEAD']).stdout; // process.env.GITHUB_SHA will be set in CI; if testing locally execa() will gather this -const FIXTURES_DIR = path.join(fileURLToPath(path.dirname(import.meta.url)), 'fixtures'); +import { GITHUB_SHA, FIXTURES_DIR } from './helpers.js'; // helpers async function fetch(url) { diff --git a/packages/create-astro/test/external.test.js b/packages/create-astro/test/external.test.js new file mode 100644 index 000000000..9fac8c202 --- /dev/null +++ b/packages/create-astro/test/external.test.js @@ -0,0 +1,29 @@ +import assert from 'assert'; +import execa from 'execa'; +import { FIXTURES_URL } from './helpers.js'; +import { existsSync } from 'fs'; + +async function run(outdir, template) { + //--template cassidoo/shopify-react-astro + await execa('../../create-astro.mjs', [outdir, '--template', template, '--force-overwrite'], { + cwd: FIXTURES_URL.pathname, + }); +} + +const testCases = [ + ['shopify', 'cassidoo/shopify-react-astro'] +]; + +async function tests() { + for(let [dir, tmpl] of testCases) { + await run(dir, tmpl); + + const outPath = new URL('' + dir, FIXTURES_URL); + assert.ok(existsSync(outPath)); + } +} + +tests().catch(err => { + console.error(err); + process.exit(1); +});
\ No newline at end of file diff --git a/packages/create-astro/test/helpers.js b/packages/create-astro/test/helpers.js new file mode 100644 index 000000000..295f9c650 --- /dev/null +++ b/packages/create-astro/test/helpers.js @@ -0,0 +1,13 @@ +import execa from 'execa'; +import path from 'path'; +import { fileURLToPath, pathToFileURL } from 'url'; + +const GITHUB_SHA = process.env.GITHUB_SHA || execa.sync('git', ['rev-parse', 'HEAD']).stdout; // process.env.GITHUB_SHA will be set in CI; if testing locally execa() will gather this +const FIXTURES_DIR = path.join(fileURLToPath(path.dirname(import.meta.url)), 'fixtures'); +const FIXTURES_URL = pathToFileURL(FIXTURES_DIR + '/'); + +export { + GITHUB_SHA, + FIXTURES_DIR, + FIXTURES_URL +};
\ No newline at end of file |