create-aws-project 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -69,6 +69,7 @@ The interactive wizard will ask you about:
69
69
  - VS Code workspace configuration
70
70
  6. **AWS region** - Where to deploy your infrastructure
71
71
  7. **Brand color** - Theme color for your UI (blue, purple, teal, green, orange)
72
+ 8. **GitHub repository** *(optional)* - Provide a repo URL to git init, commit, and push automatically. Press Enter to skip.
72
73
 
73
74
  ## Requirements
74
75
 
@@ -84,32 +85,9 @@ After creating your project, you'll set up AWS environments and GitHub deploymen
84
85
 
85
86
  Before you begin:
86
87
  - AWS CLI configured with credentials from your AWS management account
87
- - GitHub repository created for your project
88
88
  - GitHub Personal Access Token with "repo" scope ([create one here](https://github.com/settings/tokens/new))
89
89
 
90
- ### Step 1: connect to your .git project
91
-
92
- * Initialize the repository
93
- ```
94
- git init
95
- ```
96
-
97
- * Add the remote repository using the git remote add <name> <url> command. A common practice is to name it origin.
98
- ```bash
99
- git remote add origin <REMOTE_URL>
100
- ```
101
-
102
- * Verify the connection by listing your remotes. The -v flag shows the URLs.
103
- ```bash
104
- git remote -v
105
- ```
106
-
107
- * Push your local commits to the remote repository for the first time.
108
- ```bash
109
- git push -u origin main
110
- ```
111
-
112
- ### Step 2: Set Up AWS Environments
90
+ ### Step 1: Set Up AWS Environments
113
91
 
114
92
  From your project directory, run:
115
93
 
@@ -136,7 +114,7 @@ AWS environment setup complete!
136
114
 
137
115
  Account IDs are saved to `.aws-starter-config.json` for the next step.
138
116
 
139
- ### Step 3: Configure GitHub Environments
117
+ ### Step 2: Configure GitHub Environments
140
118
 
141
119
  For each environment, run:
142
120
 
package/dist/cli.js CHANGED
@@ -7,6 +7,7 @@ import { generateProject } from './generator/index.js';
7
7
  import { showDeprecationNotice } from './commands/setup-github.js';
8
8
  import { runSetupAwsEnvs } from './commands/setup-aws-envs.js';
9
9
  import { runInitializeGitHub } from './commands/initialize-github.js';
10
+ import { promptGitSetup, setupGitRepository } from './git/setup.js';
10
11
  /**
11
12
  * Write project configuration file for downstream commands
12
13
  */
@@ -40,7 +41,7 @@ function getVersion() {
40
41
  */
41
42
  function printHelp() {
42
43
  console.log(`
43
- create-aws-starter-kit [command] [options]
44
+ create-aws-project [command] [options]
44
45
 
45
46
  Scaffold a new AWS Starter Kit project with React, Lambda, and CDK infrastructure.
46
47
 
@@ -55,15 +56,15 @@ Options:
55
56
  --version, -v Show version number
56
57
 
57
58
  Usage:
58
- create-aws-starter-kit Run interactive wizard
59
- create-aws-starter-kit setup-aws-envs Create AWS accounts
60
- create-aws-starter-kit initialize-github dev Configure dev environment
59
+ create-aws-project Run interactive wizard
60
+ create-aws-project setup-aws-envs Create AWS accounts
61
+ create-aws-project initialize-github dev Configure dev environment
61
62
 
62
63
  Examples:
63
- create-aws-starter-kit my-app
64
- create-aws-starter-kit setup-aws-envs
65
- create-aws-starter-kit initialize-github dev
66
- create-aws-starter-kit --help
64
+ create-aws-project my-app
65
+ create-aws-project setup-aws-envs
66
+ create-aws-project initialize-github dev
67
+ create-aws-project --help
67
68
  `.trim());
68
69
  }
69
70
  /**
@@ -73,7 +74,7 @@ function printWelcome() {
73
74
  console.log(`
74
75
  ╔═══════════════════════════════════════════════════════╗
75
76
  ║ ║
76
- ║ create-aws-starter-kit
77
+ ║ create-aws-project
77
78
  ║ AWS Starter Kit Project Generator ║
78
79
  ║ ║
79
80
  ╚═══════════════════════════════════════════════════════╝
@@ -113,10 +114,12 @@ function printNextSteps(projectName, platforms) {
113
114
  * Run the create project wizard flow
114
115
  * This is the default command when no subcommand is specified
115
116
  */
116
- async function runCreate(_args) {
117
+ async function runCreate(args) {
117
118
  printWelcome();
118
119
  console.log(''); // blank line after banner
119
- const config = await runWizard();
120
+ // Extract project name from CLI args (first non-flag argument)
121
+ const nameArg = args.find(arg => !arg.startsWith('-'));
122
+ const config = await runWizard(nameArg ? { defaultName: nameArg } : undefined);
120
123
  if (!config) {
121
124
  console.log('\nProject creation cancelled.');
122
125
  process.exit(1);
@@ -137,6 +140,11 @@ async function runCreate(_args) {
137
140
  await generateProject(config, outputDir);
138
141
  // Write config file for downstream commands
139
142
  writeConfigFile(outputDir, config);
143
+ // Optional: GitHub repository setup
144
+ const gitResult = await promptGitSetup();
145
+ if (gitResult) {
146
+ await setupGitRepository(outputDir, gitResult.repoUrl, gitResult.pat);
147
+ }
140
148
  // Success message and next steps
141
149
  console.log('');
142
150
  console.log(pc.green('✔') + ` Created ${pc.bold(config.projectName)} successfully!`);
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Git setup module
3
+ *
4
+ * Provides optional GitHub repository setup after project generation.
5
+ * Users can push their generated project to GitHub in the same wizard flow.
6
+ * Fully optional - pressing Enter skips all git operations.
7
+ */
8
+ /**
9
+ * Checks if git is available on the system
10
+ * @returns true if git is installed and available, false otherwise
11
+ */
12
+ export declare function isGitAvailable(): boolean;
13
+ /**
14
+ * Prompts user for optional GitHub repository setup
15
+ * @returns Repository URL and PAT if user wants git setup, null if skipped
16
+ */
17
+ export declare function promptGitSetup(): Promise<{
18
+ repoUrl: string;
19
+ pat: string;
20
+ } | null>;
21
+ /**
22
+ * Sets up git repository with initial commit and pushes to GitHub
23
+ * Creates the remote repository if it doesn't exist
24
+ * @param projectDir - Path to the project directory
25
+ * @param repoUrl - GitHub repository URL
26
+ * @param pat - GitHub Personal Access Token
27
+ */
28
+ export declare function setupGitRepository(projectDir: string, repoUrl: string, pat: string): Promise<void>;
@@ -0,0 +1,165 @@
1
+ import { execSync } from 'node:child_process';
2
+ import prompts from 'prompts';
3
+ import ora from 'ora';
4
+ import pc from 'picocolors';
5
+ import { parseGitHubUrl, createGitHubClient } from '../github/secrets.js';
6
+ /**
7
+ * Git setup module
8
+ *
9
+ * Provides optional GitHub repository setup after project generation.
10
+ * Users can push their generated project to GitHub in the same wizard flow.
11
+ * Fully optional - pressing Enter skips all git operations.
12
+ */
13
+ /**
14
+ * Checks if git is available on the system
15
+ * @returns true if git is installed and available, false otherwise
16
+ */
17
+ export function isGitAvailable() {
18
+ try {
19
+ execSync('git --version', { stdio: 'pipe' });
20
+ return true;
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ }
26
+ /**
27
+ * Prompts user for optional GitHub repository setup
28
+ * @returns Repository URL and PAT if user wants git setup, null if skipped
29
+ */
30
+ export async function promptGitSetup() {
31
+ // Skip if git is not available
32
+ if (!isGitAvailable()) {
33
+ return null;
34
+ }
35
+ console.log('');
36
+ console.log(pc.bold('GitHub Repository (optional)'));
37
+ console.log(pc.dim('Push your project to a GitHub repository. Press Enter to skip.'));
38
+ console.log('');
39
+ // Prompt for repo URL
40
+ const repoResponse = await prompts({
41
+ type: 'text',
42
+ name: 'repoUrl',
43
+ message: 'GitHub repository URL:',
44
+ });
45
+ const repoUrl = repoResponse.repoUrl?.trim();
46
+ if (!repoUrl) {
47
+ return null; // User skipped
48
+ }
49
+ // Validate the URL
50
+ try {
51
+ parseGitHubUrl(repoUrl);
52
+ }
53
+ catch (error) {
54
+ if (error instanceof Error) {
55
+ console.log(pc.red('Error: ') + error.message);
56
+ }
57
+ return null;
58
+ }
59
+ // Prompt for PAT
60
+ const patResponse = await prompts({
61
+ type: 'password',
62
+ name: 'pat',
63
+ message: 'GitHub Personal Access Token:',
64
+ validate: (value) => {
65
+ if (!value.trim()) {
66
+ return 'Token is required';
67
+ }
68
+ // GitHub tokens start with ghp_ (classic) or github_pat_ (fine-grained)
69
+ if (!value.startsWith('ghp_') && !value.startsWith('github_pat_')) {
70
+ return 'Invalid token format. Expected ghp_ or github_pat_ prefix.';
71
+ }
72
+ return true;
73
+ },
74
+ }, {
75
+ onCancel: () => {
76
+ // User cancelled PAT prompt
77
+ return;
78
+ },
79
+ });
80
+ if (!patResponse.pat) {
81
+ return null; // User cancelled
82
+ }
83
+ return { repoUrl, pat: patResponse.pat };
84
+ }
85
+ /**
86
+ * Sets up git repository with initial commit and pushes to GitHub
87
+ * Creates the remote repository if it doesn't exist
88
+ * @param projectDir - Path to the project directory
89
+ * @param repoUrl - GitHub repository URL
90
+ * @param pat - GitHub Personal Access Token
91
+ */
92
+ export async function setupGitRepository(projectDir, repoUrl, pat) {
93
+ const spinner = ora();
94
+ try {
95
+ // Parse the URL
96
+ const { owner, repo } = parseGitHubUrl(repoUrl);
97
+ // Create Octokit client
98
+ const octokit = createGitHubClient(pat);
99
+ // Git init
100
+ spinner.start('Initializing git repository...');
101
+ execSync('git init -b main', { cwd: projectDir, stdio: 'pipe' });
102
+ // Check for git user config, set if not configured
103
+ try {
104
+ execSync('git config user.name', { cwd: projectDir, stdio: 'pipe' });
105
+ }
106
+ catch {
107
+ // User config not set, use defaults
108
+ execSync('git config user.name "create-aws-project"', { cwd: projectDir, stdio: 'pipe' });
109
+ execSync('git config user.email "noreply@create-aws-project"', { cwd: projectDir, stdio: 'pipe' });
110
+ }
111
+ execSync('git add .', { cwd: projectDir, stdio: 'pipe' });
112
+ execSync('git commit -m "Initial commit from create-aws-project"', { cwd: projectDir, stdio: 'pipe' });
113
+ spinner.succeed('Git repository initialized');
114
+ // Ensure remote repo exists
115
+ spinner.start('Checking GitHub repository...');
116
+ try {
117
+ await octokit.rest.repos.get({ owner, repo });
118
+ spinner.succeed(`Repository ${owner}/${repo} found`);
119
+ }
120
+ catch (error) {
121
+ if (error.status === 404) {
122
+ // Repo doesn't exist, create it
123
+ const { data: user } = await octokit.rest.users.getAuthenticated();
124
+ if (owner === user.login) {
125
+ // Create in user's account
126
+ await octokit.rest.repos.createForAuthenticatedUser({
127
+ name: repo,
128
+ private: true,
129
+ auto_init: false,
130
+ });
131
+ }
132
+ else {
133
+ // Create in organization
134
+ await octokit.rest.repos.createInOrg({
135
+ org: owner,
136
+ name: repo,
137
+ private: true,
138
+ auto_init: false,
139
+ });
140
+ }
141
+ spinner.succeed(`Created repository ${owner}/${repo}`);
142
+ }
143
+ else {
144
+ throw error;
145
+ }
146
+ }
147
+ // Push to remote
148
+ spinner.start('Pushing to GitHub...');
149
+ const authUrl = `https://${pat}@github.com/${owner}/${repo}.git`;
150
+ execSync(`git remote add origin ${authUrl}`, { cwd: projectDir, stdio: 'pipe' });
151
+ execSync('git push -u origin main', { cwd: projectDir, stdio: 'pipe' });
152
+ // CRITICAL: Remove PAT from .git/config
153
+ const cleanUrl = `https://github.com/${owner}/${repo}.git`;
154
+ execSync(`git remote set-url origin ${cleanUrl}`, { cwd: projectDir, stdio: 'pipe' });
155
+ spinner.succeed(`Pushed to ${owner}/${repo}`);
156
+ }
157
+ catch (error) {
158
+ // Git setup failure should not prevent the user from using their project
159
+ if (spinner.isSpinning) {
160
+ spinner.fail();
161
+ }
162
+ console.log(pc.yellow('Warning:') + ' Git setup failed: ' + (error instanceof Error ? error.message : 'Unknown error'));
163
+ console.log(pc.dim('Your project was created successfully. You can set up git manually.'));
164
+ }
165
+ }
package/dist/wizard.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  import type { ProjectConfig } from './types.js';
2
- export declare function runWizard(): Promise<ProjectConfig | null>;
2
+ export interface WizardOptions {
3
+ defaultName?: string;
4
+ }
5
+ export declare function runWizard(options?: WizardOptions): Promise<ProjectConfig | null>;
package/dist/wizard.js CHANGED
@@ -6,9 +6,13 @@ import { authProviderPrompt, authFeaturesPrompt } from './prompts/auth.js';
6
6
  import { featuresPrompt } from './prompts/features.js';
7
7
  import { awsRegionPrompt } from './prompts/aws-config.js';
8
8
  import { themePrompt } from './prompts/theme.js';
9
- export async function runWizard() {
9
+ export async function runWizard(options = {}) {
10
+ // Create name prompt with optional default override
11
+ const namePrompt = options.defaultName
12
+ ? { ...projectNamePrompt, initial: options.defaultName }
13
+ : projectNamePrompt;
10
14
  const response = await prompts([
11
- projectNamePrompt,
15
+ namePrompt,
12
16
  platformsPrompt,
13
17
  authProviderPrompt,
14
18
  authFeaturesPrompt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-aws-project",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "CLI tool to scaffold AWS projects",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -109,7 +109,7 @@ Push to main to trigger your first deployment:
109
109
  git push origin main
110
110
  ```
111
111
 
112
- For detailed setup instructions and troubleshooting, see the [create-aws-project documentation](https://www.npmjs.com/package/create-aws-starter-kit).
112
+ For detailed setup instructions and troubleshooting, see the [create-aws-project documentation](https://www.npmjs.com/package/create-aws-project).
113
113
 
114
114
  ## CI/CD Workflows
115
115