From f3292f564dd7291e082016edef12009a1aa33e45 Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Sun, 20 Mar 2022 16:22:48 -0300 Subject: [PATCH 1/7] Install dependencies automatically --- packages/create-astro/package.json | 3 + packages/create-astro/src/config.ts | 8 ++- packages/create-astro/src/frameworks.ts | 27 +++++--- packages/create-astro/src/index.ts | 90 ++++++++++++++++++++----- 4 files changed, 99 insertions(+), 29 deletions(-) diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json index 9db01d1615a8..2a867ea495d9 100644 --- a/packages/create-astro/package.json +++ b/packages/create-astro/package.json @@ -32,10 +32,13 @@ "degit": "^2.8.4", "kleur": "^4.1.4", "node-fetch": "^3.2.3", + "ora": "^6.1.0", "prompts": "^2.4.2", + "which-pm-runs": "^1.1.0", "yargs-parser": "^21.0.1" }, "devDependencies": { + "@types/which-pm-runs": "^1.0.0", "@types/yargs-parser": "^21.0.0", "astro-scripts": "workspace:*", "uvu": "^0.5.3" diff --git a/packages/create-astro/src/config.ts b/packages/create-astro/src/config.ts index f8e63d24cd36..4060d368c5e8 100644 --- a/packages/create-astro/src/config.ts +++ b/packages/create-astro/src/config.ts @@ -1,4 +1,6 @@ -export const createConfig = ({ integrations }: { integrations: string[] }) => { +import type { Integration } from './frameworks'; + +export const createConfig = ({ integrations }: { integrations: Integration[] }) => { if (integrations.length === 0) { return `import { defineConfig } from 'astro/config'; // https://astro.build/config @@ -6,8 +8,8 @@ export default defineConfig({}); `; } - const rendererImports = integrations.map((r: string) => ` import ${r} from '@astrojs/${r === 'solid' ? 'solid-js' : r}';`); - const rendererIntegrations = integrations.map((r: string) => ` ${r}(),`); + const rendererImports = integrations.map((r) => ` import ${r.id} from '${r.packageName}';`); + const rendererIntegrations = integrations.map((r) => ` ${r.id}(),`); return [ `import { defineConfig } from 'astro/config';`, ...rendererImports, diff --git a/packages/create-astro/src/frameworks.ts b/packages/create-astro/src/frameworks.ts index 0290c1c96dea..0483b7474e41 100644 --- a/packages/create-astro/src/frameworks.ts +++ b/packages/create-astro/src/frameworks.ts @@ -107,25 +107,30 @@ export default { }, }; -export const FRAMEWORKS = [ +export interface Integration { + id: string; + packageName: string; +} + +export const FRAMEWORKS: { title: string; value: Integration }[] = [ { - title: 'preact', - value: '@astrojs/preact', + title: 'Preact', + value: { id: 'preact', packageName: '@astrojs/preact' }, }, { - title: 'react', - value: 'react', + title: 'React', + value: { id: 'react', packageName: '@astrojs/react' }, }, { - title: 'solid', - value: 'solid', + title: 'Solid.js', + value: { id: 'solid', packageName: '@astrojs/solid-js' }, }, { - title: 'svelte', - value: 'svelte', + title: 'Svelte', + value: { id: 'svelte', packageName: '@astrojs/svelte' }, }, { - title: 'vue', - value: 'vue', + title: 'Vue', + value: { id: 'vue', packageName: '@astrojs/vue' }, }, ]; diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index 2f4f59e88a0e..1ed9050788f7 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -1,11 +1,14 @@ import fs from 'fs'; import path from 'path'; +import { exec as childProcessExec, ExecOptions } from 'child_process'; import { bold, cyan, gray, green, red, yellow } from 'kleur/colors'; import fetch from 'node-fetch'; import prompts from 'prompts'; import degit from 'degit'; import yargs from 'yargs-parser'; -import { FRAMEWORKS, COUNTER_COMPONENTS } from './frameworks.js'; +import ora from 'ora'; +import whichPM from 'which-pm-runs'; +import { FRAMEWORKS, COUNTER_COMPONENTS, Integration } from './frameworks.js'; import { TEMPLATES } from './templates.js'; import { createConfig } from './config.js'; import { logger, defaultLogLevel } from './logger.js'; @@ -27,10 +30,24 @@ export function mkdirp(dir: string) { } } +function exec(command: string[], options: ExecOptions = {}) { + return new Promise((resolve, reject) => { + childProcessExec(command.join(' '), options, (err, stdout, stderr) => { + if (err) { + reject(stderr); + } else { + resolve(stdout); + } + }); + }); +} + const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8')); const POSTPROCESS_FILES = ['package.json', 'astro.config.mjs', 'CHANGELOG.md']; // some files need processing after copying. +const issueMsg = '\nIf you think this is an error, feel free to open an issue in our GitHub repo: https://github.com/withastro/astro/issues/new'; + export async function main() { logger.debug('Verbose logging turned on'); console.log(`\n${bold('Welcome to Astro!')} ${gray(`(create-astro v${version})`)}`); @@ -57,7 +74,7 @@ export async function main() { mkdirp(cwd); } - const options = /** @type {import('./types/internal').Options} */ await prompts([ + const options = await prompts([ { type: 'select', name: 'template', @@ -87,10 +104,10 @@ export async function main() { }); const selectedTemplate = TEMPLATES.find((template) => template.value === options.template); - let integrations: string[] = []; + let integrations: Integration[] = []; if (selectedTemplate?.integrations === true) { - const result = /** @type {import('./types/internal').Options} */ await prompts([ + const result = await prompts([ { type: 'multiselect', name: 'integrations', @@ -154,13 +171,25 @@ export async function main() { const packageJSON = JSON.parse(await fs.promises.readFile(fileLoc, 'utf8')); delete packageJSON.snowpack; // delete snowpack config only needed in monorepo (can mess up projects) // Fetch latest versions of selected integrations - const integrationEntries = (await Promise.all( - ['astro', ...integrations].map((integration: string) => - fetch(`https://registry.npmjs.org/@astrojs/${integration === 'solid' ? 'solid-js' : integration}/latest`) - .then((res: any) => res.json()) - .then((res: any) => [res['name'], `^${res['version']}`]) + const integrationEntries = ( + await Promise.all( + integrations.map((integration) => + fetch(`https://registry.npmjs.org/${integration.packageName}/latest`) + .then((res) => res.json()) + .then((res: any) => { + let dependencies = [[res['name'], `^${res['version']}`]]; + + if (res['peerDependencies']) { + for (const peer in res['peerDependencies']) { + dependencies.push([peer, res['peerDependencies'][peer]]); + } + } + + return dependencies; + }) + ) ) - )) as any; + ).flat(1); packageJSON.devDependencies = { ...(packageJSON.devDependencies ?? {}), ...Object.fromEntries(integrationEntries) }; await fs.promises.writeFile(fileLoc, JSON.stringify(packageJSON, undefined, 2)); break; @@ -174,8 +203,8 @@ export async function main() { let importStatements: string[] = []; let components: string[] = []; await Promise.all( - integrations.map(async (integrations) => { - const component = COUNTER_COMPONENTS[integrations as keyof typeof COUNTER_COMPONENTS]; + integrations.map(async (integration) => { + const component = COUNTER_COMPONENTS[integration.id as keyof typeof COUNTER_COMPONENTS]; const componentName = path.basename(component.filename, path.extname(component.filename)); const absFileLoc = path.resolve(cwd, component.filename); importStatements.push(`import ${componentName} from '${component.filename.replace(/^src/, '..')}';`); @@ -198,6 +227,32 @@ export async function main() { console.log(bold(green('✔') + ' Done!')); + const { name: pm } = whichPM() || { name: 'not_found' }; + const supportedPM = ['npm', 'yarn', 'pnpm'].includes(pm); + + if (supportedPM) { + const dependenciesSpinner = ora('Installing dependencies').start(); + try { + if (pm === 'yarn') await exec(['yarn'], { cwd }); + else if (pm === 'pnpm') await exec(['pnpm', 'install'], { cwd }); + else await exec(['npm', 'install'], { cwd }); + + dependenciesSpinner.succeed('Dependencies installed'); + } catch (error) { + dependenciesSpinner.fail('There was an error installing the dependencies.\n' + `You can try to run ${bold(cyan(`${pm} install`))} manually.` + issueMsg); + console.error(error); + } + } + + try { + console.log(`${green(`>`)} ${gray(`Initializating git...`)}`); + await exec(['git', 'init'], { cwd }); + await exec(['git', 'add', '-A'], { cwd }); + await exec(['git', 'commit', '-m', '"Initial commit"'], { cwd }); + } catch (error) { + logger.debug('Error with git init', error); + } + console.log('\nNext steps:'); let i = 1; @@ -206,9 +261,14 @@ export async function main() { 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 run dev'))} (or pnpm, yarn, etc)`); + if (!supportedPM) { + console.log(` ${i++}: ${bold(cyan('npm install'))} (or pnpm install, yarn, etc)`); + console.log(` ${i++}: ${bold(cyan('npm run dev'))} (or pnpm, yarn, etc)`); + } else { + if (pm === 'yarn') console.log(` ${i++}: ${bold(cyan('yarn dev'))}`); + else if (pm === 'pnpm') console.log(` ${i++}: ${bold(cyan('pnpm run dev'))}`); + else console.log(` ${i++}: ${bold(cyan('npm run dev'))}`); + } console.log(`\nTo close the dev server, hit ${bold(cyan('Ctrl-C'))}`); console.log(`\nStuck? Visit us at ${cyan('https://astro.build/chat')}\n`); From 3c35c49af777017d9bd9617029ee4f0baf618ac1 Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Sun, 20 Mar 2022 16:34:54 -0300 Subject: [PATCH 2/7] Added spinners --- packages/create-astro/src/index.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index 1ed9050788f7..c133dca71aa2 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -53,8 +53,9 @@ 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/withastro/astro/issues')} to search or file a new issue.\n`); - console.log(`${green(`>`)} ${gray(`Prepare for liftoff.`)}`); - console.log(`${green(`>`)} ${gray(`Gathering mission details...`)}`); + let spinner = ora({ color: 'green', text: 'Prepare for liftoff.' }); + + spinner.succeed(); const cwd = (args['_'][2] as string) || '.'; if (fs.existsSync(cwd)) { @@ -118,12 +119,13 @@ export async function main() { integrations = result.integrations; } + spinner = ora({ color: 'green', text: 'Copying project files...' }).start(); + // Copy try { emitter.on('info', (info) => { logger.debug(info.message); }); - console.log(`${green(`>`)} ${gray(`Copying project files...`)}`); await emitter.clone(cwd); } catch (err: any) { // degit is compiled, so the stacktrace is pretty noisy. Only report the stacktrace when using verbose mode. @@ -145,6 +147,7 @@ export async function main() { ) ); } + spinner.fail(); process.exit(1); } @@ -225,34 +228,38 @@ export async function main() { await fs.promises.writeFile(pageFileLoc, newContent); } - console.log(bold(green('✔') + ' Done!')); + spinner.succeed(); const { name: pm } = whichPM() || { name: 'not_found' }; const supportedPM = ['npm', 'yarn', 'pnpm'].includes(pm); if (supportedPM) { - const dependenciesSpinner = ora('Installing dependencies').start(); + spinner = ora({ color: 'green', text: 'Installing dependencies...' }).start(); try { if (pm === 'yarn') await exec(['yarn'], { cwd }); else if (pm === 'pnpm') await exec(['pnpm', 'install'], { cwd }); else await exec(['npm', 'install'], { cwd }); - dependenciesSpinner.succeed('Dependencies installed'); + spinner.succeed(); } catch (error) { - dependenciesSpinner.fail('There was an error installing the dependencies.\n' + `You can try to run ${bold(cyan(`${pm} install`))} manually.` + issueMsg); + spinner.fail('There was an error installing the dependencies.\n' + `You can try to run ${bold(cyan(`${pm} install`))} manually.` + issueMsg); console.error(error); } } try { - console.log(`${green(`>`)} ${gray(`Initializating git...`)}`); + spinner = ora({ color: 'green', text: 'Initializating git...' }).start(); await exec(['git', 'init'], { cwd }); await exec(['git', 'add', '-A'], { cwd }); await exec(['git', 'commit', '-m', '"Initial commit"'], { cwd }); + spinner.succeed(); } catch (error) { + spinner.fail(); logger.debug('Error with git init', error); } + console.log(bold(green('✔') + ' Done!')); + console.log('\nNext steps:'); let i = 1; From c8a8e4412f22303c00e73b35f2b4d7e5665543ce Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Sun, 20 Mar 2022 16:49:35 -0300 Subject: [PATCH 3/7] Updated lockfile --- pnpm-lock.yaml | 152 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 115 insertions(+), 37 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cb0896db5d65..817e15c895a7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,7 +44,7 @@ importers: examples/blog: specifiers: '@astrojs/preact': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 preact: ^10.6.6 dependencies: preact: 10.6.6 @@ -55,7 +55,7 @@ importers: examples/blog-multiple-authors: specifiers: '@astrojs/preact': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 preact: ^10.6.6 sass: ^1.49.9 dependencies: @@ -67,14 +67,14 @@ importers: examples/component: specifiers: - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 devDependencies: astro: link:../../packages/astro examples/component/demo: specifiers: '@example/my-component': workspace:* - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 devDependencies: '@example/my-component': link:../packages/my-component astro: link:../../../packages/astro @@ -90,7 +90,7 @@ importers: '@docsearch/css': ^3.0.0 '@docsearch/react': ^3.0.0 '@types/react': ^17.0.40 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 preact: ^10.6.6 react: ^17.0.2 react-dom: ^17.0.2 @@ -109,13 +109,13 @@ importers: examples/env-vars: specifiers: - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 devDependencies: astro: link:../../packages/astro examples/framework-alpine: specifiers: - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 devDependencies: astro: link:../../packages/astro @@ -123,7 +123,7 @@ importers: specifiers: '@astrojs/lit': ^0.0.1 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 lit: ^2.1.3 dependencies: '@webcomponents/template-shadowroot': 0.1.0 @@ -141,7 +141,7 @@ importers: '@astrojs/svelte': ^0.0.1 '@astrojs/vue': ^0.0.1 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 lit: ^2.1.3 preact: ^10.6.6 react: ^17.0.2 @@ -170,7 +170,7 @@ importers: examples/framework-preact: specifiers: '@astrojs/preact': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 preact: ^10.6.6 dependencies: preact: 10.6.6 @@ -181,7 +181,7 @@ importers: examples/framework-react: specifiers: '@astrojs/react': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 react: ^17.0.2 react-dom: ^17.0.2 dependencies: @@ -194,7 +194,7 @@ importers: examples/framework-solid: specifiers: '@astrojs/solid-js': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 solid-js: ^1.3.6 dependencies: solid-js: 1.3.13 @@ -205,7 +205,7 @@ importers: examples/framework-svelte: specifiers: '@astrojs/svelte': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 svelte: ^3.46.4 dependencies: svelte: 3.46.4 @@ -216,7 +216,7 @@ importers: examples/framework-vue: specifiers: '@astrojs/vue': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 vue: ^3.2.30 dependencies: vue: 3.2.31 @@ -233,7 +233,7 @@ importers: '@astrojs/tailwind': ^0.0.1 '@astrojs/turbolinks': ^0.0.1 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 lit: ^2.1.3 preact: ^10.6.6 react: ^17.0.2 @@ -261,20 +261,20 @@ importers: examples/minimal: specifiers: - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 devDependencies: astro: link:../../packages/astro examples/non-html-pages: specifiers: - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 devDependencies: astro: link:../../packages/astro examples/portfolio: specifiers: '@astrojs/preact': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 preact: ^10.6.6 sass: ^1.49.9 dependencies: @@ -287,7 +287,7 @@ importers: examples/ssr: specifiers: '@astrojs/svelte': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 concurrently: ^7.0.0 lightcookie: ^1.0.25 svelte: ^3.46.4 @@ -305,14 +305,14 @@ importers: examples/starter: specifiers: - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 devDependencies: astro: link:../../packages/astro examples/subpath: specifiers: '@astrojs/react': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 react: ^17.0.2 react-dom: ^17.0.2 sass: ^1.49.9 @@ -331,7 +331,7 @@ importers: '@astrojs/react': ^0.0.1 '@astrojs/svelte': ^0.0.1 '@astrojs/vue': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 preact: ^10.6.6 react: ^17.0.2 react-dom: ^17.0.2 @@ -354,7 +354,7 @@ importers: examples/with-markdown-plugins: specifiers: '@astrojs/markdown-remark': ^0.7.0-next.0 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 hast-util-select: 5.0.1 rehype-autolink-headings: ^6.1.1 rehype-slug: ^5.0.1 @@ -372,7 +372,7 @@ importers: examples/with-markdown-shiki: specifiers: '@astrojs/markdown-remark': ^0.7.0-next.0 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 devDependencies: '@astrojs/markdown-remark': link:../../packages/markdown/remark astro: link:../../packages/astro @@ -387,7 +387,7 @@ importers: '@nanostores/preact': ^0.1.3 '@nanostores/react': ^0.1.5 '@nanostores/vue': ^0.4.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 nanostores: ^0.5.12 preact: ^10.6.6 react: ^17.0.2 @@ -415,7 +415,7 @@ importers: examples/with-tailwindcss: specifiers: '@astrojs/tailwind': ^0.0.1 - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 autoprefixer: ^10.4.4 canvas-confetti: ^1.5.1 postcss: ^8.4.12 @@ -430,7 +430,7 @@ importers: examples/with-vite-plugin-pwa: specifiers: - astro: ^0.25.0-next.0 + astro: ^0.25.0-next.1 vite-plugin-pwa: 0.11.11 workbox-window: ^6.5.1 devDependencies: @@ -1158,13 +1158,16 @@ importers: specifiers: '@types/degit': ^2.8.3 '@types/prompts': ^2.0.14 + '@types/which-pm-runs': ^1.0.0 '@types/yargs-parser': ^21.0.0 astro-scripts: workspace:* degit: ^2.8.4 kleur: ^4.1.4 node-fetch: ^3.2.3 + ora: ^6.1.0 prompts: ^2.4.2 uvu: ^0.5.3 + which-pm-runs: ^1.1.0 yargs-parser: ^21.0.1 dependencies: '@types/degit': 2.8.3 @@ -1172,9 +1175,12 @@ importers: degit: 2.8.4 kleur: 4.1.4 node-fetch: 3.2.3 + ora: 6.1.0 prompts: 2.4.2 + which-pm-runs: 1.1.0 yargs-parser: 21.0.1 devDependencies: + '@types/which-pm-runs': 1.0.0 '@types/yargs-parser': 21.0.0 astro-scripts: link:../../scripts uvu: 0.5.3 @@ -3994,6 +4000,10 @@ packages: /@types/unist/2.0.6: resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==} + /@types/which-pm-runs/1.0.0: + resolution: {integrity: sha512-BXfdlYLWvRhngJbih4N57DjO+63Z7AxiFiip8yq3rD46U7V4I2W538gngPvBsZiMehhD8sfGf4xLI6k7TgXvNw==} + dev: true + /@types/yargs-parser/21.0.0: resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==} dev: true @@ -4642,7 +4652,6 @@ packages: /base64-js/1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} - dev: true /bcp-47-match/2.0.1: resolution: {integrity: sha512-+8o7axFDN/h8xATDM87FhnU1eod87dX0eZz1+cW3gggcicBqrmkZc33KBPWoE49qt5Asi5OhcxSOMOzp3opTfg==} @@ -4670,6 +4679,14 @@ packages: readable-stream: 3.6.0 dev: true + /bl/5.0.0: + resolution: {integrity: sha512-8vxFNZ0pflFfi0WXA3WQXlj6CaMEwsmh63I1CNp0q+wWv8sD0ARx1KovSQd0l2GkwrMIOyedq0EF1FxI+RCZLQ==} + dependencies: + buffer: 6.0.3 + inherits: 2.0.4 + readable-stream: 3.6.0 + dev: false + /boolbase/1.0.0: resolution: {integrity: sha1-aN/1++YMUes3cl6p4+0xDcwed24=} @@ -4721,6 +4738,13 @@ packages: ieee754: 1.2.1 dev: true + /buffer/6.0.3: + resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} + dependencies: + base64-js: 1.5.1 + ieee754: 1.2.1 + dev: false + /builtin-modules/3.2.0: resolution: {integrity: sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==} engines: {node: '>=6'} @@ -4816,6 +4840,11 @@ packages: ansi-styles: 4.3.0 supports-color: 7.2.0 + /chalk/5.0.1: + resolution: {integrity: sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w==} + engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + dev: false + /character-entities-html4/2.1.0: resolution: {integrity: sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==} dev: false @@ -4894,6 +4923,18 @@ packages: engines: {node: '>=6'} dev: true + /cli-cursor/4.0.0: + resolution: {integrity: sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + restore-cursor: 4.0.0 + dev: false + + /cli-spinners/2.6.1: + resolution: {integrity: sha512-x/5fWmGMnbKQAaNwN+UZlV79qBLM9JFnJuJ03gIi5whrob0xV0ofNVHy9DhwGdsMJQc2OKv0oGmLzvaqvAVv+g==} + engines: {node: '>=6'} + dev: false + /cliui/6.0.0: resolution: {integrity: sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==} dependencies: @@ -4913,7 +4954,6 @@ packages: /clone/1.0.4: resolution: {integrity: sha1-2jCcwmPfFZlMaIypAheco8fNfH4=} engines: {node: '>=0.8'} - dev: true /code-block-writer/10.1.1: resolution: {integrity: sha512-67ueh2IRGst/51p0n6FvPrnRjAGHY5F8xdjkgrYE7DDzpJe6qA07RYQ9VcoUeo5ATOjSOiWpSL3SWBRRbempMw==} @@ -5199,7 +5239,6 @@ packages: resolution: {integrity: sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=} dependencies: clone: 1.0.4 - dev: true /define-properties/1.1.3: resolution: {integrity: sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==} @@ -6729,7 +6768,6 @@ packages: /ieee754/1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} - dev: true /ignore/5.2.0: resolution: {integrity: sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==} @@ -6903,6 +6941,11 @@ packages: resolution: {integrity: sha512-DgZQp241c8oO6cA1SbTEWiXeoxV42vlcJxgH+B3hi1AiqqKruZR3ZGF8In3fj4+/y/7rHvlOZLZtgJ/4ttYGZg==} dev: false + /is-interactive/2.0.0: + resolution: {integrity: sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==} + engines: {node: '>=12'} + dev: false + /is-module/1.0.0: resolution: {integrity: sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=} dev: true @@ -7023,6 +7066,11 @@ packages: engines: {node: '>=10'} dev: true + /is-unicode-supported/1.1.0: + resolution: {integrity: sha512-lDcxivp8TJpLG75/DpatAqNzOpDPSpED8XNtrpBHTdQ2InQ1PbW78jhwSxyxhhu+xbVSast2X38bwj8atwoUQA==} + engines: {node: '>=12'} + dev: false + /is-weakref/1.0.2: resolution: {integrity: sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==} dependencies: @@ -7279,6 +7327,14 @@ packages: is-unicode-supported: 0.1.0 dev: true + /log-symbols/5.1.0: + resolution: {integrity: sha512-l0x2DvrW294C9uDCoQe1VSU4gf529FkSZ6leBl4TiqZH/e+0R7hSfHQBNut2mNygDgHwvYHfFLn6Oxb3VWj2rA==} + engines: {node: '>=12'} + dependencies: + chalk: 5.0.1 + is-unicode-supported: 1.1.0 + dev: false + /longest-streak/3.0.1: resolution: {integrity: sha512-cHlYSUpL2s7Fb3394mYxwTYj8niTaNHUCLr0qdiCXQfSjfuA7CKofpX2uSwEfFDQ0EB7JcnMnm+GjbqqoinYYg==} dev: false @@ -7833,7 +7889,6 @@ packages: /mimic-fn/2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} engines: {node: '>=6'} - dev: true /mimic-fn/4.0.0: resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} @@ -8121,7 +8176,6 @@ packages: engines: {node: '>=6'} dependencies: mimic-fn: 2.1.0 - dev: true /onetime/6.0.0: resolution: {integrity: sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==} @@ -8154,6 +8208,21 @@ packages: word-wrap: 1.2.3 dev: true + /ora/6.1.0: + resolution: {integrity: sha512-CxEP6845hLK+NHFWZ+LplGO4zfw4QSfxTlqMfvlJ988GoiUeZDMzCvqsZkFHv69sPICmJH1MDxZoQFOKXerAVw==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + bl: 5.0.0 + chalk: 5.0.1 + cli-cursor: 4.0.0 + cli-spinners: 2.6.1 + is-interactive: 2.0.0 + is-unicode-supported: 1.1.0 + log-symbols: 5.1.0 + strip-ansi: 7.0.1 + wcwidth: 1.0.1 + dev: false + /os-tmpdir/1.0.2: resolution: {integrity: sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=} engines: {node: '>=0.10.0'} @@ -8646,7 +8715,6 @@ packages: inherits: 2.0.4 string_decoder: 1.3.0 util-deprecate: 1.0.2 - dev: true /readdirp/3.6.0: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} @@ -8841,6 +8909,14 @@ packages: path-parse: 1.0.7 supports-preserve-symlinks-flag: 1.0.0 + /restore-cursor/4.0.0: + resolution: {integrity: sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + onetime: 5.1.2 + signal-exit: 3.0.7 + dev: false + /retext-latin/3.1.0: resolution: {integrity: sha512-5MrD1tuebzO8ppsja5eEu+ZbBeUNCjoEarn70tkXOS7Bdsdf6tNahsv2bY0Z8VooFF6cw7/6S+d3yI/TMlMVVQ==} dependencies: @@ -9077,7 +9153,6 @@ packages: /signal-exit/3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} - dev: true /simple-concat/1.0.1: resolution: {integrity: sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==} @@ -9350,7 +9425,6 @@ packages: resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} dependencies: safe-buffer: 5.2.1 - dev: true /stringify-entities/4.0.2: resolution: {integrity: sha512-MTxTVcEkorNtBbNpoFJPEh0kKdM6+QbMjLbaxmvaPMmayOXdr/AIVIIJX7FReUVweRBFJfZepK4A4AKgwuFpMQ==} @@ -10423,7 +10497,6 @@ packages: resolution: {integrity: sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g=} dependencies: defaults: 1.0.3 - dev: true /web-namespaces/2.0.1: resolution: {integrity: sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ==} @@ -10467,6 +10540,11 @@ packages: resolution: {integrity: sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=} dev: true + /which-pm-runs/1.1.0: + resolution: {integrity: sha512-n1brCuqClxfFfq/Rb0ICg9giSZqCS+pLtccdag6C2HyufBrh3fBOiy9nb6ggRMvWOVH5GrdJskj5iGTZNxd7SA==} + engines: {node: '>=4'} + dev: false + /which-pm/2.0.0: resolution: {integrity: sha512-Lhs9Pmyph0p5n5Z3mVnN0yWcbQYUAD7rbQUiMsQxOJ3T57k7RFe35SUwWMf7dsbDZks1uOmw4AecB/JMDj3v/w==} engines: {node: '>=8.15'} From 001701635dd7b286a07edad9ffbe6f995040b742 Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Sun, 20 Mar 2022 16:51:01 -0300 Subject: [PATCH 4/7] changeset --- .changeset/rude-starfishes-drop.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rude-starfishes-drop.md diff --git a/.changeset/rude-starfishes-drop.md b/.changeset/rude-starfishes-drop.md new file mode 100644 index 000000000000..088c9d923fdb --- /dev/null +++ b/.changeset/rude-starfishes-drop.md @@ -0,0 +1,5 @@ +--- +'create-astro': minor +--- + +Install dependencies automatically From f3675d993f838c3d5092d354c186dad9d412e546 Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Mon, 21 Mar 2022 10:10:57 -0300 Subject: [PATCH 5/7] Sort dependencies --- packages/create-astro/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index c133dca71aa2..2cd996c1cfde 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -180,7 +180,7 @@ export async function main() { fetch(`https://registry.npmjs.org/${integration.packageName}/latest`) .then((res) => res.json()) .then((res: any) => { - let dependencies = [[res['name'], `^${res['version']}`]]; + let dependencies: [string, string][] = [[res['name'], `^${res['version']}`]]; if (res['peerDependencies']) { for (const peer in res['peerDependencies']) { @@ -193,7 +193,9 @@ export async function main() { ) ) ).flat(1); + // merge and sort dependencies packageJSON.devDependencies = { ...(packageJSON.devDependencies ?? {}), ...Object.fromEntries(integrationEntries) }; + packageJSON.devDependencies = Object.fromEntries(Object.entries(packageJSON.devDependencies).sort((a, b) => a[0].localeCompare(b[0]))); await fs.promises.writeFile(fileLoc, JSON.stringify(packageJSON, undefined, 2)); break; } From c1da8e978ac754d76709b40c2cfc3ecbfa3cd549 Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Mon, 21 Mar 2022 10:15:18 -0300 Subject: [PATCH 6/7] Reverted autoinstall --- packages/create-astro/package.json | 2 -- packages/create-astro/src/index.ts | 57 ++---------------------------- pnpm-lock.yaml | 13 ------- 3 files changed, 3 insertions(+), 69 deletions(-) diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json index 2a867ea495d9..e46400362b25 100644 --- a/packages/create-astro/package.json +++ b/packages/create-astro/package.json @@ -34,11 +34,9 @@ "node-fetch": "^3.2.3", "ora": "^6.1.0", "prompts": "^2.4.2", - "which-pm-runs": "^1.1.0", "yargs-parser": "^21.0.1" }, "devDependencies": { - "@types/which-pm-runs": "^1.0.0", "@types/yargs-parser": "^21.0.0", "astro-scripts": "workspace:*", "uvu": "^0.5.3" diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index 2cd996c1cfde..f41f2a87c4c7 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -1,13 +1,11 @@ import fs from 'fs'; import path from 'path'; -import { exec as childProcessExec, ExecOptions } from 'child_process'; import { bold, cyan, gray, green, red, yellow } from 'kleur/colors'; import fetch from 'node-fetch'; import prompts from 'prompts'; import degit from 'degit'; import yargs from 'yargs-parser'; import ora from 'ora'; -import whichPM from 'which-pm-runs'; import { FRAMEWORKS, COUNTER_COMPONENTS, Integration } from './frameworks.js'; import { TEMPLATES } from './templates.js'; import { createConfig } from './config.js'; @@ -30,24 +28,10 @@ export function mkdirp(dir: string) { } } -function exec(command: string[], options: ExecOptions = {}) { - return new Promise((resolve, reject) => { - childProcessExec(command.join(' '), options, (err, stdout, stderr) => { - if (err) { - reject(stderr); - } else { - resolve(stdout); - } - }); - }); -} - const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8')); const POSTPROCESS_FILES = ['package.json', 'astro.config.mjs', 'CHANGELOG.md']; // some files need processing after copying. -const issueMsg = '\nIf you think this is an error, feel free to open an issue in our GitHub repo: https://github.com/withastro/astro/issues/new'; - export async function main() { logger.debug('Verbose logging turned on'); console.log(`\n${bold('Welcome to Astro!')} ${gray(`(create-astro v${version})`)}`); @@ -231,53 +215,18 @@ export async function main() { } spinner.succeed(); - - const { name: pm } = whichPM() || { name: 'not_found' }; - const supportedPM = ['npm', 'yarn', 'pnpm'].includes(pm); - - if (supportedPM) { - spinner = ora({ color: 'green', text: 'Installing dependencies...' }).start(); - try { - if (pm === 'yarn') await exec(['yarn'], { cwd }); - else if (pm === 'pnpm') await exec(['pnpm', 'install'], { cwd }); - else await exec(['npm', 'install'], { cwd }); - - spinner.succeed(); - } catch (error) { - spinner.fail('There was an error installing the dependencies.\n' + `You can try to run ${bold(cyan(`${pm} install`))} manually.` + issueMsg); - console.error(error); - } - } - - try { - spinner = ora({ color: 'green', text: 'Initializating git...' }).start(); - await exec(['git', 'init'], { cwd }); - await exec(['git', 'add', '-A'], { cwd }); - await exec(['git', 'commit', '-m', '"Initial commit"'], { cwd }); - spinner.succeed(); - } catch (error) { - spinner.fail(); - logger.debug('Error with git init', error); - } - console.log(bold(green('✔') + ' Done!')); console.log('\nNext steps:'); let i = 1; - const relative = path.relative(process.cwd(), cwd); if (relative !== '') { console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`); } - if (!supportedPM) { - console.log(` ${i++}: ${bold(cyan('npm install'))} (or pnpm install, yarn, etc)`); - console.log(` ${i++}: ${bold(cyan('npm run dev'))} (or pnpm, yarn, etc)`); - } else { - if (pm === 'yarn') console.log(` ${i++}: ${bold(cyan('yarn dev'))}`); - else if (pm === 'pnpm') console.log(` ${i++}: ${bold(cyan('pnpm run dev'))}`); - else console.log(` ${i++}: ${bold(cyan('npm run dev'))}`); - } + 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 run dev'))} (or pnpm, yarn, etc)`); console.log(`\nTo close the dev server, hit ${bold(cyan('Ctrl-C'))}`); console.log(`\nStuck? Visit us at ${cyan('https://astro.build/chat')}\n`); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 817e15c895a7..9fd734a0c686 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1158,7 +1158,6 @@ importers: specifiers: '@types/degit': ^2.8.3 '@types/prompts': ^2.0.14 - '@types/which-pm-runs': ^1.0.0 '@types/yargs-parser': ^21.0.0 astro-scripts: workspace:* degit: ^2.8.4 @@ -1167,7 +1166,6 @@ importers: ora: ^6.1.0 prompts: ^2.4.2 uvu: ^0.5.3 - which-pm-runs: ^1.1.0 yargs-parser: ^21.0.1 dependencies: '@types/degit': 2.8.3 @@ -1177,10 +1175,8 @@ importers: node-fetch: 3.2.3 ora: 6.1.0 prompts: 2.4.2 - which-pm-runs: 1.1.0 yargs-parser: 21.0.1 devDependencies: - '@types/which-pm-runs': 1.0.0 '@types/yargs-parser': 21.0.0 astro-scripts: link:../../scripts uvu: 0.5.3 @@ -4000,10 +3996,6 @@ packages: /@types/unist/2.0.6: resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==} - /@types/which-pm-runs/1.0.0: - resolution: {integrity: sha512-BXfdlYLWvRhngJbih4N57DjO+63Z7AxiFiip8yq3rD46U7V4I2W538gngPvBsZiMehhD8sfGf4xLI6k7TgXvNw==} - dev: true - /@types/yargs-parser/21.0.0: resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==} dev: true @@ -10540,11 +10532,6 @@ packages: resolution: {integrity: sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=} dev: true - /which-pm-runs/1.1.0: - resolution: {integrity: sha512-n1brCuqClxfFfq/Rb0ICg9giSZqCS+pLtccdag6C2HyufBrh3fBOiy9nb6ggRMvWOVH5GrdJskj5iGTZNxd7SA==} - engines: {node: '>=4'} - dev: false - /which-pm/2.0.0: resolution: {integrity: sha512-Lhs9Pmyph0p5n5Z3mVnN0yWcbQYUAD7rbQUiMsQxOJ3T57k7RFe35SUwWMf7dsbDZks1uOmw4AecB/JMDj3v/w==} engines: {node: '>=8.15'} From ab164169897e7cae64aaac05dc1bde8bdf07b05a Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Mon, 21 Mar 2022 10:16:35 -0300 Subject: [PATCH 7/7] Updated changeset --- .changeset/rude-starfishes-drop.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/rude-starfishes-drop.md b/.changeset/rude-starfishes-drop.md index 088c9d923fdb..82ae86b0d0ab 100644 --- a/.changeset/rude-starfishes-drop.md +++ b/.changeset/rude-starfishes-drop.md @@ -1,5 +1,5 @@ --- -'create-astro': minor +'create-astro': patch --- -Install dependencies automatically +Add peer dependencies to package.json