Skip to content

Commit

Permalink
Merge 0785cee into fd59763
Browse files Browse the repository at this point in the history
  • Loading branch information
wongvincent committed Jan 3, 2019
2 parents fd59763 + 0785cee commit 6de9952
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 87 deletions.
36 changes: 15 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,36 @@ These include: `Version`, `EventId`, `Timestamp`, `TenantId`, `EventBody.Timesta

### Setup

Install from Bower:
Install `d2l-telemetry-browser-client` via NPM:

```shell
bower install Brightspace/d2l-telemetry-browser-client
npm install Brightspace/d2l-telemetry-browser-client
```

Then import `d2l-telemetry-browser-client.html`:
#### NPM

```html
<link rel="import" href="../d2l-telemetry-browser-client/d2l-telemetry-browser-client.html">
In NPM, require it normally:

```javascript
const d2lTelemetryBrowserClient = require('d2l-telemetry-browser-client');
```

The HTML import will reference the library from the CDN, but using bower and html imports will allow you to de-dupe different versions.
#### ES6

Alternatively you can reference it directly from the CDN
In ES6, use an `import` statement:

```html
<script src="https://s.brightspace.com/lib/d2l-telemetry-browser-client/0.1.0/d2l-telemetry-browser-client.js"></script>
```javascript
import d2lTelemetryBrowserClient from 'd2l-telemetry-browser-client';
```

Finally reference the library using the global variable `d2lTelemetryBrowserClient`

The client uses [`d2l-fetch`](https://github.com/Brightspace/d2l-fetch) for making the API requests to the telemetry service.
See the [`d2l-fetch browser compatibility`](https://github.com/Brightspace/d2l-fetch#browser-compatibility) instructions for additional requirements.

### Use

```js

