@aspruyt/json-config-sync 0.1.4 → 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.
Files changed (2) hide show
  1. package/README.md +246 -13
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -2,8 +2,68 @@
2
2
 
3
3
  [![CI](https://github.com/anthony-spruyt/json-config-sync/actions/workflows/ci.yml/badge.svg)](https://github.com/anthony-spruyt/json-config-sync/actions/workflows/ci.yml)
4
4
  [![Integration Test](https://github.com/anthony-spruyt/json-config-sync/actions/workflows/integration.yml/badge.svg)](https://github.com/anthony-spruyt/json-config-sync/actions/workflows/integration.yml)
5
+ [![npm version](https://img.shields.io/npm/v/@aspruyt/json-config-sync.svg)](https://www.npmjs.com/package/@aspruyt/json-config-sync)
6
+ [![npm downloads](https://img.shields.io/npm/dw/@aspruyt/json-config-sync.svg)](https://www.npmjs.com/package/@aspruyt/json-config-sync)
5
7
 
6
- A CLI tool that syncs JSON configuration files across multiple Git repositories by creating pull requests.
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
+ ```
7
67
 
8
68
  ## Features
9
69
 
@@ -69,11 +129,11 @@ json-config-sync --config ./config.yaml --work-dir ./my-temp
69
129
 
70
130
  ### Options
71
131
 
72
- | Option | Alias | Description | Required |
73
- |--------|-------|-------------|----------|
74
- | `--config` | `-c` | Path to YAML config file | Yes |
75
- | `--dry-run` | `-d` | Show what would be done without making changes | No |
76
- | `--work-dir` | `-w` | Temporary directory for cloning (default: `./tmp`) | No |
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 |
77
137
 
78
138
  ## Configuration Format
79
139
 
@@ -95,24 +155,55 @@ repos:
95
155
 
96
156
  ### Fields
97
157
 
98
- | Field | Description |
99
- |-------|-------------|
100
- | `fileName` | The name of the JSON file to create/update in each repo |
101
- | `repos` | Array of repository configurations |
102
- | `repos[].git` | Git URL of the repository (SSH or HTTPS) |
103
- | `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 |
104
164
 
105
165
  ## Supported Git URL Formats
106
166
 
107
167
  ### GitHub
168
+
108
169
  - SSH: `git@github.com:owner/repo.git`
109
170
  - HTTPS: `https://github.com/owner/repo.git`
110
171
 
111
172
  ### Azure DevOps
173
+
112
174
  - SSH: `git@ssh.dev.azure.com:v3/organization/project/repo`
113
175
  - HTTPS: `https://dev.azure.com/organization/project/_git/repo`
114
176
 
115
- ## Workflow
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
+ ```
116
207
 
117
208
  For each repository in the config, the tool:
118
209
 
@@ -147,11 +238,153 @@ json-config-sync --config ./config.yaml
147
238
  ```
148
239
 
149
240
  Will:
241
+
150
242
  1. Clone `example-org/my-service`
151
243
  2. Create branch `chore/sync-my-config`
152
244
  3. Write `my.config.json` with the specified content
153
245
  4. Create a PR titled "chore: sync my.config.json"
154
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
+
155
388
  ## Development
156
389
 
157
390
  ```bash
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aspruyt/json-config-sync",
3
- "version": "0.1.4",
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": {