diff --git a/.changeset/amplify-template-guidance.md b/.changeset/amplify-template-guidance.md new file mode 100644 index 00000000..32b9f3a8 --- /dev/null +++ b/.changeset/amplify-template-guidance.md @@ -0,0 +1,5 @@ +--- +"@aws-blocks/create-blocks-app": patch +--- + +Treat Amplify Gen 2 integration as an auto-detected existing-project flow instead of advertising it as a fresh project template, and report clear guidance for `--template amplify`. diff --git a/packages/create-blocks-app/README.md b/packages/create-blocks-app/README.md index 7c0cc843..e082acea 100644 --- a/packages/create-blocks-app/README.md +++ b/packages/create-blocks-app/README.md @@ -27,7 +27,6 @@ Available templates: - **backend** - Backend-only (no frontend) - **nextjs** - Next.js integration - **auth-cognito** - Cognito authentication example -- **amplify** - Amplify Gen 2 integration - **demo** - Demo application ### Add to Existing Project @@ -46,6 +45,8 @@ npx @aws-blocks/create-blocks-app . The CLI detects your Amplify project (`amplify/backend.ts`) and integrates Blocks alongside it — adding a `aws-blocks/` workspace, wiring auth via bearer tokens, and scaffolding npm scripts for deployment. Your existing Amplify auth, data, and hosting stay untouched. +Amplify Gen 2 integration is auto-detected from an existing project and is not selected with `--template`. + ## What Gets Created ``` diff --git a/packages/create-blocks-app/src/cli.test.ts b/packages/create-blocks-app/src/cli.test.ts index f440fc0b..0c35c8ba 100644 --- a/packages/create-blocks-app/src/cli.test.ts +++ b/packages/create-blocks-app/src/cli.test.ts @@ -31,7 +31,7 @@ describe('create-blocks-app CLI argument parsing', () => { assert.strictEqual(result.exitCode, 0); assert.match(result.stdout, /Usage: create-blocks-app/); assert.match(result.stdout, /--template/); - assert.match(result.stdout, /Available templates: default, bare, react, backend, nextjs, auth-cognito, amplify, demo/); + assert.match(result.stdout, /Available templates: default, bare, react, backend, nextjs, auth-cognito, demo/); assert.match(result.stdout, /--help/); assert.match(result.stdout, /auto-detected/); }); @@ -77,6 +77,14 @@ describe('create-blocks-app CLI argument parsing', () => { assert.doesNotMatch(result.stderr, /ENOENT/); }); + it('--template amplify exits 1 with existing-project guidance', () => { + const result = run(['my-app', '--template', 'amplify']); + assert.strictEqual(result.exitCode, 1); + assert.match(result.stderr, /Amplify integration is auto-detected/); + assert.match(result.stderr, /npx @aws-blocks\/create-blocks-app \./); + assert.doesNotMatch(result.stderr, /ENOENT/); + }); + it('multiple positional args exits 1 with error message', () => { const result = run(['my-app', 'extra-arg']); assert.strictEqual(result.exitCode, 1); diff --git a/packages/create-blocks-app/src/index.ts b/packages/create-blocks-app/src/index.ts index 5686730f..6367890e 100644 --- a/packages/create-blocks-app/src/index.ts +++ b/packages/create-blocks-app/src/index.ts @@ -173,12 +173,13 @@ async function addBlocksWorkspace(targetDir: string, options: { } } -const AVAILABLE_TEMPLATES = ['default', 'bare', 'react', 'backend', 'nextjs', 'auth-cognito', 'amplify', 'demo']; +const FRESH_PROJECT_TEMPLATES = ['default', 'bare', 'react', 'backend', 'nextjs', 'auth-cognito', 'demo']; +const AMPLIFY_INTEGRATION_TEMPLATE = 'amplify'; function validateTemplateName(templateName: string): void { - if (!AVAILABLE_TEMPLATES.includes(templateName)) { + if (!FRESH_PROJECT_TEMPLATES.includes(templateName)) { console.error(`Error: Unknown template "${templateName}".`); - console.error(`Available templates: ${AVAILABLE_TEMPLATES.join(', ')}`); + console.error(`Available templates: ${FRESH_PROJECT_TEMPLATES.join(', ')}`); process.exit(1); } } @@ -295,7 +296,7 @@ async function integrateWithAmplify(targetDir: string, skipConfirm = false, skip console.log('\nšŸ“¦ Scaffolding Blocks...\n'); // 1. Copy aws-blocks/ template - const templateDir = join(__dirname, '../templates/amplify'); + const templateDir = join(__dirname, '../templates', AMPLIFY_INTEGRATION_TEMPLATE); const awsBlocksSrc = join(templateDir, 'aws-blocks'); const awsBlocksDest = join(targetDir, 'aws-blocks'); await cp(awsBlocksSrc, awsBlocksDest, { recursive: true }); @@ -574,7 +575,7 @@ Options: starter app; when adding to an existing project it selects which aws-blocks/ workspace to copy, e.g. "nextjs" for a Next.js dev server (default: "default") - Available templates: ${AVAILABLE_TEMPLATES.join(', ')} + Available templates: ${FRESH_PROJECT_TEMPLATES.join(', ')} -y, --yes Skip confirmation prompts -h, --help Show this help message @@ -625,6 +626,13 @@ async function create() { } } + if (templateName === AMPLIFY_INTEGRATION_TEMPLATE) { + console.error('Error: The Amplify integration is auto-detected and is not a fresh project template.'); + console.error('Run from your Amplify Gen 2 project root without --template:'); + console.error(' npx @aws-blocks/create-blocks-app .'); + process.exit(1); + } + validateTemplateName(templateName); const templatePkgVersion: string = JSON.parse(