1 | varsnap.js
|
2 | ==========
|
3 |
|
4 | [![Codeship Status for albertyw/varsnap.js](https://app.codeship.com/projects/772d6dd0-7616-0137-b181-4a74f06c083c/status?branch=master)](https://app.codeship.com/projects/349777)
|
5 |
|
6 | [Python Varsnap Client](https://www.varsnap.com/). For use in both browser and node.js
|
7 |
|
8 | Installation
|
9 | ------------
|
10 |
|
11 | Install from NPM - `npm install --save varsnap`
|
12 |
|
13 | Configuration
|
14 | -------------
|
15 |
|
16 | The varsnap decorator needs to be configured with a `config` object with these variables:
|
17 |
|
18 | - `varsnap` - Should be either `true` or `false`. Varsnap will be disabled if the variable is anything other than `true`.
|
19 | - `env` - If set to `development`, the client will receive events from production. If set to `production`, the client will emit events.
|
20 | - `producerToken` - Only clients with this token may emit production snapshots. Copied from https://www.varsnap.com/user/
|
21 | - `consumerToken` - Only clients with this token may emit development snapshots. Copied from https://www.varsnap.com/user/
|
22 |
|
23 | If you're deploying varsnap to a browser, note that Varsnap needs unmangled code in production to work correctly.
|
24 |
|
25 | Usage
|
26 | -----
|
27 |
|
28 | Wrap your functions with the varsnap decorator for any function you'd like to make better:
|
29 |
|
30 | ```javascript
|
31 | // Node.js
|
32 | var varsnap = require('varsnap');
|
33 |
|
34 | // Browser
|
35 | var varsnap = window.varsnap;
|
36 |
|
37 | // Configuration
|
38 | varsnap.updateConfig({
|
39 | varsnap: true,
|
40 | env: 'production',
|
41 | producerToken: 'producer-abcd'
|
42 | });
|
43 |
|
44 | // Integration
|
45 | function example(x, y, z) {
|
46 | // ...
|
47 | }
|
48 | example = varsnap(example);
|
49 |
|
50 | example(1, 2, 3);
|
51 | ```
|
52 |
|
53 | See `example/example.js` for example usage.
|
54 |
|
55 | Typescript
|
56 | ----------
|
57 | If you are using typescript, make sure your `tsconfig.json` has a `"target"` to `"es2015"`, `"es6"`, or later.
|
58 | This is needed to persist function names after compiling to javascript.
|
59 | See https://github.com/microsoft/TypeScript/issues/5611 for details.
|
60 |
|
61 | Testing
|
62 | -------
|
63 |
|
64 | Use the `varsnap.runTests()` function.
|
65 |
|
66 | ```javascript
|
67 | function test() {
|
68 | const status = varsnap.runTests().then(function(status) => {
|
69 | console.assert(status);
|
70 | });;
|
71 | }
|
72 | ```
|
73 |
|
74 | If you are using [mocha](https://mochajs.org/) and [chai](https://www.chaijs.com/),
|
75 | you can include this test script:
|
76 |
|
77 | ```javascript
|
78 | const expect = require('chai').expect;
|
79 | const varsnap = require('varsnap');
|
80 |
|
81 | // Load the modules where varsnap is being used
|
82 | require('./example');
|
83 |
|
84 | context('Varsnap', function() {
|
85 | this.timeout(30 * 1000);
|
86 | it('runs with production', function() {
|
87 | return varsnap.runTests().then(status => {
|
88 | expect(status).to.be.true;
|
89 | });
|
90 | });
|
91 | });
|
92 | ```
|
93 |
|
94 | See `example/test.js` for example usage.
|
95 |
|
96 | Release
|
97 | -------
|
98 |
|
99 | 1. Update Changelog with new version
|
100 | 2. Update `const version` in `varsnap/core.ts`
|
101 | 3. Update package.json version and run `npm install`
|
102 | 4. Update `.uglify.json` and `.uglify.min.json`
|
103 | 5. Run `npm run package`
|
104 | 6. Git commit and tag
|
105 | 7. `npm publish`
|
106 | 8. Upload `dist/*` to https://github.com/albertyw/varsnap.js/releases
|