generate_template.sh
#!/bin/bash
VERSION="1.0"

set -e

TEMPLATE_DIR="$HOME/.createproj_templates"

echo "Creating project templates in $TEMPLATE_DIR ..."

mkdir -p "$TEMPLATE_DIR"

########### C TEMPLATE ###########
echo "Generating C template..."
mkdir -p "$TEMPLATE_DIR/c/includes" "$TEMPLATE_DIR/c/srcs" "$TEMPLATE_DIR/c/extLibs" "$TEMPLATE_DIR/c/obj"

cat > "$TEMPLATE_DIR/c/includes/includes.h" <<'EOF'
#ifndef INCLUDES_H
#define INCLUDES_H

// Put your standard includes here
#include <stdio.h>
#include <stdlib.h>

#endif
EOF

cat > "$TEMPLATE_DIR/c/includes/typedefs.h" <<'EOF'
#ifndef TYPEDEFS_H
#define TYPEDEFS_H

// Define your types here

#endif
EOF

cat > "$TEMPLATE_DIR/c/srcs/main.c" <<'EOF'
#include "../includes/includes.h"

int main(void)
{
    printf("Hello, C project!\n");
    return 0;
}
EOF

cat > "$TEMPLATE_DIR/c/Makefile" <<'EOF'
NAME = project_name

CC = gcc
CFLAGS = -Wall -Wextra -Werror -Iincludes

SRC_DIR = srcs
OBJ_DIR = obj

