Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/amplify-template-guidance.md
Original file line number Diff line number Diff line change
@@ -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`.
3 changes: 2 additions & 1 deletion packages/create-blocks-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

```
Expand Down
10 changes: 9 additions & 1 deletion packages/create-blocks-app/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 13 additions & 5 deletions packages/create-blocks-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down