@aspruyt/json-config-sync 1.0.0 → 1.0.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.md +244 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,7 +5,65 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/@aspruyt/json-config-sync)
|
|
6
6
|
[](https://www.npmjs.com/package/@aspruyt/json-config-sync)
|
|
7
7
|
|
|
8
|
-
A CLI tool that syncs JSON configuration files across multiple
|
|
8
|
+
A CLI tool that syncs JSON configuration files across multiple GitHub and Azure DevOps repositories by creating pull requests.
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [Quick Start](#quick-start)
|
|
13
|
+
- [Features](#features)
|
|
14
|
+
- [How It Works](#how-it-works)
|
|
15
|
+
- [Installation](#installation)
|
|
16
|
+
- [Prerequisites](#prerequisites)
|
|
17
|
+
- [Usage](#usage)
|
|
18
|
+
- [Configuration Format](#configuration-format)
|
|
19
|
+
- [Supported Git URL Formats](#supported-git-url-formats)
|
|
20
|
+
- [CI/CD Integration](#cicd-integration)
|
|
21
|
+
- [Output Examples](#output-examples)
|
|
22
|
+
- [Troubleshooting](#troubleshooting)
|
|
23
|
+
- [Development](#development)
|
|
24
|
+
- [License](#license)
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Install
|
|
30
|
+
npm install -g @aspruyt/json-config-sync
|
|
31
|
+
|
|
32
|
+
# Authenticate (GitHub)
|
|
33
|
+
gh auth login
|
|
34
|
+
|
|
35
|
+
# Create config.yaml
|
|
36
|
+
cat > config.yaml << 'EOF'
|
|
37
|
+
fileName: .prettierrc.json
|
|
38
|
+
repos:
|
|
39
|
+
- git: git@github.com:your-org/frontend-app.git
|
|
40
|
+
json:
|
|
41
|
+
semi: false
|
|
42
|
+
singleQuote: true
|
|
43
|
+
tabWidth: 2
|
|
44
|
+
trailingComma: es5
|
|
45
|
+
- git: git@github.com:your-org/backend-api.git
|
|
46
|
+
json:
|
|
47
|
+
semi: false
|
|
48
|
+
singleQuote: true
|
|
49
|
+
tabWidth: 2
|
|
50
|
+
trailingComma: es5
|
|
51
|
+
EOF
|
|
52
|
+
|
|
53
|
+
# Run
|
|
54
|
+
json-config-sync --config ./config.yaml
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Result:** PRs are created in both repos with `.prettierrc.json`:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"semi": false,
|
|
62
|
+
"singleQuote": true,
|
|
63
|
+
"tabWidth": 2,
|
|
64
|
+
"trailingComma": "es5"
|
|
65
|
+
}
|
|
66
|
+
```
|
|
9
67
|
|
|
10
68
|
## Features
|
|
11
69
|
|
|
@@ -71,11 +129,11 @@ json-config-sync --config ./config.yaml --work-dir ./my-temp
|
|
|
71
129
|
|
|
72
130
|
### Options
|
|
73
131
|
|
|
74
|
-
| Option
|
|
75
|
-
|
|
76
|
-
| `--config`
|
|
77
|
-
| `--dry-run`
|
|
78
|
-
| `--work-dir` | `-w`
|
|
132
|
+
| Option | Alias | Description | Required |
|
|
133
|
+
| ------------ | ----- | -------------------------------------------------- | -------- |
|
|
134
|
+
| `--config` | `-c` | Path to YAML config file | Yes |
|
|
135
|
+
| `--dry-run` | `-d` | Show what would be done without making changes | No |
|
|
136
|
+
| `--work-dir` | `-w` | Temporary directory for cloning (default: `./tmp`) | No |
|
|
79
137
|
|
|
80
138
|
## Configuration Format
|
|
81
139
|
|
|
@@ -97,24 +155,55 @@ repos:
|
|
|
97
155
|
|
|
98
156
|
### Fields
|
|
99
157
|
|
|
100
|
-
| Field
|
|
101
|
-
|
|
102
|
-
| `fileName`
|
|
103
|
-
| `repos`
|
|
104
|
-
| `repos[].git`
|
|
105
|
-
| `repos[].json` | The JSON content to write to the file
|
|
158
|
+
| Field | Description |
|
|
159
|
+
| -------------- | ------------------------------------------------------- |
|
|
160
|
+
| `fileName` | The name of the JSON file to create/update in each repo |
|
|
161
|
+
| `repos` | Array of repository configurations |
|
|
162
|
+
| `repos[].git` | Git URL of the repository (SSH or HTTPS) |
|
|
163
|
+
| `repos[].json` | The JSON content to write to the file |
|
|
106
164
|
|
|
107
165
|
## Supported Git URL Formats
|
|
108
166
|
|
|
109
167
|
### GitHub
|
|
168
|
+
|
|
110
169
|
- SSH: `git@github.com:owner/repo.git`
|
|
111
170
|
- HTTPS: `https://github.com/owner/repo.git`
|
|
112
171
|
|
|
113
172
|
### Azure DevOps
|
|
173
|
+
|
|
114
174
|
- SSH: `git@ssh.dev.azure.com:v3/organization/project/repo`
|
|
115
175
|
- HTTPS: `https://dev.azure.com/organization/project/_git/repo`
|
|
116
176
|
|
|
117
|
-
##
|
|
177
|
+
## How It Works
|
|
178
|
+
|
|
179
|
+
```mermaid
|
|
180
|
+
flowchart TB
|
|
181
|
+
subgraph Input
|
|
182
|
+
YAML[/"YAML Config File<br/>fileName + repos[]"/]
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
subgraph Processing["For Each Repository"]
|
|
186
|
+
CLONE[Clone Repo] --> BRANCH[Create/Checkout Branch<br/>chore/sync-filename]
|
|
187
|
+
BRANCH --> WRITE[Write JSON File]
|
|
188
|
+
WRITE --> CHECK{Changes?}
|
|
189
|
+
CHECK -->|No| SKIP[Skip - No Changes]
|
|
190
|
+
CHECK -->|Yes| COMMIT[Commit Changes]
|
|
191
|
+
COMMIT --> PUSH[Push to Remote]
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
subgraph Platform["Platform Detection"]
|
|
195
|
+
PUSH --> DETECT{GitHub or<br/>Azure DevOps?}
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
subgraph Output
|
|
199
|
+
DETECT -->|GitHub| GH_PR[Create PR via gh CLI]
|
|
200
|
+
DETECT -->|Azure DevOps| AZ_PR[Create PR via az CLI]
|
|
201
|
+
GH_PR --> GH_URL[/"GitHub PR URL"/]
|
|
202
|
+
AZ_PR --> AZ_URL[/"Azure DevOps PR URL"/]
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
YAML --> CLONE
|
|
206
|
+
```
|
|
118
207
|
|
|
119
208
|
For each repository in the config, the tool:
|
|
120
209
|
|
|
@@ -149,11 +238,153 @@ json-config-sync --config ./config.yaml
|
|
|
149
238
|
```
|
|
150
239
|
|
|
151
240
|
Will:
|
|
241
|
+
|
|
152
242
|
1. Clone `example-org/my-service`
|
|
153
243
|
2. Create branch `chore/sync-my-config`
|
|
154
244
|
3. Write `my.config.json` with the specified content
|
|
155
245
|
4. Create a PR titled "chore: sync my.config.json"
|
|
156
246
|
|
|
247
|
+
## CI/CD Integration
|
|
248
|
+
|
|
249
|
+
### GitHub Actions
|
|
250
|
+
|
|
251
|
+
```yaml
|
|
252
|
+
name: Sync Configs
|
|
253
|
+
on:
|
|
254
|
+
push:
|
|
255
|
+
branches: [main]
|
|
256
|
+
paths: ["config.yaml"]
|
|
257
|
+
|
|
258
|
+
jobs:
|
|
259
|
+
sync:
|
|
260
|
+
runs-on: ubuntu-latest
|
|
261
|
+
steps:
|
|
262
|
+
- uses: actions/checkout@v4
|
|
263
|
+
- uses: actions/setup-node@v4
|
|
264
|
+
with:
|
|
265
|
+
node-version: "20"
|
|
266
|
+
- run: npm install -g @aspruyt/json-config-sync
|
|
267
|
+
- run: json-config-sync --config ./config.yaml
|
|
268
|
+
env:
|
|
269
|
+
GH_TOKEN: ${{ secrets.GH_PAT }}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
> **Note:** `GH_PAT` must be a Personal Access Token with `repo` scope to create PRs in target repositories.
|
|
273
|
+
|
|
274
|
+
### Azure Pipelines
|
|
275
|
+
|
|
276
|
+
```yaml
|
|
277
|
+
trigger:
|
|
278
|
+
branches:
|
|
279
|
+
include: [main]
|
|
280
|
+
paths:
|
|
281
|
+
include: ["config.yaml"]
|
|
282
|
+
|
|
283
|
+
pool:
|
|
284
|
+
vmImage: "ubuntu-latest"
|
|
285
|
+
|
|
286
|
+
steps:
|
|
287
|
+
- task: NodeTool@0
|
|
288
|
+
inputs:
|
|
289
|
+
versionSpec: "20.x"
|
|
290
|
+
- script: npm install -g @aspruyt/json-config-sync
|
|
291
|
+
displayName: "Install json-config-sync"
|
|
292
|
+
- script: json-config-sync --config ./config.yaml
|
|
293
|
+
displayName: "Sync configs"
|
|
294
|
+
env:
|
|
295
|
+
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
> **Note:** Ensure the build service account has permission to create PRs in target repositories.
|
|
299
|
+
|
|
300
|
+
## Output Examples
|
|
301
|
+
|
|
302
|
+
### Console Output
|
|
303
|
+
|
|
304
|
+
```
|
|
305
|
+
[1/3] Processing example-org/repo1...
|
|
306
|
+
✓ Cloned repository
|
|
307
|
+
✓ Created branch chore/sync-my-config
|
|
308
|
+
✓ Wrote my.config.json
|
|
309
|
+
✓ Committed changes
|
|
310
|
+
✓ Pushed to remote
|
|
311
|
+
✓ Created PR: https://github.com/example-org/repo1/pull/42
|
|
312
|
+
|
|
313
|
+
[2/3] Processing example-org/repo2...
|
|
314
|
+
✓ Cloned repository
|
|
315
|
+
✓ Checked out existing branch chore/sync-my-config
|
|
316
|
+
✓ Wrote my.config.json
|
|
317
|
+
⊘ No changes detected, skipping
|
|
318
|
+
|
|
319
|
+
[3/3] Processing example-org/repo3...
|
|
320
|
+
✓ Cloned repository
|
|
321
|
+
✓ Created branch chore/sync-my-config
|
|
322
|
+
✓ Wrote my.config.json
|
|
323
|
+
✓ Committed changes
|
|
324
|
+
✓ Pushed to remote
|
|
325
|
+
✓ PR already exists: https://github.com/example-org/repo3/pull/15
|
|
326
|
+
|
|
327
|
+
Summary: 2 succeeded, 1 skipped, 0 failed
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Created PR
|
|
331
|
+
|
|
332
|
+
The tool creates PRs with:
|
|
333
|
+
|
|
334
|
+
- **Title:** `chore: sync {fileName}`
|
|
335
|
+
- **Branch:** `chore/sync-{sanitized-filename}`
|
|
336
|
+
- **Body:** Describes the sync action and links to documentation
|
|
337
|
+
|
|
338
|
+
## Troubleshooting
|
|
339
|
+
|
|
340
|
+
### Authentication Errors
|
|
341
|
+
|
|
342
|
+
**GitHub:**
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
# Check authentication status
|
|
346
|
+
gh auth status
|
|
347
|
+
|
|
348
|
+
# Re-authenticate if needed
|
|
349
|
+
gh auth login
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
**Azure DevOps:**
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
# Check authentication status
|
|
356
|
+
az account show
|
|
357
|
+
|
|
358
|
+
# Re-authenticate if needed
|
|
359
|
+
az login
|
|
360
|
+
az devops configure --defaults organization=https://dev.azure.com/YOUR_ORG
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### Permission Denied
|
|
364
|
+
|
|
365
|
+
- Ensure your token has write access to the target repositories
|
|
366
|
+
- For GitHub, the token needs `repo` scope
|
|
367
|
+
- For Azure DevOps, ensure the user/service account has "Contribute to pull requests" permission
|
|
368
|
+
|
|
369
|
+
### Branch Already Exists
|
|
370
|
+
|
|
371
|
+
The tool automatically reuses existing branches. If you see unexpected behavior:
|
|
372
|
+
|
|
373
|
+
```bash
|
|
374
|
+
# Delete the remote branch to start fresh
|
|
375
|
+
git push origin --delete chore/sync-my-config
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### Network/Proxy Issues
|
|
379
|
+
|
|
380
|
+
If cloning fails behind a corporate proxy:
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
# Configure git proxy
|
|
384
|
+
git config --global http.proxy http://proxy.example.com:8080
|
|
385
|
+
git config --global https.proxy http://proxy.example.com:8080
|
|
386
|
+
```
|
|
387
|
+
|
|
157
388
|
## Development
|
|
158
389
|
|
|
159
390
|
```bash
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aspruyt/json-config-sync",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "CLI tool to sync JSON configuration files across multiple repositories",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "CLI tool to sync JSON configuration files across multiple GitHub and Azure DevOps repositories",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"bin": {
|