code-craft-cli 1.0.0

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.
Files changed (3) hide show
  1. package/README.md +63 -0
  2. package/bin/index.js +49 -0
  3. package/package.json +26 -0
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # code-craft-cli
2
+
3
+ A high-performance CLI tool that generates runnable code files from natural language prompts using Google's Gemini 2.0 Flash AI.
4
+
5
+ ## Installation
6
+
7
+ Install the package globally via NPM so you can use the `gen` command anywhere:
8
+
9
+ ```bash
10
+ npm install -g code-craft-cli
11
+ ```
12
+
13
+ ## Setup
14
+
15
+ You need a Google Generative AI API key to use this tool. Set it up in a .env file in your project root or add it to your environment variables:
16
+
17
+ ```
18
+ GOOGLE_GENERATIVE_AI_API_KEY=your_api_key_here
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Run the tool by describing the code you want to generate. By default, it saves to output.ts.
24
+
25
+ ```bash
26
+ gen "Create a function to calculate the area of a circle"
27
+ ```
28
+
29
+ ## Specify Filename and Extension
30
+
31
+ The tool is context-aware. If you use a .ts extension, it will automatically provide explicit TypeScript types and interfaces. For .js, it will provide clean JavaScript.
32
+
33
+ ```bash
34
+ # Generate a JavaScript file
35
+ gen "fetch bitcoin price from a public API" --name crypto.js
36
+
37
+ # Generate a TypeScript file
38
+ gen "binary search algorithm" --name search.ts
39
+ ```
40
+
41
+ ## Features
42
+
43
+ - **Smart Type Detection**: Automatically applies TypeScript types if the output file is .ts, ensuring your code is ready for professional environments.
44
+ - **Clean Output**: Automatically strips AI markdown backticks (```) so the generated file contains only valid code.
45
+ - **Immediate Execution**: Includes example variables and console.log statements so you can run node filename.js and see the results instantly.
46
+ - **Modern Tech Stack**: Built with Node.js, Vercel AI SDK, and Gemini 2.0 Flash.
47
+
48
+ ## Requirements
49
+
50
+ - **Node.js**: 18.0.0 or higher
51
+ - **API Key**: A valid Google Gemini API key from Google AI Studio
52
+
53
+ ## Author
54
+
55
+ Syed Affan Ali
56
+
57
+ GitHub: MrAfoo
58
+
59
+ Portfolio: mrafoo-portfolio.vercel.app
60
+
61
+ ## License
62
+
63
+ MIT
package/bin/index.js ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { generateText } from 'ai';
4
+ import { google } from '@ai-sdk/google';
5
+ import fs from 'fs';
6
+ import ora from 'ora';
7
+ import chalk from 'chalk';
8
+ import 'dotenv/config';
9
+
10
+ const program = new Command();
11
+
12
+ const packageJson = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
13
+
14
+ program
15
+ .name('gen')
16
+ .description('Code Craft CLI: AI-powered code generation')
17
+ .version(packageJson.version) // Fixes the --version error
18
+ .argument('<prompt>', 'What do you want to build?')
19
+ .option('-n, --name <name>', 'Filename', 'output.ts')
20
+ .action(async (prompt, options) => {
21
+ const spinner = ora(chalk.cyan('AI is generating your code...')).start();
22
+
23
+ try {
24
+ const { text } = await generateText({
25
+ model: google('gemini-2.5-flash'),
26
+ prompt: `
27
+ Task: ${prompt}
28
+ File Name: ${options.name}
29
+
30
+ CRITICAL INSTRUCTIONS:
31
+ 1. If the file ends in .ts, you MUST use TypeScript syntax with explicit types.
32
+ 2. If the file ends in .js, you MUST use pure JavaScript. DO NOT use type annotations, interfaces, or any TS-specific syntax.
33
+ 3. Include example data and a console.log to make it runnable.
34
+ 4. Output ONLY the code. No markdown backticks or explanation.
35
+ `,
36
+ });
37
+
38
+ // Regex to ensure no backticks end up in your file
39
+ const cleanCode = text.replace(/```[a-z]*\n/g, '').replace(/```/g, '');
40
+
41
+ fs.writeFileSync(options.name, cleanCode);
42
+ spinner.succeed(chalk.green(`File ${options.name} created successfully!`));
43
+ } catch (error) {
44
+ spinner.fail(chalk.red('Error generating code.'));
45
+ console.error(error);
46
+ }
47
+ });
48
+
49
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "code-craft-cli",
3
+ "version": "1.0.0",
4
+ "description": "A high-performance CLI tool to generate runnable code files using Gemini AI",
5
+ "type": "module",
6
+ "author": "Syed Affan Ali",
7
+ "bin": {
8
+ "gen": "./bin/index.js"
9
+ },
10
+ "keywords": [
11
+ "ai",
12
+ "gemini",
13
+ "automation",
14
+ "cli",
15
+ "typescript"
16
+ ],
17
+ "license": "MIT",
18
+ "dependencies": {
19
+ "@ai-sdk/google": "^3.0.71",
20
+ "ai": "^6.0.177",
21
+ "chalk": "^5.4.1",
22
+ "commander": "^13.1.0",
23
+ "dotenv": "^16.4.7",
24
+ "ora": "^8.2.1"
25
+ }
26
+ }