|
| 1 | +#!/usr/bin/env node |
| 2 | +/* |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +'use strict'; |
| 17 | + |
| 18 | +const fs = require('fs'); |
| 19 | +const glob = require('glob'); |
| 20 | + |
| 21 | +/** |
| 22 | + * This script updates the devDependencies and dependencies in the workspaces |
| 23 | + * to match the version specified by the given parameter. |
| 24 | + * The expected parameter should be the tag for the package. |
| 25 | + * |
| 26 | + * Example: |
| 27 | + * node ./scripts/bump_version.js <tag> |
| 28 | + */ |
| 29 | + |
| 30 | +const workspacesPattern = 'packages/**/package.json'; // Adjust this pattern based on your workspace setup |
| 31 | +const packageNames = [ |
| 32 | + "@accordproject/markdown-cicero", |
| 33 | + "@accordproject/markdown-cli", |
| 34 | + "@accordproject/markdown-common", |
| 35 | + "@accordproject/markdown-html", |
| 36 | + "@accordproject/markdown-it-cicero", |
| 37 | + "@accordproject/markdown-it-template", |
| 38 | + "@accordproject/markdown-template", |
| 39 | + "@accordproject/markdown-transform", |
| 40 | +]; |
| 41 | + |
| 42 | +function bumpDependencies() { |
| 43 | + const targetPackageVersion = process.argv[2].replace(/^v/, ''); |
| 44 | + const workspacePackages = glob.sync(workspacesPattern, { |
| 45 | + ignore: ['**/node_modules/**', '**/test/**'], |
| 46 | + }); |
| 47 | + |
| 48 | + workspacePackages.forEach((packagePath) => { |
| 49 | + const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8')); |
| 50 | + |
| 51 | + ['dependencies', 'devDependencies'].forEach((depType) => { |
| 52 | + packageNames.forEach(dep => { |
| 53 | + if (packageJson[depType] && (dep in packageJson[depType])) { |
| 54 | + packageJson[depType][dep] = targetPackageVersion; |
| 55 | + } |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2) + '\n', 'utf8'); |
| 60 | + }); |
| 61 | + |
| 62 | + console.log('Dependencies updated successfully!'); |
| 63 | +} |
| 64 | + |
| 65 | +bumpDependencies(); |
0 commit comments