@gracefullight/validate-branch 1.0.1 → 1.1.1
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.ko.md +470 -0
- package/README.md +131 -131
- package/dist/cli.js +41 -41
- package/dist/index.js +40 -40
- package/package.json +36 -19
- package/README.en.md +0 -470
package/README.md
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
1
|
# @gracefullight/validate-branch
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Git branch name validation tool with custom regexp support
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@gracefullight/validate-branch)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
**English** | [한국어](./README.ko.md)
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Features
|
|
11
11
|
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- **CLI
|
|
16
|
-
-
|
|
17
|
-
-
|
|
12
|
+
- **Flexible Regular Expression Pattern** - Use default pattern or custom regular expression
|
|
13
|
+
- **Current Branch Detection** - Automatically detect current branch name from Git repository
|
|
14
|
+
- **Config File Support** - Load patterns from `branch.config.{ts,js,mjs}` files
|
|
15
|
+
- **CLI Tool** - Use directly from command line
|
|
16
|
+
- **Detailed Error Messages** - Clear error descriptions on validation failure
|
|
17
|
+
- **Full TypeScript Support** - Complete TypeScript type definitions
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## Default Pattern
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
By default, the following branch names are allowed:
|
|
22
22
|
|
|
23
|
-
- `main` / `master` -
|
|
24
|
-
- `develop` / `stage` -
|
|
25
|
-
- `feature/.*` -
|
|
26
|
-
- `fix/.*` -
|
|
27
|
-
- `hotfix/.*` -
|
|
28
|
-
- `release/.*` -
|
|
23
|
+
- `main` / `master` - Main branches
|
|
24
|
+
- `develop` / `stage` - Development/staging branches
|
|
25
|
+
- `feature/.*` - Feature branches (e.g., `feature/login`, `feature/user-auth`)
|
|
26
|
+
- `fix/.*` - Bug fix branches (e.g., `fix/memory-leak`, `fix/typo`)
|
|
27
|
+
- `hotfix/.*` - Hotfix branches (e.g., `hotfix/critical-bug`)
|
|
28
|
+
- `release/.*` - Release branches (e.g., `release/v1.0.0`)
|
|
29
29
|
|
|
30
|
-
##
|
|
30
|
+
## Installation
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
|
-
# pnpm
|
|
33
|
+
# Using pnpm
|
|
34
34
|
pnpm add @gracefullight/validate-branch
|
|
35
35
|
|
|
36
|
-
# npm
|
|
36
|
+
# Using npm
|
|
37
37
|
npm install @gracefullight/validate-branch
|
|
38
38
|
|
|
39
|
-
# yarn
|
|
39
|
+
# Using yarn
|
|
40
40
|
yarn add @gracefullight/validate-branch
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## Usage
|
|
44
44
|
|
|
45
|
-
### CLI
|
|
45
|
+
### CLI Usage
|
|
46
46
|
|
|
47
47
|
```bash
|
|
48
|
-
#
|
|
48
|
+
# Validate current branch
|
|
49
49
|
npx validate-branch
|
|
50
50
|
|
|
51
|
-
#
|
|
51
|
+
# Validate specific branch
|
|
52
52
|
npx validate-branch --test feature/new-feature
|
|
53
53
|
|
|
54
|
-
#
|
|
54
|
+
# Use custom regular expression
|
|
55
55
|
npx validate-branch --regexp "^(main|develop|feature/.+)$"
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
###
|
|
58
|
+
### Programmatic Usage
|
|
59
59
|
|
|
60
|
-
####
|
|
60
|
+
#### Validate with Default Pattern
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
63
|
import { validateBranchName, validateWithDetails } from "@gracefullight/validate-branch";
|
|
64
64
|
|
|
65
|
-
//
|
|
65
|
+
// Simple boolean return
|
|
66
66
|
const isValid = validateBranchName("feature/new-component");
|
|
67
67
|
console.log(isValid); // true
|
|
68
68
|
|
|
69
|
-
//
|
|
69
|
+
// Detailed result return
|
|
70
70
|
const result = validateWithDetails("feature/new-component");
|
|
71
71
|
console.log(result);
|
|
72
72
|
// { valid: true, branchName: "feature/new-component" }
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
####
|
|
75
|
+
#### Validate with Custom Regexp
|
|
76
76
|
|
|
77
77
|
```typescript
|
|
78
78
|
import { validateBranchName } from "@gracefullight/validate-branch";
|
|
@@ -82,16 +82,16 @@ const isValid = validateBranchName("story/US-123-add-user", { customRegexp: cust
|
|
|
82
82
|
console.log(isValid); // true
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
####
|
|
85
|
+
#### Get Current Branch Name
|
|
86
86
|
|
|
87
87
|
```typescript
|
|
88
88
|
import { getCurrentBranchName } from "@gracefullight/validate-branch";
|
|
89
89
|
|
|
90
90
|
const currentBranch = await getCurrentBranchName();
|
|
91
|
-
console.log(currentBranch); // "feature/new-component"
|
|
91
|
+
console.log(currentBranch); // "feature/new-component" or null
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
####
|
|
94
|
+
#### Load Config File
|
|
95
95
|
|
|
96
96
|
```typescript
|
|
97
97
|
import { loadConfig } from "@gracefullight/validate-branch";
|
|
@@ -100,87 +100,87 @@ const config = await loadConfig();
|
|
|
100
100
|
console.log(config);
|
|
101
101
|
// {
|
|
102
102
|
// pattern: "^(main|develop|feature/.+)$",
|
|
103
|
-
// description: "
|
|
103
|
+
// description: "Project branch naming rules"
|
|
104
104
|
// }
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
##
|
|
107
|
+
## Configuration File
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
Create a `branch.config.ts` or `branch.config.js` file in your project root to define custom patterns.
|
|
110
110
|
|
|
111
|
-
### TypeScript
|
|
111
|
+
### TypeScript Config (`branch.config.ts`)
|
|
112
112
|
|
|
113
113
|
```typescript
|
|
114
114
|
import type { Config } from "@gracefullight/validate-branch";
|
|
115
115
|
|
|
116
116
|
const config: Config = {
|
|
117
117
|
pattern: "^(main|develop|feature/.+|fix/.+|refactor/.+)$",
|
|
118
|
-
description: "
|
|
118
|
+
description: "Project branch naming rules",
|
|
119
119
|
};
|
|
120
120
|
|
|
121
121
|
export default config;
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
### JavaScript
|
|
124
|
+
### JavaScript Config (`branch.config.js`)
|
|
125
125
|
|
|
126
126
|
```javascript
|
|
127
127
|
module.exports = {
|
|
128
128
|
pattern: "^(main|develop|feature/.+|fix/.+)$",
|
|
129
|
-
description: "
|
|
129
|
+
description: "Project branch naming rules",
|
|
130
130
|
};
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
-
###
|
|
133
|
+
### Using Presets (`branch.config.ts`)
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
You can use built-in presets instead of custom patterns.
|
|
136
136
|
|
|
137
137
|
```typescript
|
|
138
138
|
import type { Config } from "@gracefullight/validate-branch";
|
|
139
139
|
|
|
140
140
|
const config: Config = {
|
|
141
|
-
preset: "jira", // "gitflow"
|
|
142
|
-
description: "JIRA
|
|
141
|
+
preset: "jira", // "gitflow" or "jira"
|
|
142
|
+
description: "JIRA ticket-based branch naming",
|
|
143
143
|
};
|
|
144
144
|
|
|
145
145
|
export default config;
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
**Available Presets:**
|
|
149
149
|
|
|
150
|
-
#### `gitflow` (
|
|
150
|
+
#### `gitflow` (default)
|
|
151
151
|
|
|
152
|
-
Git Flow
|
|
152
|
+
Pattern following Git Flow branching strategy.
|
|
153
153
|
|
|
154
|
-
|
|
|
155
|
-
|
|
156
|
-
| ✅
|
|
157
|
-
| ✅
|
|
158
|
-
| ✅
|
|
159
|
-
| ✅
|
|
160
|
-
| ✅
|
|
161
|
-
| ❌
|
|
162
|
-
| ❌
|
|
163
|
-
| ❌
|
|
154
|
+
| Status | Branch Examples |
|
|
155
|
+
|--------|-----------------|
|
|
156
|
+
| ✅ Allowed | `main`, `master`, `develop`, `stage` |
|
|
157
|
+
| ✅ Allowed | `feature/login`, `feature/user-auth`, `feature/add-payment` |
|
|
158
|
+
| ✅ Allowed | `fix/memory-leak`, `fix/typo`, `fix/null-pointer` |
|
|
159
|
+
| ✅ Allowed | `hotfix/critical-bug`, `hotfix/security-patch` |
|
|
160
|
+
| ✅ Allowed | `release/v1.0.0`, `release/2.3.1` |
|
|
161
|
+
| ❌ Rejected | `login`, `bugfix`, `my-branch` (no prefix) |
|
|
162
|
+
| ❌ Rejected | `feature/`, `fix/` (no name) |
|
|
163
|
+
| ❌ Rejected | `Feature/Login`, `FIX/bug` (uppercase prefix) |
|
|
164
164
|
|
|
165
165
|
#### `jira`
|
|
166
166
|
|
|
167
|
-
JIRA
|
|
167
|
+
JIRA ticket number-based branch pattern.
|
|
168
168
|
|
|
169
|
-
|
|
|
170
|
-
|
|
171
|
-
| ✅
|
|
172
|
-
| ✅
|
|
173
|
-
| ✅
|
|
174
|
-
| ❌
|
|
175
|
-
| ❌
|
|
176
|
-
| ❌
|
|
177
|
-
| ❌
|
|
169
|
+
| Status | Branch Examples |
|
|
170
|
+
|--------|-----------------|
|
|
171
|
+
| ✅ Allowed | `main`, `master`, `develop`, `stage` |
|
|
172
|
+
| ✅ Allowed | `FEATURE-123`, `FEATURE-1`, `FEATURE-99999` |
|
|
173
|
+
| ✅ Allowed | `BUG-456`, `STORY-789`, `TASK-101`, `HOTFIX-202` |
|
|
174
|
+
| ❌ Rejected | `feature/login` (gitflow style) |
|
|
175
|
+
| ❌ Rejected | `FEATURE-ABC` (not a number) |
|
|
176
|
+
| ❌ Rejected | `feature-123` (lowercase) |
|
|
177
|
+
| ❌ Rejected | `JIRA-123/description` (contains slash) |
|
|
178
178
|
|
|
179
|
-
## API
|
|
179
|
+
## API Reference
|
|
180
180
|
|
|
181
181
|
### `validateBranchName(branchName, options?)`
|
|
182
182
|
|
|
183
|
-
|
|
183
|
+
Check if a branch name is valid.
|
|
184
184
|
|
|
185
185
|
```typescript
|
|
186
186
|
interface ValidateBranchNameOptions {
|
|
@@ -194,19 +194,19 @@ function validateBranchName(
|
|
|
194
194
|
): boolean
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
-
|
|
198
|
-
- `branchName`:
|
|
199
|
-
- `options`:
|
|
200
|
-
- `customRegexp`:
|
|
201
|
-
- `preset`:
|
|
197
|
+
**Parameters:**
|
|
198
|
+
- `branchName`: Branch name to validate
|
|
199
|
+
- `options`: Optional, validation options object
|
|
200
|
+
- `customRegexp`: Custom regular expression string
|
|
201
|
+
- `preset`: Preset pattern (`gitflow` or `jira`, default: `gitflow`)
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
**Returns:** Validity status
|
|
204
204
|
|
|
205
205
|
---
|
|
206
206
|
|
|
207
207
|
### `validateWithDetails(branchName, options?)`
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
Return detailed validation result.
|
|
210
210
|
|
|
211
211
|
```typescript
|
|
212
212
|
function validateWithDetails(
|
|
@@ -215,16 +215,16 @@ function validateWithDetails(
|
|
|
215
215
|
): ValidationResult
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
**Returns:**
|
|
219
219
|
```typescript
|
|
220
220
|
{
|
|
221
221
|
valid: boolean;
|
|
222
222
|
branchName: string;
|
|
223
|
-
error?: string; //
|
|
223
|
+
error?: string; // Error message on failure
|
|
224
224
|
}
|
|
225
225
|
```
|
|
226
226
|
|
|
227
|
-
|
|
227
|
+
**Example:**
|
|
228
228
|
```typescript
|
|
229
229
|
const result = validateWithDetails("invalid-branch");
|
|
230
230
|
// {
|
|
@@ -238,45 +238,45 @@ const result = validateWithDetails("invalid-branch");
|
|
|
238
238
|
|
|
239
239
|
### `getCurrentBranchName()`
|
|
240
240
|
|
|
241
|
-
|
|
241
|
+
Get current Git branch name.
|
|
242
242
|
|
|
243
243
|
```typescript
|
|
244
244
|
function getCurrentBranchName(): Promise<string | null>
|
|
245
245
|
```
|
|
246
246
|
|
|
247
|
-
|
|
247
|
+
**Returns:** Current branch name, `null` if not in a Git repository
|
|
248
248
|
|
|
249
249
|
---
|
|
250
250
|
|
|
251
251
|
### `loadConfig()`
|
|
252
252
|
|
|
253
|
-
|
|
253
|
+
Load project configuration file.
|
|
254
254
|
|
|
255
255
|
```typescript
|
|
256
256
|
function loadConfig(): Promise<Config | null>
|
|
257
257
|
```
|
|
258
258
|
|
|
259
|
-
|
|
259
|
+
**Config file search order:**
|
|
260
260
|
1. `branch.config.ts`
|
|
261
261
|
2. `branch.config.mts`
|
|
262
262
|
3. `branch.config.js`
|
|
263
263
|
4. `branch.config.cjs`
|
|
264
264
|
5. `branch.config.mjs`
|
|
265
265
|
|
|
266
|
-
|
|
266
|
+
**Returns:** Configuration object, `null` if no config file exists
|
|
267
267
|
|
|
268
268
|
---
|
|
269
269
|
|
|
270
|
-
##
|
|
270
|
+
## Type Definitions
|
|
271
271
|
|
|
272
272
|
### `Config`
|
|
273
273
|
|
|
274
274
|
```typescript
|
|
275
275
|
interface Config {
|
|
276
|
-
pattern?: string; //
|
|
277
|
-
patterns?: string[]; //
|
|
278
|
-
preset?: "gitflow" | "jira"; //
|
|
279
|
-
description?: string; //
|
|
276
|
+
pattern?: string; // Single regex pattern
|
|
277
|
+
patterns?: string[]; // Multiple regex patterns (planned)
|
|
278
|
+
preset?: "gitflow" | "jira"; // Preset pattern (default: "gitflow")
|
|
279
|
+
description?: string; // Config description
|
|
280
280
|
}
|
|
281
281
|
```
|
|
282
282
|
|
|
@@ -290,11 +290,11 @@ interface ValidationResult {
|
|
|
290
290
|
}
|
|
291
291
|
```
|
|
292
292
|
|
|
293
|
-
##
|
|
293
|
+
## Examples
|
|
294
294
|
|
|
295
|
-
### Git Hooks
|
|
295
|
+
### Use with Git Hooks
|
|
296
296
|
|
|
297
|
-
#### `package.json
|
|
297
|
+
#### With Husky in `package.json`
|
|
298
298
|
|
|
299
299
|
```json
|
|
300
300
|
{
|
|
@@ -306,7 +306,7 @@ interface ValidationResult {
|
|
|
306
306
|
}
|
|
307
307
|
```
|
|
308
308
|
|
|
309
|
-
####
|
|
309
|
+
#### Direct Git Hooks
|
|
310
310
|
|
|
311
311
|
```bash
|
|
312
312
|
#!/bin/sh
|
|
@@ -314,12 +314,12 @@ interface ValidationResult {
|
|
|
314
314
|
|
|
315
315
|
npx validate-branch
|
|
316
316
|
if [ $? -ne 0 ]; then
|
|
317
|
-
echo "
|
|
317
|
+
echo "Branch name does not follow naming conventions."
|
|
318
318
|
exit 1
|
|
319
319
|
fi
|
|
320
320
|
```
|
|
321
321
|
|
|
322
|
-
### GitHub Actions
|
|
322
|
+
### Use with GitHub Actions
|
|
323
323
|
|
|
324
324
|
```yaml
|
|
325
325
|
name: Branch Validation
|
|
@@ -346,7 +346,7 @@ jobs:
|
|
|
346
346
|
run: validate-branch --test ${{ github.head_ref }}
|
|
347
347
|
```
|
|
348
348
|
|
|
349
|
-
### CI/CD
|
|
349
|
+
### Use in CI/CD Pipeline
|
|
350
350
|
|
|
351
351
|
```yaml
|
|
352
352
|
# .github/workflows/ci.yml
|
|
@@ -362,14 +362,14 @@ jobs:
|
|
|
362
362
|
run: npx validate-branch
|
|
363
363
|
```
|
|
364
364
|
|
|
365
|
-
###
|
|
365
|
+
### Use with ESLint Plugin
|
|
366
366
|
|
|
367
367
|
```javascript
|
|
368
368
|
// .eslintrc.js
|
|
369
369
|
const { execSync } = require("child_process");
|
|
370
370
|
|
|
371
371
|
module.exports = {
|
|
372
|
-
// ...
|
|
372
|
+
// ... other config
|
|
373
373
|
rules: {
|
|
374
374
|
"custom/validate-branch": {
|
|
375
375
|
meta: {
|
|
@@ -401,70 +401,70 @@ module.exports = {
|
|
|
401
401
|
};
|
|
402
402
|
```
|
|
403
403
|
|
|
404
|
-
##
|
|
404
|
+
## Development
|
|
405
405
|
|
|
406
|
-
###
|
|
406
|
+
### Setup
|
|
407
407
|
|
|
408
408
|
```bash
|
|
409
|
-
#
|
|
409
|
+
# Clone repository
|
|
410
410
|
git clone https://github.com/gracefullight/saju.git
|
|
411
411
|
cd packages/validate-branch
|
|
412
412
|
|
|
413
|
-
#
|
|
413
|
+
# Install dependencies
|
|
414
414
|
pnpm install
|
|
415
415
|
|
|
416
|
-
#
|
|
416
|
+
# Build
|
|
417
417
|
pnpm build
|
|
418
418
|
|
|
419
|
-
#
|
|
419
|
+
# Test
|
|
420
420
|
pnpm test
|
|
421
421
|
|
|
422
|
-
#
|
|
422
|
+
# Lint
|
|
423
423
|
pnpm lint
|
|
424
424
|
|
|
425
|
-
#
|
|
425
|
+
# Format
|
|
426
426
|
pnpm lint:fix
|
|
427
427
|
```
|
|
428
428
|
|
|
429
|
-
###
|
|
429
|
+
### Test CLI Locally
|
|
430
430
|
|
|
431
431
|
```bash
|
|
432
|
-
#
|
|
432
|
+
# After building, test CLI locally
|
|
433
433
|
node bin/validate-branch.js --test feature/new-feature
|
|
434
434
|
|
|
435
|
-
#
|
|
435
|
+
# Test with custom pattern
|
|
436
436
|
node bin/validate-branch.js --test invalid-name --regexp "^(main|develop)$"
|
|
437
437
|
```
|
|
438
438
|
|
|
439
|
-
##
|
|
439
|
+
## Contributing
|
|
440
440
|
|
|
441
|
-
|
|
441
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
442
442
|
|
|
443
|
-
1.
|
|
444
|
-
2. feature
|
|
445
|
-
3.
|
|
446
|
-
4.
|
|
447
|
-
5. Pull Request
|
|
443
|
+
1. Fork repository
|
|
444
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
445
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
446
|
+
4. Push to branch (`git push origin feature/amazing-feature`)
|
|
447
|
+
5. Open a Pull Request
|
|
448
448
|
|
|
449
|
-
###
|
|
449
|
+
### Guidelines
|
|
450
450
|
|
|
451
|
-
-
|
|
452
|
-
-
|
|
453
|
-
-
|
|
454
|
-
-
|
|
451
|
+
- Write tests for new features
|
|
452
|
+
- Maintain or improve code coverage
|
|
453
|
+
- Follow existing code style (enforced by Biome)
|
|
454
|
+
- Update documentation as needed
|
|
455
455
|
|
|
456
|
-
##
|
|
456
|
+
## License
|
|
457
457
|
|
|
458
458
|
MIT © [gracefullight](https://github.com/gracefullight)
|
|
459
459
|
|
|
460
|
-
##
|
|
460
|
+
## Related Projects
|
|
461
461
|
|
|
462
|
-
- [isomorphic-git](https://isomorphic-git.org/) - Git
|
|
463
|
-
- [Commander.js](https://commander.js/) - Node.js CLI
|
|
464
|
-
- [Chalk](https://chalk.js.org/) -
|
|
462
|
+
- [isomorphic-git](https://isomorphic-git.org/) - Git implementation library
|
|
463
|
+
- [Commander.js](https://commander.js/) - Node.js CLI framework
|
|
464
|
+
- [Chalk](https://chalk.js.org/) - Terminal string styling
|
|
465
465
|
|
|
466
|
-
##
|
|
466
|
+
## Support
|
|
467
467
|
|
|
468
|
-
- [
|
|
469
|
-
- [
|
|
470
|
-
- [
|
|
468
|
+
- [Documentation](https://github.com/gracefullight/saju#readme)
|
|
469
|
+
- [Issue Tracker](https://github.com/gracefullight/saju/issues)
|
|
470
|
+
- [Discussions](https://github.com/gracefullight/saju/discussions)
|
package/dist/cli.js
CHANGED
|
@@ -1,20 +1,57 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
-
import { Command, Option } from "commander";
|
|
5
4
|
import chalk from "chalk";
|
|
5
|
+
import { Command, Option } from "commander";
|
|
6
|
+
|
|
7
|
+
// src/load-config.ts
|
|
8
|
+
import { readFile } from "fs/promises";
|
|
9
|
+
import { resolve } from "path";
|
|
10
|
+
import { cwd } from "process";
|
|
11
|
+
var CONFIG_FILES = [
|
|
12
|
+
"branch.config.ts",
|
|
13
|
+
"branch.config.mts",
|
|
14
|
+
"branch.config.js",
|
|
15
|
+
"branch.config.cjs",
|
|
16
|
+
"branch.config.mjs"
|
|
17
|
+
];
|
|
18
|
+
async function loadConfig() {
|
|
19
|
+
for (const file of CONFIG_FILES) {
|
|
20
|
+
const configPath = resolve(cwd(), file);
|
|
21
|
+
try {
|
|
22
|
+
await readFile(configPath, "utf-8");
|
|
23
|
+
if (file.endsWith(".ts") || file.endsWith(".mts")) {
|
|
24
|
+
const { default: config } = await import(`file://${configPath}?ts=${Date.now()}`);
|
|
25
|
+
return config;
|
|
26
|
+
}
|
|
27
|
+
if (file.endsWith(".mjs")) {
|
|
28
|
+
const { default: config } = await import(`file://${configPath}?ts=${Date.now()}`);
|
|
29
|
+
return config;
|
|
30
|
+
}
|
|
31
|
+
if (file.endsWith(".js") || file.endsWith(".cjs")) {
|
|
32
|
+
const { default: config } = await import(configPath);
|
|
33
|
+
return config;
|
|
34
|
+
}
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error.code !== "ENOENT") {
|
|
37
|
+
console.error(`Error loading config file ${file}:`, error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
6
43
|
|
|
7
44
|
// src/validate-branch-name.ts
|
|
8
|
-
import * as git from "isomorphic-git";
|
|
9
45
|
import * as fs from "fs";
|
|
10
|
-
import { cwd } from "process";
|
|
46
|
+
import { cwd as cwd2 } from "process";
|
|
47
|
+
import * as git from "isomorphic-git";
|
|
11
48
|
var GITFLOW_PATTERN = /^(main|master|develop|stage|feature\/[A-Za-z0-9_-]+|fix\/[A-Za-z0-9_-]+|hotfix\/[A-Za-z0-9_-]+|release\/[A-Za-z0-9_.-]+)$/;
|
|
12
49
|
var JIRA_PATTERN = /^(main|master|develop|stage|[A-Z]+-[0-9]+)$/;
|
|
13
50
|
async function getCurrentBranchName() {
|
|
14
51
|
try {
|
|
15
52
|
const branch = await git.currentBranch({
|
|
16
53
|
fs,
|
|
17
|
-
dir:
|
|
54
|
+
dir: cwd2(),
|
|
18
55
|
fullname: false
|
|
19
56
|
});
|
|
20
57
|
return branch ?? null;
|
|
@@ -46,43 +83,6 @@ function validateWithDetails(branchName, options) {
|
|
|
46
83
|
};
|
|
47
84
|
}
|
|
48
85
|
|
|
49
|
-
// src/load-config.ts
|
|
50
|
-
import { readFile } from "fs/promises";
|
|
51
|
-
import { resolve } from "path";
|
|
52
|
-
import { cwd as cwd2 } from "process";
|
|
53
|
-
var CONFIG_FILES = [
|
|
54
|
-
"branch.config.ts",
|
|
55
|
-
"branch.config.mts",
|
|
56
|
-
"branch.config.js",
|
|
57
|
-
"branch.config.cjs",
|
|
58
|
-
"branch.config.mjs"
|
|
59
|
-
];
|
|
60
|
-
async function loadConfig() {
|
|
61
|
-
for (const file of CONFIG_FILES) {
|
|
62
|
-
const configPath = resolve(cwd2(), file);
|
|
63
|
-
try {
|
|
64
|
-
await readFile(configPath, "utf-8");
|
|
65
|
-
if (file.endsWith(".ts") || file.endsWith(".mts")) {
|
|
66
|
-
const { default: config } = await import(`file://${configPath}?ts=${Date.now()}`);
|
|
67
|
-
return config;
|
|
68
|
-
}
|
|
69
|
-
if (file.endsWith(".mjs")) {
|
|
70
|
-
const { default: config } = await import(`file://${configPath}?ts=${Date.now()}`);
|
|
71
|
-
return config;
|
|
72
|
-
}
|
|
73
|
-
if (file.endsWith(".js") || file.endsWith(".cjs")) {
|
|
74
|
-
const { default: config } = await import(configPath);
|
|
75
|
-
return config;
|
|
76
|
-
}
|
|
77
|
-
} catch (error) {
|
|
78
|
-
if (error.code !== "ENOENT") {
|
|
79
|
-
console.error(`Error loading config file ${file}:`, error);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
86
|
// src/cli.ts
|
|
87
87
|
var SUCCESS_CODE = 0;
|
|
88
88
|
var FAILED_CODE = 1;
|