Skip to content

Commit

Permalink
chore: publish to npm
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin committed Jun 21, 2023
1 parent 3aba19a commit fcbd4cc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/libs/ui-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@cowprotocol/ui-utils",
"version": "0.0.1",
"version": "0.0.3",
"type": "commonjs"
}
3 changes: 1 addition & 2 deletions src/libs/widget-lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ nx test widget-lib

# Build the library
nx build widget-lib
cp src/libs/widget-lib/README.md dist/libs/widget-lib # automate

# Publish to NPM
npm publish --access=public ./dist/libs/widget-lib
nx publish widget-lib --ver 0.0.7 --tag latest
```

## Running unit tests
Expand Down
2 changes: 1 addition & 1 deletion src/libs/widget-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cowprotocol/widget-lib",
"version": "0.0.2",
"version": "0.0.5",
"type": "commonjs",
"description": "CoW Swap Widget Library. Allows you to easily embed a CoW Swap widget on your website.",
"main": "index.js",
Expand Down
6 changes: 0 additions & 6 deletions src/libs/widget-lib/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
"outputPath": "dist/libs/widget-lib"
}
},
"docs": {
"executor": "nx:run-commands",
"options": {
"command": "cp src/libs/widget-lib/README.md dist/libs/widget-lib"
}
},
"publish": {
"command": "node tools/scripts/publish.mjs widget-lib {args.ver} {args.tag}",
"dependsOn": ["build"]
Expand Down
17 changes: 12 additions & 5 deletions tools/scripts/publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
* You might need to authenticate with NPM before running this script.
*/

import { execSync } from 'child_process'
import { readFileSync, writeFileSync } from 'fs'
import devkit from '@nx/devkit'
import chalk from 'chalk'

import devkit from '@nx/devkit'
import { execSync } from 'child_process'
import { readFileSync, writeFileSync } from 'fs'
import path from 'path'
const { readCachedProjectGraph } = devkit

function invariant(condition, message) {
Expand All @@ -23,7 +24,7 @@ function invariant(condition, message) {

// Executing publish script: node path/to/publish.mjs {name} --version {version} --tag {tag}
// Default "tag" to "next" so we won't publish the "latest" tag by accident.
const [, , name, version, tag = 'next'] = process.argv
const [, , name, version, tag] = process.argv

// A simple SemVer validation to validate the version
const validVersion = /^\d+\.\d+\.\d+(-\w+\.\d+)?/
Expand All @@ -43,6 +44,9 @@ invariant(
`Could not find "build.options.outputPath" of project "${name}". Is project.json configured correctly?`
)

const rootLib = path.dirname(project.data.sourceRoot)
const copyReadmeCommand = `cp ${rootLib}/README.md ${outputPath}`
console.log(chalk.bold.greenBright(copyReadmeCommand))
process.chdir(outputPath)

// Updating the version in "package.json" before publishing
Expand All @@ -55,4 +59,7 @@ try {
}

// Execute "npm publish" to publish
execSync(`npm publish --access public --tag ${tag}`)
const publishCommand = `npm publish --access public --tag ${tag === 'undefined' ? 'next' : tag}`
console.log(chalk.bold.greenBright(publishCommand))
execSync(publishCommand)
console.log('Published successfully 🎉')

0 comments on commit fcbd4cc

Please sign in to comment.