@cbs-consulting/generator-btp 1.2.10 → 1.3.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.
package/README.md CHANGED
@@ -1,105 +1,284 @@
1
- # CAP/UI5 Foundation Generator
1
+ # CBS Best Practice Generator
2
2
 
3
- A Yeoman generator for creating the foundation of CAP/UI5 projects with TypeScript, ESLint, Prettier, and other essential development configurations.
3
+ A modular Yeoman generator for bootstrapping and enhancing SAP CAP and UI5 projects with industry best practices, including TypeScript, linting, formatting, dev containers, and Azure DevOps CI/CD configuration.
4
4
 
5
- ## Features
5
+ ## Overview
6
6
 
7
- This generator sets up a solid foundation for your CAP/UI5 projects with:
7
+ This generator provides a suite of modular sub-generators that can be used together or independently:
8
8
 
9
- - **TypeScript** - Full TypeScript configuration with strict settings
10
- - **ESLint** - Code quality and linting rules optimized for TypeScript
11
- - **Prettier** - Consistent code formatting
12
- - **Husky** - Git hooks for pre-commit quality checks
13
- - **Jest** - Testing framework with TypeScript support
14
- - ✅ **GitHub Actions** - CI/CD pipeline for automated testing and building
15
- - ✅ **VS Code** - Optimized settings and recommended extensions
16
- - ✅ **Docker** - Container configuration for deployment (optional)
9
+ - 🎯 **Main Entry Point** - Interactive menu to select which generator to run
10
+ - 🚀 **CAP Generator** - Complete CAP project setup with TypeScript, MTA, dev container, and optional Azure DevOps
11
+ - 🎨 **UI5 Generator** - Add best practices to existing UI5 applications (ESLint, UI5lint, TypeScript)
12
+ - 🐳 **Devcontainer Generator** - VS Code dev container for consistent development environments
13
+ - ☁️ **Azure DevOps Setup** - Automated scripts for configuring branch policies, merge strategies, and CI/CD pipelines
14
+
15
+ ## Prerequisites
16
+
17
+ The **CAP generator** requires [`@sap/cds-dk`](https://www.npmjs.com/package/@sap/cds-dk) to be installed globally, as it invokes `cds init` directly during execution:
18
+
19
+ ```bash
20
+ npm install -g @sap/cds-dk
21
+ ```
17
22
 
18
23
  ## Installation
19
24
 
20
- First, install Yeoman and this generator globally:
25
+ Install Yeoman and this generator globally:
21
26
 
22
27
  ```bash
23
- npm install -g yo
24
- npm install -g @cbs-consulting/generator-btp
28
+ npm install -g yo @cbs-consulting/generator-btp
25
29
  ```
26
30
 
27
- Or install locally in your project:
31
+ Or install as a dev dependency:
28
32
 
29
33
  ```bash
30
- npm install --save-dev @cbs-consulting/generator-btp
34
+ npm install --save-dev yo @cbs-consulting/generator-btp
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ### Interactive Mode (Recommended)
40
+
41
+ Run the generator and select from the menu:
42
+
43
+ ```bash
44
+ yo @cbs-consulting/btp
45
+ ```
46
+
47
+ ### Direct Generator Access
48
+
49
+ Invoke specific generators directly:
50
+
51
+ ```bash
52
+ # Bootstrap a new CAP project (includes devcontainer + optional Azure DevOps)
53
+ yo @cbs-consulting/btp:cap
54
+
55
+ # Add best practices to existing UI5 apps
56
+ yo @cbs-consulting/btp:ui5
57
+
58
+ # Add devcontainer only
59
+ yo @cbs-consulting/btp:devcontainer
60
+
61
+ # Add Azure DevOps setup scripts only
62
+ yo @cbs-consulting/btp:setup-azure-devops
31
63
  ```
32
64
 
33
- ## Usage
65
+ ## Generators
66
+
67
+ ### 🚀 CAP Generator
68
+
69
+ **Purpose**: Bootstrap a complete CAP project with all best practices.
70
+
71
+ > **Requires** `@sap/cds-dk` installed globally (`npm install -g @sap/cds-dk`).
34
72
 
35
- This generator is split into two sub-generators.
73
+ **What it does**:
36
74
 
37
- 1. CAP flow
75
+ - Runs `cds init` with TypeScript, MTA, XSUAA, HANA, and sample content
76
+ - Configures ESLint and Prettier (using [@cbs-consulting/tools](https://www.npmjs.com/package/@cbs-consulting/tools))
77
+ - Sets up git workflows with advanced aliases (ticket-based branches, PR automation)
78
+ - Adds pre-commit hooks (linting, formatting) with simple-git-hooks
79
+ - Generates MTA deployment descriptors with environment-specific extensions (dev/test/prod)
80
+ - Configures VS Code with 30+ recommended extensions
81
+ - **Includes devcontainer generator** (always)
82
+ - **Includes setup-azure-devops generator** (optional, if selected)
83
+
84
+ **Key files added**:
85
+
86
+ - `.gitignore`, `.gitconfig.aliases`, `.gitattributes`, `.npmrc`
87
+ - `eslint.config.mjs`, `prettier.config.mjs`
88
+ - `mta.yaml` + `mta-ext/{dev,test,prod}.mtaext`
89
+ - `azure-pipelines.yaml` (if Azure DevOps enabled)
90
+ - `.devcontainer/` folder
91
+ - `scripts/setup-azure-devops/` folder (if Azure DevOps enabled)
92
+
93
+ **Usage**:
38
94
 
39
95
  ```bash
40
- mkdir my-cap
41
- cd my-cap
96
+ mkdir my-cap-project
97
+ cd my-cap-project
42
98
  yo @cbs-consulting/btp:cap
43
- # read and execute the printed steps shown in the terminal
44
99
  ```
45
100
 
46
- 2. UI5 flow
101
+ ---
102
+
103
+ ### 🎨 UI5 Generator
104
+
105
+ **Purpose**: Add best practices to existing UI5 applications.
106
+
107
+ **What it does**:
108
+
109
+ - Auto-detects UI5 apps in the `app/` folder (by finding `ui5.yaml`)
110
+ - Adds ESLint and UI5lint configurations per app
111
+ - Configures TypeScript to work with CAP-generated models
112
+ - Adds npm scripts for linting and UI5-specific linting
113
+
114
+ **Key files added** (per app):
115
+
116
+ - `eslint.config.mjs`, `ui5lint.config.mjs`
117
+ - Updates `package.json` and `tsconfig.json`
118
+
119
+ **Usage**:
47
120
 
48
121
  ```bash
49
- mkdir my-ui5
50
- cd my-ui5
51
- # ensure you have a UI5 project skeleton (or after cds init)
122
+ # Run from CAP project root with app/ folder
52
123
  yo @cbs-consulting/btp:ui5
53
- # read and execute the printed steps in the terminal
54
124
  ```
55
125
 
56
- The CAP sub-generator copies all templates from generators/app/templatesCAP into your project and merges additions from generators/app/additionsCAP into existing files. The scripting.txt is shown but not executed automatically.
126
+ ---
127
+
128
+ ### 🐳 Devcontainer Generator
129
+
130
+ **Purpose**: Set up VS Code dev container for consistent development environments.
131
+
132
+ **What it does**:
133
+
134
+ - Creates `.devcontainer/` configuration using CBS Docker image
135
+ - Pre-configures 30+ VS Code extensions
136
+ - Auto-installs Cloud Foundry and Azure DevOps CLI tools on container creation
137
+ - Provides isolated, reproducible development environment
138
+
139
+ **Key files added**:
140
+
141
+ - `.devcontainer/devcontainer.json`
142
+ - `.devcontainer/Dockerfile`
143
+ - `.devcontainer/post-create.sh`
144
+
145
+ **Usage**:
146
+
147
+ ```bash
148
+ yo @cbs-consulting/btp:devcontainer
149
+ ```
150
+
151
+ **Note**: This generator is automatically included when using the CAP generator.
152
+
153
+ ---
154
+
155
+ ### ☁️ Azure DevOps Setup Generator
156
+
157
+ **Purpose**: Create automation scripts for Azure DevOps branch policies and CI/CD pipelines.
57
158
 
58
- ## Generated Project Structure
159
+ **What it does**:
59
160
 
161
+ - Generates bash script to automate Azure DevOps configuration
162
+ - Creates `main` and `development` branches with policies
163
+ - Configures code review requirements, merge strategies, and build validation
164
+ - Sets up Azure Pipeline from `azure-pipelines.yaml`
165
+
166
+ **Key files added**:
167
+
168
+ - `scripts/setup-azure-devops/setup.sh` (automation script)
169
+ - `scripts/setup-azure-devops/azure-devops.env` (configuration variables)
170
+ - `scripts/setup-azure-devops/README.md` (detailed documentation)
171
+
172
+ **Usage**:
173
+
174
+ ```bash
175
+ yo @cbs-consulting/btp:setup-azure-devops
176
+ # Then run: bash scripts/setup-azure-devops/setup.sh
60
177
  ```
61
- my-project/
62
- ├── src/ # Source TypeScript files
63
- ├── tests/ # Test files (if Jest is selected)
64
- ├── dist/ # Compiled output (after build)
65
- ├── .github/workflows/ # GitHub Actions CI/CD (if selected)
66
- ├── .vscode/ # VS Code settings (if selected)
67
- ├── .eslintrc.js # ESLint configuration
68
- ├── .prettierrc # Prettier configuration
69
- ├── .gitignore # Git ignore rules
70
- ├── tsconfig.json # TypeScript configuration
71
- ├── jest.config.js # Jest configuration (if selected)
72
- ├── package.json # Project dependencies and scripts
73
- └── README.md # Project documentation
178
+
179
+ **Note**: This generator is automatically included when using the CAP generator with Azure DevOps enabled.
180
+
181
+ ---
182
+
183
+ ## Generated Project Structure (CAP)
184
+
185
+ When using the CAP generator, your project will include:
186
+
187
+ ``` tree
188
+ my-cap-project/
189
+ ├── .devcontainer/ # Dev container configuration
190
+ │ ├── devcontainer.json
191
+ │ ├── Dockerfile
192
+ │ └── post-create.sh
193
+ ├── .vscode/ # VS Code settings & extensions
194
+ │ ├── settings.json
195
+ │ └── extensions.json
196
+ ├── app/ # UI5 applications (from cds init)
197
+ ├── db/ # Database models (from cds init)
198
+ ├── srv/ # Service definitions (from cds init)
199
+ ├── mta-ext/ # MTA extensions for environments
200
+ │ ├── dev.mtaext
201
+ │ ├── test.mtaext
202
+ │ └── prod.mtaext
203
+ ├── scripts/ # Automation scripts
204
+ │ └── setup-azure-devops/ # Azure DevOps setup (if enabled)
205
+ │ ├── setup.sh
206
+ │ ├── azure-devops.env
207
+ │ └── README.md
208
+ ├── .gitignore # Comprehensive ignore patterns
209
+ ├── .gitconfig.aliases # Git workflow aliases
210
+ ├── .gitattributes # Line ending configuration
211
+ ├── .npmrc # npm settings
212
+ ├── azure-pipelines.yaml # CI/CD pipeline (if enabled)
213
+ ├── tsconfig.json # Project TypeScript config
214
+ ├── eslint.config.mjs # ESLint configuration
215
+ ├── prettier.config.mjs # Prettier configuration
216
+ ├── mta.yaml # MTA deployment descriptor
217
+ └── package.json # Dependencies and scripts
74
218
  ```
75
219
 
76
220
  ## Available Scripts
77
221
 
78
- The generated project includes these npm scripts:
222
+ The CAP generator adds these npm scripts:
223
+
224
+ **Code Quality**:
79
225
 
80
- - `npm run build` - Compile TypeScript to JavaScript
81
- - `npm run build:watch` - Watch mode compilation
82
- - `npm run lint` - Run ESLint on your code
83
- - `npm run lint:fix` - Fix auto-fixable ESLint issues
84
226
  - `npm run format` - Format code with Prettier
85
227
  - `npm run format:check` - Check if code is properly formatted
86
- - `npm test` - Run Jest tests (if enabled)
87
- - `npm run test:watch` - Run tests in watch mode
88
- - `npm run test:coverage` - Generate test coverage report
228
+ - `npm run lint` - Run ESLint
229
+ - `npm run lint:fix` - Fix auto-fixable ESLint issues
230
+
231
+ **Testing & Building**:
232
+
233
+ - `npm test` - Run tests
234
+ - `npm run build` - Build TypeScript
235
+ - `npm run coverage-report` - Generate test coverage report
236
+
237
+ **Deployment**:
238
+
239
+ - `npm run build:mta` - Build MTA archive
240
+ - `npm run deploy-dev` - Deploy to dev environment
241
+
242
+ **Utilities**:
243
+
244
+ - `npm run git-config` - Set up git aliases
245
+ - `npm run check-deps` - Check for outdated dependencies
246
+ - `npm run upgrade-deps` - Upgrade dependencies (minor versions)
247
+
248
+ **Git Hooks**:
249
+
250
+ - Pre-commit hook automatically runs linting and formatting on staged files
251
+
252
+ ## Key Features
253
+
254
+ - ✅ **TypeScript-first** with strict compiler settings
255
+ - ✅ **Code quality** enforced via ESLint, Prettier, and pre-commit hooks
256
+ - ✅ **Git workflows** with advanced aliases for ticket-based development
257
+ - ✅ **MTA deployment** with environment-specific configurations
258
+ - ✅ **Dev containers** for reproducible development environments
259
+ - ✅ **Azure DevOps** automation for branch policies and CI/CD
260
+ - ✅ **VS Code optimized** with 30+ recommended extensions
261
+ - ✅ **UI5 linting** with @ui5/linter integration
262
+ - ✅ **Centralized configs** via @cbs-consulting/tools package
89
263
 
90
264
  ## Development
91
265
 
92
266
  To develop this generator locally:
93
267
 
94
- 1. Clone this repository
95
- 2. Install dependencies: `npm install`
96
- 3. Link the generator: `npm link`
97
- 4. Test in a new directory: `yo @cbs-consulting/btp`
268
+ ```bash
269
+ git clone <repository-url>
270
+ cd generator-btp
271
+ npm install
272
+ npm link
273
+ yo @cbs-consulting/btp
274
+ ```
275
+
276
+ Run tests:
98
277
 
99
- ## Contributing
278
+ ```bash
279
+ npm test
280
+ npm run test:watch
281
+ npm run test:coverage
282
+ ```
100
283
 
101
- 1. Fork the repository
102
- 2. Create a feature branch
103
- 3. Make your changes
104
- 4. Add tests if applicable
105
- 5. Submit a pull request
284
+ See [DEVELOPMENT.md](DEVELOPMENT.md) for more details.
@@ -19,6 +19,25 @@ describe("generator-btp:app", () => {
19
19
  .run(join(__dirname, "../index.js"))
20
20
  .withPrompts({
21
21
  kind: "cap",
22
+ // CAP generator prompts
23
+ projectName: "Test Project",
24
+ customerName: "Test Customer",
25
+ dbSchema: "TEST_SCHEMA",
26
+ useAzureDevOps: true,
27
+ azureRepoUrl:
28
+ "https://dev.azure.com/testorg/testproject/_git/test-repo",
29
+ useBestPractices: true,
30
+ cdsFeatures: [
31
+ "typescript",
32
+ "mta",
33
+ "xsuaa",
34
+ "hana",
35
+ "sqlite",
36
+ "html5-repo",
37
+ "tiny-sample",
38
+ "http",
39
+ "test",
40
+ ],
22
41
  })
23
42
  .withOptions({
24
43
  skipInstall: true,
@@ -98,18 +117,86 @@ describe("generator-btp:app", () => {
98
117
  });
99
118
  });
100
119
 
120
+ // ========================================
121
+ // Generator: setup-azure-devops
122
+ // ========================================
123
+ describe("when user selects setup-azure-devops", () => {
124
+ let runResult;
125
+
126
+ // Run the generator with setup-azure-devops selection
127
+ beforeAll(async () => {
128
+ runResult = await helpers
129
+ .run(join(__dirname, "../index.js"))
130
+ .withPrompts({
131
+ kind: "setup-azure-devops",
132
+ projectName: "Test Project",
133
+ azureRepoUrl:
134
+ "https://dev.azure.com/testorg/testproject/_git/test-repo",
135
+ useBestPractices: true,
136
+ });
137
+ });
138
+
139
+ // Restore the environment after tests
140
+ afterAll(() => {
141
+ if (runResult) {
142
+ runResult.restore();
143
+ }
144
+ });
145
+
146
+ // Test that the correct generator is composed based on user selection
147
+ it("should compose with setup-azure-devops generator", () => {
148
+ expect(runResult.generator.kind).toBe("setup-azure-devops");
149
+ });
150
+ });
151
+
101
152
  // ========================================
102
153
  // Test all prompt choices
103
154
  // ========================================
104
155
  describe("prompting", () => {
105
- it.each(["cap", "ui5", "devcontainer"])(
156
+ it.each(["cap", "ui5", "devcontainer", "setup-azure-devops"])(
106
157
  "should accept '%s' as valid choice",
107
158
  async (choice) => {
159
+ const prompts = {
160
+ kind: choice,
161
+ };
162
+
163
+ // Add CAP-specific prompts
164
+ if (choice === "cap") {
165
+ Object.assign(prompts, {
166
+ projectName: "Test Project",
167
+ customerName: "Test Customer",
168
+ dbSchema: "TEST_SCHEMA",
169
+ useAzureDevOps: true,
170
+ azureRepoUrl:
171
+ "https://dev.azure.com/testorg/testproject/_git/test-repo",
172
+ useBestPractices: true,
173
+ cdsFeatures: [
174
+ "typescript",
175
+ "mta",
176
+ "xsuaa",
177
+ "hana",
178
+ "sqlite",
179
+ "html5-repo",
180
+ "tiny-sample",
181
+ "http",
182
+ "test",
183
+ ],
184
+ });
185
+ }
186
+
187
+ // Add setup-azure-devops-specific prompts
188
+ if (choice === "setup-azure-devops") {
189
+ Object.assign(prompts, {
190
+ projectName: "Test Project",
191
+ azureRepoUrl:
192
+ "https://dev.azure.com/testorg/testproject/_git/test-repo",
193
+ useBestPractices: true,
194
+ });
195
+ }
196
+
108
197
  const runResult = await helpers
109
198
  .run(join(__dirname, "../index.js"))
110
- .withPrompts({
111
- kind: choice,
112
- })
199
+ .withPrompts(prompts)
113
200
  .withOptions({
114
201
  skipInstall: true,
115
202
  })
@@ -33,6 +33,10 @@ export default class extends Generator {
33
33
  name: "Add devcontainer configuration",
34
34
  value: "devcontainer",
35
35
  },
36
+ {
37
+ name: "Setup Azure DevOps configuration",
38
+ value: "setup-azure-devops",
39
+ },
36
40
  ],
37
41
  },
38
42
  ]);
@@ -60,6 +64,13 @@ export default class extends Generator {
60
64
  Generator: DevcontainerGenerator,
61
65
  path: resolve(__dirname, "../devcontainer"),
62
66
  });
67
+ } else if (this.kind === "setup-azure-devops") {
68
+ const { default: SetupAzureDevOpsGenerator } =
69
+ await import("../setup-azure-devops/index.js");
70
+ this.composeWith({
71
+ Generator: SetupAzureDevOpsGenerator,
72
+ path: resolve(__dirname, "../setup-azure-devops"),
73
+ });
63
74
  } else {
64
75
  this.log(chalk.red("Unknown selection"));
65
76
  }