Files
troupe-standup/wizard-work/spark/new-node-project.sh
T

123 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# new-node-project.sh - Scaffold a new Node.js project with best practices
# Usage: ./new-node-project.sh <project-name>
set -e
if [ -z "$1" ]; then
echo "Error: Project name required"
echo "Usage: $0 <project-name>"
exit 1
fi
PROJECT_NAME="$1"
if [ -d "$PROJECT_NAME" ]; then
echo "Error: Directory '$PROJECT_NAME' already exists"
exit 1
fi
echo "Creating Node.js project: $PROJECT_NAME"
mkdir -p "$PROJECT_NAME"
cd "$PROJECT_NAME"
cat > package.json << 'EOF'
{
"name": "PROJECT_NAME_PLACEHOLDER",
"version": "1.0.0",
"description": "A new Node.js project",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "jest",
"dev": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"jest": "^29.0.0",
"nodemon": "^3.0.0"
}
}
EOF
sed -i "s/PROJECT_NAME_PLACEHOLDER/$PROJECT_NAME/g" package.json
cat > index.js << 'EOF'
#!/usr/bin/env node
/**
* Main entry point for PROJECT_NAME_PLACEHOLDER
*/
console.log('Hello from PROJECT_NAME_PLACEHOLDER!');
module.exports = {
greet: (name) => `Hello, ${name}!`
};
EOF
sed -i "s/PROJECT_NAME_PLACEHOLDER/$PROJECT_NAME/g" index.js
cat > .gitignore << 'EOF'
node_modules/
.env
.DS_Store
*.log
npm-debug.log*
EOF
mkdir -p src test
touch src/index.js
touch test/index.test.js
cat > test/index.test.js << 'EOF'
const { greet } = require('../index');
describe('greet', () => {
test('returns greeting with name', () => {
expect(greet('World')).toBe('Hello, World!');
});
});
EOF
cat > README.md << 'EOF'
# PROJECT_NAME_PLACEHOLDER
A Node.js project.
## Setup
\`\`\`bash
npm install
\`\`\`
## Usage
\`\`\`bash
npm start
\`\`\`
## Development
\`\`\`bash
npm run dev
\`\`\`
## Testing
\`\`\`bash
npm test
\`\`\`
EOF
sed -i "s/PROJECT_NAME_PLACEHOLDER/$PROJECT_NAME/g" README.md
echo ""
echo "Project '$PROJECT_NAME' created successfully!"
echo "Next steps:"
echo " 1. cd $PROJECT_NAME"
echo " 2. npm install"
echo " 3. npm start"