# Contributing to create-tempi-app

## Cài đặt phát triển

### Yêu cầu tiền đề
- Node.js (version >= `20.9.0`)
- npm (preferred) or yarn
- Git

### Các bước setup
1. Clone repository:
```bash
git clone git@git.teko.vn:sale-channels/ecommerce-website/create-tempi-app.git
cd create-tempi-app
```
1. Cài đặt dependencies:
```bash
npm install
```

1. Link package để test local:
```bash
npm link
```

## Cấu trúc project

```
create-tempi-app/
├── templates/          # Submodule từ tempi-boilerplate
├── index.js            # Entry point của CLI
├── package.json        # Package configuration
└── .gitlab-ci.yml      # CI/CD configuration
```

## Scripts

- `npm run sync-templates` - Pull code mới nhất từ tempi-boilerplate submodule
- `npm run release` - Release phiên bản mới (chạy tự động qua CI)
  - Trong GitlabCI sẽ yêu cầu:
    - GL_TOKEN để push code lên repository
    - NPM_TOKEN để publish package

## Quy trình phát triển

1. **Branch**
   - Tạo branch mới từ `master`
   - Format branch name: `feat/name` hoặc `fix/name`

2. **Development**
   - Pull code mới nhất từ submodule: `npm run sync-templates`
   - Test local bằng `npm link`
   - Test tạo project mới: `npx create-tempi-app@latest my-app`

3. **Commit**
   Sử dụng conventional commits để tự động versioning:
   - `feat: new feature`
   - `fix: bug fix`
   - `chore: maintenance`
   - `docs: documentation`

4. **Testing**
   - Test local trước khi push
   - Verify project structure được tạo ra
   - Kiểm tra dependencies installation

5. **Release**
   - Merge vào master
   - CI/CD sẽ tự động:
     - Sync submodules
     - Run tests
     - Publish to npm

## Quản lý Submodule

### Cập nhật Submodule
```bash
# Pull code mới từ remote
git submodule update --remote --merge

# Commit changes
git add templates
git commit -m "chore: update templates"
```

### Troubleshooting Submodule

Nếu gặp vấn đề với submodule:
```bash
# Reset submodule
git submodule deinit -f templates
git submodule update --init

# Verify status
git submodule status
```

## CI/CD

Pipeline sẽ tự động:
1. Sync submodules
2. Release version mới (nếu có changes)
3. Publish to npm registry

## Quy tắc phát triển

1. **Code Style**
   - Sử dụng ES6+ features
   - Đảm bảo backward compatibility
   - Comment code khi cần thiết

2. **Documentation**
   - Update README.md nếu có thay đổi về usage
   - Update CHANGELOG.md qua conventional commits

3. **Testing**
   - Test trên Node.js phiên bản mới nhất
   - Verify project structure
   - Test npm installation
