diff --git a/developer/js/.npmignore b/developer/js/.npmignore new file mode 100644 index 0000000000..884d65b27d --- /dev/null +++ b/developer/js/.npmignore @@ -0,0 +1,6 @@ +# Ignore files required only in development. +build.sh +source/* +tests/* +*.js.map +tsconfig.json diff --git a/developer/js/build.sh b/developer/js/build.sh index 4c65b6d5d9..94038a31b7 100755 --- a/developer/js/build.sh +++ b/developer/js/build.sh @@ -21,9 +21,10 @@ display_usage ( ) { echo " $0 -help" echo echo " -help displays this screen and exits" - echo " -test runs unit tests after building" echo " -version version sets the package version before building" - echo " -tier tier also sets the package version tier (alpha, beta, stable) before building" + echo " -test runs unit tests after building" + echo " -publish-to-npm publishes the current version to the npm package index" + echo " -tier tier also sets the package version tier and npm tag (alpha, beta, stable) before building or publishing" echo " If version has 4 components, only first three are used." } @@ -34,6 +35,7 @@ install_dependencies=1 publish_version= publish_tier= lastkey= +should_publish=0 # Process command-line arguments while [[ $# -gt 0 ]] ; do @@ -54,6 +56,9 @@ while [[ $# -gt 0 ]] ; do -tier) lastkey=$key ;; + -publish-to-npm) + should_publish=1 + ;; *) echo "$0: invalid option: $key" display_usage @@ -122,3 +127,17 @@ echo "Typescript compilation successful." if (( run_tests )); then npm test || fail "Tests failed" fi + +if (( should_publish )); then + # Note: In either case, npm publish MUST be given --access public to publish + # a package in the @keymanapp scope on the public npm package index. + # + # See `npm help publish` for more details. + if [ -z "$publish_tier" ] ; then + # Publish a stable release (npm tag: latest) + npm publish --access public || fail "Could not publish stable release." + else + # Publish a pre-release (npm tag: alpha or beta) + npm publish --access public --tag "$publish_tier" || fail "Could not publish $publish_tier release." + fi +fi diff --git a/docs/npm-packages.md b/docs/npm-packages.md index 37c99d7cb5..b10d4f3f7d 100644 --- a/docs/npm-packages.md +++ b/docs/npm-packages.md @@ -4,23 +4,33 @@ npm packages This is a guide for how the various Keyman `npm` packages are developed and published. +`npm` packages are published on the CI (continuous integration) server. +Currently, we're using TeamCity for this. + +Packages are **never** published from a developer's machine. + For CI developers ----------------- ### In general -Before publishing, a package must be **built** and **tested**. +Before publishing, a package must be **built** and **tested** on the CI +server. This is typically done with: ./build.sh -test -Once the build succeeds and tests pass, the version is set in +Once the build succeeds and the tests pass, the version is set in `package.json`: ./build.sh -version 12.0.${BUILD_NUMBER} -tier ${tier} +Now you can publish! Use the following script for this (again, **only on the CI server**!) + + ./build.sh -publish-to-npm -tier ${tier} + It is then uploaded to the npm package directory. **Ensure that the compiled sources are included in the tarball**. For example,