Skip to content

Commit

Permalink
Explore publishing certain packages only
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarta committed May 9, 2023
1 parent f8dcaa0 commit 42a8bc1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/actions/publish_to_npm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ runs:
# Publish all changed packages. The "from-package" arg means "look
# at the version numbers in each package.json file and if that doesn't
# exist on NPM, publish"
npm run lerna -- publish from-package --yes --no-verify-access --pre-dist-tag next
# npm run lerna -- publish from-package --yes --no-verify-access --pre-dist-tag next
npm run publish-to-npm
# Cleanup
rm ~/.npmrc
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "3.1.0-dev",
"scripts": {
"pwa-kit-version": "node ./scripts/bump-version.js",
"publish-to-npm": "node ./scripts/publish-to-npm.js",
"format": "lerna run --stream format",
"preinstall": "node ./scripts/check-version.js",
"postinstall": "node ./scripts/bootstrap.js",
Expand Down
76 changes: 76 additions & 0 deletions scripts/publish-to-npm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env node
/*
* 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
*/

const sh = require('shelljs')
const path = require('path')

// Exit upon error
sh.set('-e')

const PWA_KIT_PACKAGES = [
'pwa-kit-create-app',
'pwa-kit-dev',
'pwa-kit-runtime',
'pwa-kit-react-sdk',
'commerce-sdk-react'
]

const main = () => {
// TODO
// - look at the release branch's name
// - toggle `private` accordingly
// - run `lerna publish`
// - restore `private` afterwards
const {stdout: branchName} = sh.exec('git branch --show-current', {silent: true})

// If branch name is `release-3.1.x`
// If branch name is `release-retail-react-app-3.1.x`
// if (/^release-\d/.test(branchName)) {}
// if (/^release-retail-react-app-\d/.test(branchName)) {}

const isReleasingPWAKit = false
const isReleasingRetailApp = true

if (isReleasingPWAKit) {
console.log('--- Planning to release pwa-kit packages...')
const pathToRetailApp = path.join(__dirname, '..', 'packages/template-retail-react-app')

sh.exec('npm pkg set private=true', {cwd: pathToRetailApp})
lernaPublish()
sh.exec('npm pkg delete private', {cwd: pathToRetailApp})

} else if (isReleasingRetailApp) {
console.log('--- Planning to release retail-react-app...')
// TODO: rely on `lerna list --json`
PWA_KIT_PACKAGES.forEach((packageName) => {
const pathToPackage = path.join(__dirname, '..', `packages/${packageName}`)
sh.exec('npm pkg set private=true', {cwd: pathToPackage})
})

lernaPublish()

PWA_KIT_PACKAGES.forEach((packageName) => {
const pathToPackage = path.join(__dirname, '..', `packages/${packageName}`)
sh.exec('npm pkg delete private', {cwd: pathToPackage})
})
}
}

const lernaPublish = () => {
// Why do we still want `lerna publish`? It turns that we do need it. Sometimes we wanted some behaviour that's unique to Lerna.
// For example: we have `publishConfig.directory` in some package.json files that only Lerna knows what to do with it.
// https://github.com/lerna/lerna/tree/main/libs/commands/publish#publishconfigdirectory

// DEBUG: disable for now
// sh.exec('npm run lerna -- publish from-package --yes --no-verify-access --pre-dist-tag next')

console.log('--- Would publish some packages that are public:')
sh.exec('npm run lerna -- list --long --all')
}

main()

0 comments on commit 42a8bc1

Please sign in to comment.