-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathpwa-kit-deps-version.js
More file actions
54 lines (45 loc) · 1.79 KB
/
pwa-kit-deps-version.js
File metadata and controls
54 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
/* eslint-disable @typescript-eslint/no-var-requires */
const sh = require('shelljs')
const path = require('path')
const {saveJSONToFile, getLatestVersion} = require('../utils')
// Exit upon error
sh.set('-e')
const publicPackages = JSON.parse(sh.exec('lerna list --json', {silent: true}))
const pathToPackage = (packageName) => {
const pkg = publicPackages.find((pkg) => pkg.name === packageName)
return pkg?.location
}
// Assuming that this is run within a specific package,
// the script would update its pwa-kit/sdk dependencies.
const main = () => {
const updateBehaviour = process.argv[2]
const packageName = process.argv[3]
const pathToPackageJson = path.join(pathToPackage(packageName), 'package.json')
const pkgJson = JSON.parse(sh.cat(pathToPackageJson))
if (updateBehaviour === 'latest') {
publicPackages.forEach(({name}) => {
if (pkgJson.dependencies?.[name]) {
pkgJson.dependencies[name] = getLatestVersion(name)
} else if (pkgJson.devDependencies?.[name]) {
pkgJson.devDependencies[name] = getLatestVersion(name)
}
})
} else if (updateBehaviour === 'sync') {
// Sync version with what's in the monorepo
publicPackages.forEach(({version, name}) => {
if (pkgJson.dependencies?.[name]) {
pkgJson.dependencies[name] = version
} else if (pkgJson.devDependencies?.[name]) {
pkgJson.devDependencies[name] = version
}
})
}
saveJSONToFile(pkgJson, pathToPackageJson)
}
main()