SRCS = $(wildcard $(SRC_DIR)/*.c)
OBJS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS))

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
	@mkdir -p $(OBJ_DIR)
	$(CC) $(CFLAGS) -c $< -o $@

all: $(NAME)

$(NAME): $(OBJS)
	$(CC) $(CFLAGS) -o $@ $^

clean:
	rm -rf $(OBJ_DIR)

fclean: clean
	rm -f $(NAME)

re: fclean all

.PHONY: all clean fclean re
EOF

cat > "$TEMPLATE_DIR/c/README.md" <<'EOF'
# project_name

This is a C project scaffold generated by createproj.
EOF

cat > "$TEMPLATE_DIR/c/.gitignore" <<'EOF'
obj/
*.o
*.out
*.a
*.dSYM/
project_name
EOF

########### PYTHON TEMPLATE ###########
echo "Generating Python template..."
mkdir -p "$TEMPLATE_DIR/python/project_name" "$TEMPLATE_DIR/python/tests"

cat > "$TEMPLATE_DIR/python/project_name/__init__.py" <<'EOF'
# Init file for python package
EOF

cat > "$TEMPLATE_DIR/python/project_name/main.py" <<'EOF'
def main():
    print("Hello, Python project!")

if __name__ == "__main__":
    main()
EOF

cat > "$TEMPLATE_DIR/python/tests/test_main.py" <<'EOF'
def test_example():
    assert True
EOF

cat > "$TEMPLATE_DIR/python/requirements.txt" <<'EOF'
# Add your dependencies here
EOF

cat > "$TEMPLATE_DIR/python/README.md" <<'EOF'
# project_name

This is a Python project scaffold generated by createproj.
EOF

cat > "$TEMPLATE_DIR/python/.gitignore" <<'EOF'
__pycache__/
*.pyc
*.pyo
.env
venv/
EOF

########### JAVASCRIPT TEMPLATE ###########
echo "Generating JavaScript template..."
mkdir -p "$TEMPLATE_DIR/js/lib"

cat > "$TEMPLATE_DIR/js/index.js" <<'EOF'
console.log("Hello, JavaScript project!");
EOF

cat > "$TEMPLATE_DIR/js/package.json" <<'EOF'
{
  "name": "project_name",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "license": "MIT"
}
EOF

cat > "$TEMPLATE_DIR/js/README.md" <<'EOF'
# project_name

This is a JavaScript (Node.js) project scaffold generated by createproj.
EOF

cat > "$TEMPLATE_DIR/js/.gitignore" <<'EOF'
node_modules/
.env
EOF

########### FRONTEND TEMPLATE ###########
echo "Generating Frontend template..."
mkdir -p "$TEMPLATE_DIR/frontend/assets"

cat > "$TEMPLATE_DIR/frontend/index.html" <<'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>project_name</title>
    <link rel="stylesheet" href="style.css" />
</head>
<body>
    <h1>Hello, Frontend project!</h1>
    <script src="script.js"></script>
</body>
</html>
EOF

cat > "$TEMPLATE_DIR/frontend/style.css" <<'EOF'
body {
    font-family: Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
}
EOF

cat > "$TEMPLATE_DIR/frontend/script.js" <<'EOF'
console.log("Hello, Frontend project!");
EOF

cat > "$TEMPLATE_DIR/frontend/README.md" <<'EOF'
# project_name

This is a Frontend project scaffold generated by createproj.
EOF

cat > "$TEMPLATE_DIR/frontend/.gitignore" <<'EOF'
.DS_Store
node_modules/
EOF

########### C++ TEMPLATE ###########
echo "Generating C++ template..."
mkdir -p "$TEMPLATE_DIR/cpp/include" "$TEMPLATE_DIR/cpp/src" "$TEMPLATE_DIR/cpp/build"

cat > "$TEMPLATE_DIR/cpp/include/includes.hpp" <<'EOF'
#ifndef INCLUDES_HPP
#define INCLUDES_HPP

#include <iostream>

#endif
EOF

cat > "$TEMPLATE_DIR/cpp/src/main.cpp" <<'EOF'
#include "../include/includes.hpp"

int main() {
    std::cout << "Hello, C++ project!" << std::endl;
    return 0;
}
EOF

cat > "$TEMPLATE_DIR/cpp/Makefile" <<'EOF'
NAME = project_name

CXX = g++
CXXFLAGS = -Wall -Wextra -Werror -Iinclude

SRC_DIR = src
OBJ_DIR = build

SRCS = $(wildcard $(SRC_DIR)/*.cpp)
OBJS = $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRCS))

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
	@mkdir -p $(OBJ_DIR)
	$(CXX) $(CXXFLAGS) -c $< -o $@

all: $(NAME)

$(NAME): $(OBJS)
	$(CXX) $(CXXFLAGS) -o $@ $^

clean:
	rm -rf $(OBJ_DIR)

fclean: clean
	rm -f $(NAME)

re: fclean all

.PHONY: all clean fclean re
EOF

cat > "$TEMPLATE_DIR/cpp/README.md" <<'EOF'
# project_name

This is a C++ project scaffold generated by createproj.
EOF

cat > "$TEMPLATE_DIR/cpp/.gitignore" <<'EOF'
build/
*.o
*.out
*.a
*.dSYM/
project_name
EOF

########### RUST TEMPLATE ###########
echo "Generating Rust template..."
mkdir -p "$TEMPLATE_DIR/rust/src"

cat > "$TEMPLATE_DIR/rust/Cargo.toml" <<'EOF'
[package]
name = "project_name"
version = "0.1.0"
edition = "2021"

[dependencies]
EOF

cat > "$TEMPLATE_DIR/rust/src/main.rs" <<'EOF'
fn main() {
    println!("Hello, Rust project!");
}
EOF

cat > "$TEMPLATE_DIR/rust/README.md" <<'EOF'
# project_name

This is a Rust project scaffold generated by createproj.
EOF

cat > "$TEMPLATE_DIR/rust/.gitignore" <<'EOF'
/target
**/*.rs.bk
Cargo.lock
EOF

########### GO TEMPLATE ###########
echo "Generating Go template..."
mkdir -p "$TEMPLATE_DIR/go"

cat > "$TEMPLATE_DIR/go/main.go" <<'EOF'
package main

import "fmt"

func main() {
    fmt.Println("Hello, Go project!")
}
EOF

cat > "$TEMPLATE_DIR/go/go.mod" <<EOF
module project_name

go 1.20
EOF

cat > "$TEMPLATE_DIR/go/README.md" <<'EOF'
# project_name

This is a Go project scaffold generated by createproj.
EOF

cat > "$TEMPLATE_DIR/go/.gitignore" <<'EOF'
/bin/
/obj/
/vendor/
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
EOF

echo "✅ Rust, C++, and Go templates generated."

echo "✅ All templates generated."