const client = new window.d2lTelemetryBrowserClient.Client({
const client = new d2lTelemetryBrowserClient.Client({
endpoint
});

Expand All @@ -69,11 +69,11 @@ const id = 'http://prd.activityfeed.us-east-1.brightspace.com/api/v1/d2l:orgUnit
// by current BDP processing. Even though these events are not yet going to BDP, suggestion
// is to either use an internal identifier or encode the URL.
// The URL is included as a new EventBody.Object.Url property.
const eventBody = new window.d2lTelemetryBrowserClient.EventBody()
const eventBody = new d2lTelemetryBrowserClient.EventBody()
.setAction('Created')
.setObject(encodeURIComponent(id), 'Article', id);

const event = new window.d2lTelemetryBrowserClient.TelemetryEvent()
const event = new d2lTelemetryBrowserClient.TelemetryEvent()
.setDate(new Date())
.setType('TelemetryEvent')
.setSourceId('activityfeed')
Expand All @@ -92,15 +92,9 @@ yarn install
yarn run test
```

This library builds a de-umdified browserify bundle that is exposed on the global object as `d2lTelemetryBrowserClient`.

### Publishing

The Travis CI build on master branch will bump the version of the library, publish the dist/ bundle to the CDN and commit an updated `./d2l-telemetry-browser-client.html` html import file referencing the CDN library back to the repo.

Refer to `./update.sh` and `./travis.yml` for details on how this publish process works.

You can control the level of verison bump by including either `[increment major]` or `[increment patch]` in your commit message. By default it will increment minor.
You can control the level of version bump by including either `[increment major]` or `[increment patch]` in your commit message. By default it will increment minor.


[ci-url]: https://travis-ci.org/Brightspace/d2l-telemetry-browser-client
Expand Down
26 changes: 0 additions & 26 deletions bower.json

This file was deleted.

3 changes: 0 additions & 3 deletions d2l-telemetry-browser-client.html

This file was deleted.

21 changes: 2 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d2l-telemetry-browser-client",
"version": "0.0.1",
"version": "1.0.0",
"description": "Client for sending telemetry from the browser to a telemetry service",
"private": true,
"main": "src/index.js",
Expand All @@ -13,30 +13,14 @@
"test:bundle": "karma start karma-bundle.conf.js",
"test:unit": "cross-env NODE_ENV=test karma start karma.conf.js",
"test:sauce": "cross-env NODE_ENV=test karma start karma-sauce.conf.js",
"report-coverage": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"publish-location": "node publishLocation",
"prepublish-release": "npm run build",
"publish-release": "frau-publisher && npm run publish-location"
"report-coverage": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
},
"repository": {
"type": "git",
"url": "https://github.com/Brightspace/d2l-telemetry-browser-client.git"
},
"author": "D2L Corporation",
"license": "Apache-2.0",
"config": {
"frauPublisher": {
"files": "./dist/**",
"moduleType": "lib",
"targetDirectory": "d2l-telemetry-browser-client",
"creds": {
"key": "AKIAIA66UIEEOZM63VEQ",
"secretVar": "CDN_SECRET"
},
"devTagVar": "TRAVIS_COMMIT",
"versionVar": "TRAVIS_TAG"
}
},
"devDependencies": {
"babel-plugin-istanbul": "^4.1.5",
"babel-preset-env": "^1.6.1",
Expand All @@ -50,7 +34,6 @@
"deumdify": "^1.2.5",
"eslint": "^4.15.0",
"eslint-config-brightspace": "^0.3.1",
"frau-publisher": "^2.6.2",
"karma": "^2.0.0",
"karma-browserify": "^5.1.3",
"karma-chai": "^0.1.0",
Expand Down
1 change: 0 additions & 1 deletion publishLocation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
var publisherOptions = require('./package.json').config.frauPublisher;
publisherOptions.devTag = process.env.TRAVIS_COMMIT || publisherOptions.devTagVar;
publisherOptions.version = process.env.TRAVIS_TAG;
Expand Down
12 changes: 7 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import {EventBody} from './eventBody';
import {PerformanceEventBody} from './performanceEventBody';
import {ProblemEventBody} from './problemEventBody';

module.exports.Client = Client;
module.exports.TelemetryEvent = TelemetryEvent;
module.exports.EventBody = EventBody;
module.exports.PerformanceEventBody = PerformanceEventBody;
module.exports.ProblemEventBody = ProblemEventBody;
export {
Client,
TelemetryEvent,
EventBody,
PerformanceEventBody,
ProblemEventBody
};
13 changes: 1 addition & 12 deletions update.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash
set -e

echo "Generating HTML import and publishing to CDN"

if ! [ "$TRAVIS_BRANCH" == "master" ] || ! [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
echo "Version is only bumped on master"
exit 0
Expand Down Expand Up @@ -52,9 +50,7 @@ git config --global user.email "travis@travis-ci.com"
git config --global user.name "Travis CI"

echo "Updating from ${lastVersion} to v${newVersion}"
echo "<!-- CHANGES TO THIS FILE WILL BE LOST - IT IS AUTOMATICALLY GENERATED WHEN d2l-telemetry-browser-client IS RELEASED -->" > d2l-telemetry-browser-client.html
echo "<script src=\"https://s.brightspace.com/lib/d2l-telemetry-browser-client/"$newVersion"/d2l-telemetry-browser-client.js\"></script>" >> d2l-telemetry-browser-client.html
echo "<link rel=\"import\" href=\"../d2l-fetch/d2l-fetch.html\">" >> d2l-telemetry-browser-client.html
sed -i "s/\"version\": \".*\"/\"version\": \""$newVersion"\"/" package.json

# Add the updated d2l-telemetry-browser-client.html, and add a new tag to create the release
git add .
Expand All @@ -63,12 +59,5 @@ git commit -m "[skip ci] Update to v${newVersion}"
echo "About to tag new version"
git tag -a v${newVersion} -m "v${newVersion} - ${lastLogMessageShort}"

echo "git status"
git status

echo "push new tag"
git push upstream HEAD:master --tags

# Publish the release via frau-publisher
export TRAVIS_TAG=$newVersion
npm run publish-release

0 comments on commit 6de9952

Please sign in to comment.