Skip to content

feat: add automated template initialization script#103

Open
madhavansingh wants to merge 1 commit intoAOSSIE-Org:mainfrom
madhavansingh:feat/template-setup-script
Open

feat: add automated template initialization script#103
madhavansingh wants to merge 1 commit intoAOSSIE-Org:mainfrom
madhavansingh:feat/template-setup-script

Conversation

@madhavansingh
Copy link

@madhavansingh madhavansingh commented Mar 16, 2026

Addressed Issues:

Fixes #102


Description

This PR introduces an automated template initialization script (setup.js) to improve the usability of the repository and eliminate manual placeholder replacement.

Key Features

  • Interactive CLI for project setup:
    • Prompts for project name, description, and tech stack
  • Automatic replacement of placeholders:
    • Replaces TODO: Project Name and TODO: Project Description across files
  • Multi-file support:
    • Processes README.md and CONTRIBUTING.md
  • Dry-run mode:
    • Allows preview using node setup.js --dry-run
  • Backup system:
    • Creates .bak files before modifying original files
  • Idempotent behavior:
    • Skips files that are already initialized
  • Validation step:
    • Detects remaining placeholders after execution
  • Structured logging:
    • Clear [INFO], [SUCCESS], [WARNING], [ERROR] logs

Usage

Run:
node setup.js

Dry run:
node setup.js --dry-run


Additional Notes:

  • Uses only built-in Node.js modules (fs, readline, path)
  • Designed to be simple, extensible, and safe (with confirmation + backup)
  • Improves developer onboarding and reduces manual setup effort

This contribution is part of my preparation for GSoC 2026.


Checklist

  • My code follows the project's code style and conventions
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contributing Guidelines

Summary by CodeRabbit

  • New Features
    • Interactive project setup process with guided configuration for project name and description
    • Tech stack selection between Node.js and Python
    • Dry-run mode to preview changes before applying them
    • Automatic backup creation for modified template files
    • Post-setup guidance tailored to your selected technology stack
    • Input validation to ensure all required project details are provided

@github-actions github-actions bot added enhancement New feature or request javascript JavaScript/TypeScript code changes size/M Medium PR (51-200 lines changed) first-time-contributor First PR of an external contributor pending-coderabbit-review labels Mar 16, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 16, 2026

Walkthrough

A new Node.js script setup.js is introduced to automate template initialization. It interactively prompts for project name, description, and tech stack; validates inputs; replaces TODO placeholders in template files; creates backups; supports dry-run mode; and verifies successful completion with exit codes.

Changes

Cohort / File(s) Summary
Setup Initialization Script
setup.js
New 195-line Node.js script for automated template initialization featuring interactive prompts with colored logging, placeholder validation and replacement, backup file creation, dry-run mode support, pre-execution confirmation, post-execution guidance, and completion validation with exit codes.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant setup.js as Setup Script
    participant FileSystem as File System
    participant TemplateFiles as Template Files<br/>(README.md, CONTRIBUTING.md)

    User->>setup.js: Run node setup.js
    setup.js->>User: Prompt for project name
    User->>setup.js: Provide project name
    setup.js->>User: Prompt for project description
    User->>setup.js: Provide description
    setup.js->>User: Prompt for tech stack
    User->>setup.js: Select tech stack
    setup.js->>User: Display summary & request confirmation
    User->>setup.js: Confirm changes
    
    setup.js->>FileSystem: Read README.md
    FileSystem-->>setup.js: File content
    alt Placeholders found
        setup.js->>FileSystem: Create .bak backup
        FileSystem-->>setup.js: Backup created
        setup.js->>setup.js: Replace placeholders with values
        setup.js->>FileSystem: Write updated content
        FileSystem-->>setup.js: Write complete
    end
    
    setup.js->>FileSystem: Read CONTRIBUTING.md
    FileSystem-->>setup.js: File content
    alt Placeholders found
        setup.js->>FileSystem: Create .bak backup
        FileSystem-->>setup.js: Backup created
        setup.js->>setup.js: Replace placeholders with values
        setup.js->>FileSystem: Write updated content
        FileSystem-->>setup.js: Write complete
    end
    
    setup.js->>TemplateFiles: Scan for remaining placeholders
    TemplateFiles-->>setup.js: Validation results
    alt No placeholders remain
        setup.js->>User: Print success & setup guidance
    else Placeholders still present
        setup.js->>User: Print warnings
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested labels

Typescript Lang

Poem

🐰 A script hops forth with prompt and cheer,
Replacing TODOs far and near,
With backups safe and dry-run care,
Template setup beyond compare!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add automated template initialization script' directly and clearly summarizes the main change: introduction of a new setup script for template initialization.
Linked Issues check ✅ Passed The PR fully implements the primary objectives from issue #102: interactive prompts for project details, automatic placeholder replacement in README.md and CONTRIBUTING.md, validation to ensure no TODO placeholders remain, and error handling with structured logging.
Out of Scope Changes check ✅ Passed All changes in setup.js are directly scoped to the automation requirements in issue #102; no unrelated modifications or feature creep are present in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@madhavansingh
Copy link
Author

