Skip to content

Commit

Permalink
[AAE-11496] Publish libraries to npm (#2880)
Browse files Browse the repository at this point in the history
* [AAE-11496] Publish libraries to npm registry

* update

* update

* added md

* deprecate old version
  • Loading branch information
BSekula committed Jan 26, 2023
1 parent 87c1c2b commit a8268c6
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ stages:
if: branch = master AND type = push
- name: e2e
if: type = cron || type = pull_request
- name: Release Libraries
if: type = push
- name: Trigger DW
if: branch = develop AND (type = cron OR (type = api AND commit_message =~ /\[trigger aca\]/))

Expand Down Expand Up @@ -190,6 +192,13 @@ jobs:
name: Release Tag
script: ./scripts/travis/release/git-tag.sh

- stage: Release Libraries
name: Release Libraries
script:
- npm ci
- ./scripts/ci/npm/publish-libs.sh
cache: false

- name: Publish to Dockerhub
script: ./scripts/travis/deploy/publish.sh "content-ce" "$DOCKER_HUB_REPOSITORY_DOMAIN" "$DOCKER_HUB_USERNAME" "$DOCKER_HUB_PASSWORD"

Expand Down
3 changes: 2 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@
"production": {
"tsConfig": "projects/aca-shared/tsconfig.lib.prod.json"
}
}
},
"defaultConfiguration": "production"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
Expand Down
37 changes: 37 additions & 0 deletions docs/extending/publish-to-npm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
Title: Publish to npm
---

# Create a new library

New library can be created using standard `ng` command

e.g. if we would like to create `aca-new-lib` we need to run the following:

```
ng generate @schematics/angular:library aca-new-lib
```

# Publish library

## Build library
In order to publish new library, we need to build it first. You need to add build of your library to `build-libs` command in `package.json`

```
"build-libs": "ng build aca-shared && ng build aca-new-lib",
```

## Update publish script
If we would like to publish the new library we need to update `scripts/ci/npm/publish-libs.sh`

The only thing that need to be done is to update `PROJECTS` variable by adding your library name i.e.

```
PROJECTS=(
'aca-shared',
'aca-new-lib'
);
```
# Caveats
- The versions of libraries are updated automatically by the script (should not be done manually)
- In travis setting you can find `PUBLISH_PROJECTS` variable, which can be used for enabling dry mode when running the publish command
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"prebuild": "mkdir -p ./app/.tmp && cp ./app/src/app.config.json.tpl ./app/.tmp/app.config.json",
"build": "ng build content-ce",
"build.release": "npm run build -- --configuration=production,release",
"build-libs": "ng build aca-shared",
"test": "ng test",
"test:ci": "ng test adf-office-services-ext && ng test content-ce --code-coverage",
"lint": "NODE_OPTIONS=--max_old_space_size=4096 ng lint && npm run spellcheck && npm run e2e.typecheck",
Expand Down
83 changes: 83 additions & 0 deletions scripts/ci/npm/publish-libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR=${DIR}/../../..
DIST_DIR=${ROOT_DIR}/dist/@alfresco
PROJECTS_DIR=${ROOT_DIR}/projects

DRY_RUN=""
if [ "$PUBLISH_PROJECTS" = "false" ]; then
DRY_RUN=true
echo "PUBLISH_PROJECTS is set to false, run in dry mode"
fi

VERSION_IN_PACKAGE_JSON=`node -p "require('$ROOT_DIR/package.json')".version;`;

if [[ $TRAVIS_BRANCH =~ ^master.*?$ ]] ; then
NEW_LIBRARY_VERSION=VERSION_IN_PACKAGE_JSON
else
NEW_LIBRARY_VERSION="${VERSION_IN_PACKAGE_JSON}-${TRAVIS_BUILD_NUMBER}"
fi

if [[ $TRAVIS_BRANCH =~ ^master(-patch.*)?$ ]]
then
# Pre-release versions
if [[ $VERSION_IN_PACKAGE_JSON =~ ^[0-9]*\.[0-9]*\.[0-9]*-A\.[0-9]*$ ]];
then
TAG_NPM=next
# Stable major versions
else
TAG_NPM=latest
fi
fi

if [[ $TRAVIS_BRANCH =~ ^develop(-patch.*)?$ ]]
then
TAG_NPM=alpha
fi

echo -e "Branch is '$TRAVIS_BRANCH', therefore publish with '$TAG_NPM' tag\n"

PROJECTS=(
'aca-shared'
);

for PROJECT in "${PROJECTS[@]}"
do
echo "Update ${PROJECT} version to ${NEW_LIBRARY_VERSION}"

cd $PROJECTS_DIR/${PROJECT}
npm version ${NEW_LIBRARY_VERSION};
done

echo -e "\n\nBuild projects"
cd ${ROOT_DIR}

npm run build-libs

for PROJECT in "${PROJECTS[@]}"
do
cd $DIST_DIR/${PROJECT}
PREVIOUS_LIBRARY_VERSION=$(npm view @alfresco/${PROJECT} version)

if [ "$DRY_RUN" = "true" ] ; then
echo -e "Publish with dry mode for project: $PROJECT\n"
echo -e "npm publish --dry-run --tag $TAG_NPM \n"

npm publish --dry-run --tag $TAG_NPM

echo -e "Deprecating old version of @alfresco/$PROJECT the old version is $PREVIOUS_LIBRARY_VERSION\n"

echo "npm deprecate @alfresco/$PROJECT@$PREVIOUS_LIBRARY_VERSION 'Upgrade to @latest or $NEW_LIBRARY_VERSION'"
else
echo -e "Publish $PROJECT\n"
echo -e "npm publish --tag $TAG_NPM\n"

echo 'strict-ssl=false' >> .npmrc
echo 'registry=http://${NPM_REGISTRY_ADDRESS}' >> .npmrc
echo '//${NPM_REGISTRY_ADDRESS}/:_authToken="${NPM_REGISTRY_TOKEN}"' >> .npmrc

npm publish --tag $TAG_NPM
npm deprecate "@alfresco/$PROJECT@$PREVIOUS_LIBRARY_VERSION" "Upgrade to @latest or $NEW_LIBRARY_VERSION"
fi
done

0 comments on commit a8268c6

Please sign in to comment.