diff options
author | 2021-06-10 10:30:48 -0600 | |
---|---|---|
committer | 2021-06-10 10:30:48 -0600 | |
commit | a660e49f80accbc4e18f48cc10bf23a239f711fe (patch) | |
tree | 7f6652556315008cef020dd3ef4ef3c298a2da13 /packages/create-astro/src/index.ts | |
parent | 047b0fcc6cbe722fd0f3d8ca7894e7986f004302 (diff) | |
download | astro-a660e49f80accbc4e18f48cc10bf23a239f711fe.tar.gz astro-a660e49f80accbc4e18f48cc10bf23a239f711fe.tar.zst astro-a660e49f80accbc4e18f48cc10bf23a239f711fe.zip |
Add integration test for templates (#372)
Diffstat (limited to 'packages/create-astro/src/index.ts')
-rw-r--r-- | packages/create-astro/src/index.ts | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index 0d1d834f3..240faf7c0 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -19,6 +19,8 @@ export function mkdirp(dir: string) { const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8')); +const POSTPROCESS_FILES = ['package.json']; // some files need processing after copying. + 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`); @@ -52,12 +54,14 @@ export async function main() { }, ]); - const emitter = degit(`snowpackjs/astro/examples/${options.template}`, { + const hash = args.commit ? `#${args.commit}` : ''; + const emitter = degit(`snowpackjs/astro/examples/${options.template}${hash}`, { cache: false, force: true, verbose: false, }); + // Copy try { // emitter.on('info', info => { console.log(info.message) }); console.log(green(`>`) + gray(` Copying project files...`)); @@ -68,6 +72,22 @@ export async function main() { process.exit(1); } + // Post-process in parallel + await Promise.all( + POSTPROCESS_FILES.map(async (file) => { + const fileLoc = path.join(cwd, file); + + switch (file) { + case 'package.json': { + const packageJSON = JSON.parse(await fs.promises.readFile(fileLoc, 'utf8')); + delete packageJSON.snowpack; // delete snowpack config only needed in monorepo (can mess up projects) + await fs.promises.writeFile(fileLoc, JSON.stringify(packageJSON, undefined, 2)); + break; + } + } + }) + ); + console.log(bold(green('✔ Copied project files'))); console.log('\nNext steps:'); |