Hi @Zahnentferner

I have implemented the automated template initialization script as discussed in Issue #102.

Summary:

  • Added setup.js for interactive project configuration
  • Replaces TODO placeholders automatically
  • Supports dry-run mode for safe preview
  • Includes backup system and validation checks

I have tested the script locally and ensured it works as expected.

Would appreciate your feedback and suggestions. Thanks!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@setup.js`:
- Around line 15-20: Replace the current log.error implementation so errors are
written to stderr instead of stdout: update the log object (symbol: log) and
specifically the error method (log.error) to call console.error with the same
formatted message rather than console.log; keep the ANSI coloring and message
format unchanged so other methods (info, success, warning) remain intact.
- Line 195: The call to main() should chain a .catch() to handle any unhandled
promise rejections—update the invocation of main() so that it appends .catch(err
=> { processLogger.error("Unhandled error in main", err); process.exit(1); })
(or use console.error if processLogger is not available) to log the error and
exit with a non-zero code; reference the existing main() invocation to apply
this defensive handler.
- Around line 61-66: The replacePlaceholders function is vulnerable because
String.replace treats $-patterns in the replacement string; change both .replace
calls to use a replacement function (e.g., .replace(/TODO:\s*Project\s*Name/gi,
() => data.projectName) and .replace(/TODO:\s*Project\s*Description/gi, () =>
data.projectDescription)) so user-provided projectName/projectDescription are
inserted literally and special $ sequences are not interpreted.
- Around line 137-142: The techStack value collected by promptUser is passed
into processFile but never used by replacePlaceholders, so update
replacePlaceholders to accept and apply tech-stack-specific replacements (e.g.,
replace tokens like {{techStack}} or {{isNode}}/{{isPython}}) or remove passing
techStack from processFile and the prompt; specifically, modify
replacePlaceholders(signature and implementation) to take a third parameter
techStack and perform substitution logic for {{techStack}} (and any conditional
tokens used for guidance), then ensure processFile calls
replacePlaceholders(projectName, projectDescription, techStack) and that any
template placeholders referenced in the repo match these token names.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 446b78cb-56a3-409e-8eb5-663044227cc4

📥 Commits

Reviewing files that changed from the base of the PR and between b586b0c and 0580e6a.

📒 Files selected for processing (1)
  • setup.js

Comment on lines +15 to +20
const log = {
info: (msg) => console.log(`\x1b[36m[INFO]\x1b[0m ${msg}`),
success: (msg) => console.log(`\x1b[32m[SUCCESS]\x1b[0m ${msg}`),
warning: (msg) => console.log(`\x1b[33m[WARNING]\x1b[0m ${msg}`),
error: (msg) => console.log(`\x1b[31m[ERROR]\x1b[0m ${msg}`)
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Use console.error for error logging.

Error messages should be written to stderr, not stdout. This follows Node.js conventions and allows proper stream separation when piping output.

♻️ Suggested fix
 const log = {
     info: (msg) => console.log(`\x1b[36m[INFO]\x1b[0m ${msg}`),
     success: (msg) => console.log(`\x1b[32m[SUCCESS]\x1b[0m ${msg}`),
-    warning: (msg) => console.log(`\x1b[33m[WARNING]\x1b[0m ${msg}`),
-    error: (msg) => console.log(`\x1b[31m[ERROR]\x1b[0m ${msg}`)
+    warning: (msg) => console.warn(`\x1b[33m[WARNING]\x1b[0m ${msg}`),
+    error: (msg) => console.error(`\x1b[31m[ERROR]\x1b[0m ${msg}`)
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const log = {
info: (msg) => console.log(`\x1b[36m[INFO]\x1b[0m ${msg}`),
success: (msg) => console.log(`\x1b[32m[SUCCESS]\x1b[0m ${msg}`),
warning: (msg) => console.log(`\x1b[33m[WARNING]\x1b[0m ${msg}`),
error: (msg) => console.log(`\x1b[31m[ERROR]\x1b[0m ${msg}`)
};
const log = {
info: (msg) => console.log(`\x1b[36m[INFO]\x1b[0m ${msg}`),
success: (msg) => console.log(`\x1b[32m[SUCCESS]\x1b[0m ${msg}`),
warning: (msg) => console.warn(`\x1b[33m[WARNING]\x1b[0m ${msg}`),
error: (msg) => console.error(`\x1b[31m[ERROR]\x1b[0m ${msg}`)
};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@setup.js` around lines 15 - 20, Replace the current log.error implementation
so errors are written to stderr instead of stdout: update the log object
(symbol: log) and specifically the error method (log.error) to call
console.error with the same formatted message rather than console.log; keep the
ANSI coloring and message format unchanged so other methods (info, success,
warning) remain intact.

Comment on lines +61 to +66
const replacePlaceholders = (content, data) => {
let newContent = content;
newContent = newContent.replace(/TODO:\s*Project\s*Name/gi, data.projectName);
newContent = newContent.replace(/TODO:\s*Project\s*Description/gi, data.projectDescription);
return newContent;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

User input may contain special replacement patterns causing unexpected output.

In JavaScript's String.replace(), the replacement string interprets special patterns like $& (matched substring), $' (portion after match), $` (portion before match), and $$ (literal $). If a user enters a project name or description containing these patterns, the replacement will produce incorrect results.

Example: If user enters "My $& Project" as the name, the output would be "My TODO: Project Name Project".

🐛 Proposed fix using replacement function
 const replacePlaceholders = (content, data) => {
     let newContent = content;
-    newContent = newContent.replace(/TODO:\s*Project\s*Name/gi, data.projectName);
-    newContent = newContent.replace(/TODO:\s*Project\s*Description/gi, data.projectDescription);
+    newContent = newContent.replace(/TODO:\s*Project\s*Name/gi, () => data.projectName);
+    newContent = newContent.replace(/TODO:\s*Project\s*Description/gi, () => data.projectDescription);
     return newContent;
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@setup.js` around lines 61 - 66, The replacePlaceholders function is
vulnerable because String.replace treats $-patterns in the replacement string;
change both .replace calls to use a replacement function (e.g.,
.replace(/TODO:\s*Project\s*Name/gi, () => data.projectName) and
.replace(/TODO:\s*Project\s*Description/gi, () => data.projectDescription)) so
user-provided projectName/projectDescription are inserted literally and special
$ sequences are not interpreted.

Comment on lines +137 to +142
let techStack;
while (true) {
techStack = (await promptUser('Enter tech stack (node/python)')).toLowerCase();
if (techStack === 'node' || techStack === 'python') break;
log.error('Invalid choice. Please enter either "node" or "python".');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if template files contain any tech stack related placeholders
rg -i "TODO.*tech|TODO.*stack" README.md CONTRIBUTING.md 2>/dev/null || echo "No tech stack placeholders found"

Repository: AOSSIE-Org/Template-Repo

Length of output: 100


🏁 Script executed:

# Find all template files and search for placeholders more broadly
find . -type f \( -name "*.template" -o -name "*.tmpl" -o -name "*.hbs" \) | head -20

Repository: AOSSIE-Org/Template-Repo

Length of output: 50


🏁 Script executed:

# Search for placeholder patterns across the entire codebase
rg -E "{{|TODO|FIXME|\$\{" --type-list | head -5 && rg -E "{{|TODO|FIXME" . --max-count=20 2>/dev/null | head -30

Repository: AOSSIE-Org/Template-Repo

Length of output: 177


🏁 Script executed:

# Read setup.js around the techStack usage lines to understand its purpose
cat -n setup.js | sed -n '130,180p'

Repository: AOSSIE-Org/Template-Repo

Length of output: 2409


🏁 Script executed:

# Find and read the processFile function
rg -n "function processFile|const processFile|processFile\s*=" setup.js -A 30

Repository: AOSSIE-Org/Template-Repo

Length of output: 1132


🏁 Script executed:

# Also search for any placeholder patterns in actual template files or content files
find . -type f \( -name "*.md" -o -name "*.json" -o -name "*.txt" \) -exec grep -l "projectName\|projectDescription\|techStack" {} \; 2>/dev/null | head -20

Repository: AOSSIE-Org/Template-Repo

Length of output: 50


🏁 Script executed:

# Find and read the replacePlaceholders function
rg -n "function replacePlaceholders|const replacePlaceholders|replacePlaceholders\s*=" setup.js -A 30

Repository: AOSSIE-Org/Template-Repo

Length of output: 1241


🏁 Script executed:

# Check FILES_TO_PROCESS to see which files are actually being modified
rg -n "FILES_TO_PROCESS" setup.js -B 5 -A 5

Repository: AOSSIE-Org/Template-Repo

Length of output: 1711


Tech stack input is collected but not used in placeholder replacement.

The techStack value is passed to processFile() but the replacePlaceholders() function only processes projectName and projectDescription placeholders. It ignores the techStack parameter entirely, using the value only for conditional guidance messages (lines 170-174). Either remove the unnecessary techStack collection, or extend replacePlaceholders() to support tech-stack-specific placeholders if that's intended.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@setup.js` around lines 137 - 142, The techStack value collected by promptUser
is passed into processFile but never used by replacePlaceholders, so update
replacePlaceholders to accept and apply tech-stack-specific replacements (e.g.,
replace tokens like {{techStack}} or {{isNode}}/{{isPython}}) or remove passing
techStack from processFile and the prompt; specifically, modify
replacePlaceholders(signature and implementation) to take a third parameter
techStack and perform substitution logic for {{techStack}} (and any conditional
tokens used for guidance), then ensure processFile calls
replacePlaceholders(projectName, projectDescription, techStack) and that any
template placeholders referenced in the repo match these token names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request first-time-contributor First PR of an external contributor javascript JavaScript/TypeScript code changes pending-coderabbit-review size/M Medium PR (51-200 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add automated template initialization script to replace placeholders and streamline project setup

1 participant