particle-api-js 9.4.1 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/.circleci/config.yml +7 -5
  2. package/CHANGELOG.md +11 -0
  3. package/{test/EventStream-e2e-browser.html → EventStream-e2e-browser.html} +0 -1
  4. package/{test/EventStream-e2e-node.js → EventStream-e2e-node.js} +2 -3
  5. package/README.md +2 -2
  6. package/RELEASE.md +1 -1
  7. package/dist/particle.min.js +1 -399
  8. package/dist/particle.min.js.map +1 -1
  9. package/docs/api.md +5223 -115
  10. package/fs.js +2 -0
  11. package/karma.conf.js +18 -6
  12. package/package.json +23 -26
  13. package/src/Agent.js +407 -0
  14. package/src/Client.js +170 -0
  15. package/src/Defaults.js +7 -0
  16. package/src/EventStream.js +263 -0
  17. package/src/Library.js +33 -0
  18. package/src/Particle.js +2644 -0
  19. package/test/Agent.integration.js +5 -4
  20. package/test/Agent.spec.js +174 -291
  21. package/test/Client.spec.js +7 -7
  22. package/test/Defaults.spec.js +2 -2
  23. package/test/EventStream.spec.js +6 -4
  24. package/test/FakeAgent.js +2 -2
  25. package/test/Library.spec.js +2 -2
  26. package/test/Particle.integration.js +7 -7
  27. package/test/Particle.spec.js +332 -18
  28. package/test/fixtures/index.js +4 -18
  29. package/test/support/FixtureHttpServer.js +5 -3
  30. package/test/test-setup.js +5 -5
  31. package/tsconfig.json +14 -0
  32. package/webpack.config.js +45 -0
  33. package/.babelrc +0 -4
  34. package/lib/Agent.js +0 -516
  35. package/lib/Agent.js.map +0 -1
  36. package/lib/Client.js +0 -312
  37. package/lib/Client.js.map +0 -1
  38. package/lib/Defaults.js +0 -14
  39. package/lib/Defaults.js.map +0 -1
  40. package/lib/EventStream.js +0 -335
  41. package/lib/EventStream.js.map +0 -1
  42. package/lib/Library.js +0 -67
  43. package/lib/Library.js.map +0 -1
  44. package/lib/Particle.js +0 -3248
  45. package/lib/Particle.js.map +0 -1
  46. package/lib/superagent-binary-parser.js +0 -20
  47. package/lib/superagent-binary-parser.js.map +0 -1
  48. package/test/Client.integration.js +0 -69
  49. package/test/fixtures/tarball.tar.gz +0 -0
  50. package/test/fixtures/test-library-publish-0.0.1.tar.gz +0 -0
  51. package/test/fixtures/test-library-publish-0.0.2.tar.gz +0 -0
@@ -1,7 +1,7 @@
1
- import { expect, sinon } from './test-setup';
2
- import Client from '../src/Client';
3
- import * as fixtures from './fixtures';
4
- import Library from '../src/Library';
1
+ const { expect, sinon } = require('./test-setup');
2
+ const Client = require('../src/Client');
3
+ const fixtures = require('./fixtures');
4
+ const Library = require('../src/Library');
5
5
 
6
6
  let api;
7
7
  const token = 'tok';
@@ -25,7 +25,7 @@ describe('Client', () => {
25
25
 
26
26
  describe('libraries', () => {
27
27
  it('resolves to a list of Library objects', () => {
28
- api.listLibraries = () => Promise.resolve({ body: fixtures.readJSON('libraries.json') });
28
+ api.listLibraries = () => Promise.resolve({ body: fixtures.read('libraries.json') });
29
29
  return client.libraries().then(libraries => {
30
30
  expect(libraries.length).to.equal(1);
31
31
  expect(libraries[0].name).to.equal('neopixel');
@@ -35,7 +35,7 @@ describe('Client', () => {
35
35
 
36
36
  describe('library', () => {
37
37
  it('resolves to a Library objects', () => {
38
- api.getLibrary = () => Promise.resolve({ body: fixtures.readJSON('library.json') });
38
+ api.getLibrary = () => Promise.resolve({ body: fixtures.read('library.json') });
39
39
  return client.library('neopixel').then(library => {
40
40
  expect(library.name).to.equal('neopixel');
41
41
  });
@@ -44,7 +44,7 @@ describe('Client', () => {
44
44
 
45
45
  describe('libraryVersions', () => {
46
46
  it('resolves to a Library objects', () => {
47
- api.getLibraryVersions = () => Promise.resolve({ body: fixtures.readJSON('libraryVersions.json') });
47
+ api.getLibraryVersions = () => Promise.resolve({ body: fixtures.read('libraryVersions.json') });
48
48
  return client.libraryVersions().then(libraries => {
49
49
  expect(libraries.length).to.equal(9);
50
50
  expect(libraries[0].name).to.equal('neopixel');
@@ -1,5 +1,5 @@
1
- import { expect } from './test-setup';
2
- import Defaults from '../src/Defaults';
1
+ const { expect } = require('./test-setup');
2
+ const Defaults = require('../src/Defaults');
3
3
 
4
4
  describe('Default Particle constructor options', () => {
5
5
  it('includes baseUrl', () => {
@@ -1,8 +1,8 @@
1
- import { sinon, expect } from './test-setup';
2
- import http from 'http';
3
- import { EventEmitter } from 'events';
1
+ const { sinon, expect } = require('./test-setup');
2
+ const http = require('http');
3
+ const { EventEmitter } = require('events');
4
4
 
5
- import EventStream from '../src/EventStream';
5
+ const EventStream = require('../src/EventStream');
6
6
 
7
7
  describe('EventStream', () => {
8
8
  afterEach(() => {
@@ -32,6 +32,7 @@ describe('EventStream', () => {
32
32
 
33
33
  describe('connect', () => {
34
34
  it('successfully connects to http', () => {
35
+ sinon.useFakeTimers({ shouldAdvanceTime: true });
35
36
  const fakeRequest = makeRequest();
36
37
  sinon.stub(http, 'request').callsFake(() => {
37
38
  setImmediate(() => {
@@ -57,6 +58,7 @@ describe('EventStream', () => {
57
58
  });
58
59
 
59
60
  it('returns http errors on connect', () => {
61
+ sinon.useFakeTimers({ shouldAdvanceTime: true });
60
62
  const fakeRequest = makeRequest();
61
63
  sinon.stub(http, 'request').callsFake(() => {
62
64
  setImmediate(() => {
package/test/FakeAgent.js CHANGED
@@ -1,4 +1,4 @@
1
- export default class FakeAgent {
1
+ class FakeAgent {
2
2
  get({ uri, auth, headers, query, context }){
3
3
  return this.request({ uri, method: 'get', auth, headers, query, context });
4
4
  }
@@ -23,4 +23,4 @@ export default class FakeAgent {
23
23
  return new Promise((resolve) => resolve(opts));
24
24
  }
25
25
  }
26
-
26
+ module.exports = FakeAgent;
@@ -1,5 +1,5 @@
1
- import { expect } from './test-setup';
2
- import Library from '../src/Library';
1
+ const { expect } = require('./test-setup');
2
+ const Library = require('../src/Library');
3
3
 
4
4
  let client = {};
5
5
 
@@ -1,17 +1,16 @@
1
- import { expect, sinon } from './test-setup';
2
- import Particle from '../src/Particle';
3
-
1
+ const { expect, sinon } = require('./test-setup');
2
+ const Particle = require('../src/Particle');
4
3
 
5
4
  describe('Particle', () => {
6
5
  let api;
7
6
 
8
7
  beforeEach(() => {
9
- api = new Particle();
8
+ api = new Particle({ baseUrl: '' });
10
9
  });
11
10
 
12
11
  describe('downloadFile', () => {
13
12
  it('download the file', () => {
14
- const uri = 'https://s3.amazonaws.com/binaries.particle.io/libraries/neopixel/neopixel-0.0.10.tar.gz';
13
+ const uri = 'https://binaries.particle.io/libraries/neopixel/neopixel-0.0.10.tar.gz';
15
14
  const fileSize = 25505;
16
15
  return api.downloadFile({ uri })
17
16
  .then(contents => {
@@ -28,9 +27,10 @@ describe('Particle', () => {
28
27
  return api.flashTinker('deviceID', 'auth').then(() => {
29
28
  expect(api.agent._promiseResponse).to.have.been.calledOnce;
30
29
  const req = api.agent._promiseResponse.firstCall.args[0];
30
+ const options = req[1];
31
31
  expect(req).to.be.ok;
32
- expect(req.header).to.have.property('X-Particle-Tool').eql('cli@1.2.3');
33
- expect(req.header).to.have.property('X-Particle-Project').eql('blinky; version=0.0.1');
32
+ expect(options.headers).to.have.property('X-Particle-Tool').eql('cli@1.2.3');
33
+ expect(options.headers).to.have.property('X-Particle-Project').eql('blinky; version=0.0.1');
34
34
  });
35
35
  });
36
36
  });
@@ -1,10 +1,10 @@
1
- import should from 'should'; // monkeypatch the world~!1
2
- import Particle from '../src/Particle';
3
- import Defaults from '../src/Defaults';
4
- import Client from '../src/Client';
5
- import EventStream from '../src/EventStream';
6
- import FakeAgent from './FakeAgent';
7
- import { sinon, expect } from './test-setup';
1
+ const should = require('should'); // monkeypatch the world~!1
2
+ const Particle = require('../src/Particle');
3
+ const Defaults = require('../src/Defaults');
4
+ const Client = require('../src/Client');
5
+ const EventStream = require('../src/EventStream');
6
+ const FakeAgent = require('./FakeAgent');
7
+ const { sinon, expect } = require('./test-setup');
8
8
 
9
9
  let api;
10
10
 
@@ -95,12 +95,49 @@ const props = {
95
95
  groups: ['foo', 'bar'],
96
96
  dateRange: '2020-05-15T18:29:45.000Z,2020-05-19T18:29:45.000Z',
97
97
  rectBl: '56.185412,-4.049868',
98
- rectTr: '56.571537,-5.385920'
98
+ rectTr: '56.571537,-5.385920',
99
+ blockId: 1,
100
+ runId: 1,
101
+ block: {
102
+ enabled: true,
103
+ name: 'block-1',
104
+ description: 'hello world',
105
+ logic: {
106
+ type: 'JavaScript',
107
+ code: 'console.log("hello from block-1");'
108
+ },
109
+ matchers: [
110
+ {
111
+ type: 'PubSub',
112
+ enabled: true,
113
+ product_id: 9001,
114
+ event_name: 'main',
115
+ },
116
+ {
117
+ type: 'Chron',
118
+ enabled: true,
119
+ cron: '0 0 1 * *',
120
+ start_at: '2021-05-15T18:29:45.000Z',
121
+ end_at: '2021-05-19T18:29:45.000Z',
122
+ }
123
+ ]
124
+ },
125
+ ledgerName: 'myledger',
126
+ ledger: {
127
+ scope: 'Owner',
128
+ name: 'myledger',
129
+ description: 'my ledger',
130
+ direction: 'Downstream'
131
+ },
132
+ scopeValue: '1234'
99
133
  };
100
134
 
101
135
  const product = 'ze-product-v1';
102
136
  const propsWithProduct = Object.assign({ product }, props);
103
137
 
138
+ const org = 'test-org';
139
+ const propsWithOrg = Object.assign({ org }, props);
140
+
104
141
  class Common {
105
142
  static expectCredentials({ form }){
106
143
  form.username.should.equal(props.username);
@@ -854,15 +891,15 @@ describe('ParticleAPI', () => {
854
891
 
855
892
  describe('.downloadFirmwareBinary', () => {
856
893
  it('generates request', () => {
857
- sinon.stub(api, '_provideFileData').callsFake(x => Promise.resolve(x));
894
+ sinon.stub(api, 'request').callsFake(x => Promise.resolve(x));
858
895
  const req = api.downloadFirmwareBinary(propsWithProduct);
859
- api._provideFileData.callCount.should.equal(1);
896
+ api.request.callCount.should.equal(1);
860
897
  return req.then((results) => {
861
898
  results.should.match({
862
899
  uri: `/v1/binaries/${props.binaryId}`,
863
900
  method: 'get',
864
901
  auth: props.auth,
865
- raw: true
902
+ isBuffer: true
866
903
  });
867
904
  });
868
905
  });
@@ -1916,12 +1953,12 @@ describe('ParticleAPI', () => {
1916
1953
 
1917
1954
  describe('.downloadFile', () => {
1918
1955
  it('generates request', () => {
1919
- sinon.stub(api, '_provideFileData').callsFake(x => Promise.resolve(x));
1956
+ sinon.stub(api, 'request').callsFake(x => Promise.resolve(x));
1920
1957
  const uri = 'http://example.com/path/to/file.png';
1921
1958
  const req = api.downloadFile({ uri });
1922
- api._provideFileData.callCount.should.equal(1);
1959
+ api.request.callCount.should.equal(1);
1923
1960
  return req.then((results) => {
1924
- results.should.match({ uri, method: 'get', raw: true });
1961
+ results.should.match({ uri, method: 'get', isBuffer: true });
1925
1962
  });
1926
1963
  });
1927
1964
  });
@@ -2137,17 +2174,17 @@ describe('ParticleAPI', () => {
2137
2174
 
2138
2175
  describe('.downloadProductFirmware', () => {
2139
2176
  it('generates request', () => {
2140
- sinon.stub(api, '_provideFileData').callsFake(x => Promise.resolve(x));
2177
+ sinon.stub(api, 'request').callsFake(x => Promise.resolve(x));
2141
2178
  const req = api.downloadProductFirmware(propsWithProduct);
2142
- api._provideFileData.callCount.should.equal(1);
2179
+ api.request.callCount.should.equal(1);
2143
2180
  return req.then((results) => {
2144
2181
  results.should.match({
2145
2182
  uri: `/v1/products/${product}/firmware/${props.version}/binary`,
2146
2183
  method: 'get',
2147
2184
  auth: props.auth,
2148
2185
  headers: props.headers,
2149
- context: {},
2150
- raw: true
2186
+ context: undefined,
2187
+ isBuffer: true
2151
2188
  });
2152
2189
  });
2153
2190
  });
@@ -2537,6 +2574,154 @@ describe('ParticleAPI', () => {
2537
2574
  });
2538
2575
  });
2539
2576
 
2577
+ describe('.createLogicBlock', () => {
2578
+ it('generates request', () => {
2579
+ return api.createLogicBlock(propsWithOrg).then((results) => {
2580
+ results.should.match({
2581
+ method: 'post',
2582
+ uri: `/v1/orgs/${org}/blocks`,
2583
+ auth: props.auth,
2584
+ data: {
2585
+ block: {
2586
+ enabled: true,
2587
+ name: 'block-1',
2588
+ description: 'hello world',
2589
+ logic: {
2590
+ type: 'JavaScript',
2591
+ code: 'console.log("hello from block-1");'
2592
+ },
2593
+ matchers: [
2594
+ {
2595
+ type: 'PubSub',
2596
+ enabled: true,
2597
+ product_id: parseInt(props.productId),
2598
+ event_name: props.event,
2599
+ },
2600
+ {
2601
+ type: 'Chron',
2602
+ enabled: true,
2603
+ cron: '0 0 1 * *',
2604
+ start_at: '2021-05-15T18:29:45.000Z',
2605
+ end_at: '2021-05-19T18:29:45.000Z',
2606
+ }
2607
+ ]
2608
+ }
2609
+ }
2610
+ });
2611
+ });
2612
+ });
2613
+ });
2614
+
2615
+ describe('.getLogicBlock', () => {
2616
+ it('generates request', () => {
2617
+ return api.getLogicBlock(propsWithOrg).then((results) => {
2618
+ results.should.match({
2619
+ method: 'get',
2620
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}`,
2621
+ auth: props.auth
2622
+ });
2623
+ });
2624
+ });
2625
+ });
2626
+
2627
+ describe('.updateLogicBlock', () => {
2628
+ it('generates request', () => {
2629
+ return api.updateLogicBlock(propsWithOrg).then((results) => {
2630
+ results.should.match({
2631
+ method: 'put',
2632
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}`,
2633
+ auth: props.auth,
2634
+ data: {
2635
+ block: {
2636
+ enabled: true,
2637
+ name: 'block-1',
2638
+ description: 'hello world',
2639
+ logic: {
2640
+ type: 'JavaScript',
2641
+ code: 'console.log("hello from block-1");'
2642
+ },
2643
+ matchers: [
2644
+ {
2645
+ type: 'PubSub',
2646
+ enabled: true,
2647
+ product_id: parseInt(props.productId),
2648
+ event_name: props.event,
2649
+ },
2650
+ {
2651
+ type: 'Chron',
2652
+ enabled: true,
2653
+ cron: '0 0 1 * *',
2654
+ start_at: '2021-05-15T18:29:45.000Z',
2655
+ end_at: '2021-05-19T18:29:45.000Z',
2656
+ }
2657
+ ]
2658
+ }
2659
+ }
2660
+ });
2661
+ });
2662
+ });
2663
+ });
2664
+
2665
+ describe('.deleteLogicBlock', () => {
2666
+ it('generates request', () => {
2667
+ return api.deleteLogicBlock(propsWithOrg).then((results) => {
2668
+ results.should.match({
2669
+ method: 'delete',
2670
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}`,
2671
+ auth: props.auth
2672
+ });
2673
+ });
2674
+ });
2675
+ });
2676
+
2677
+ describe('.listLogicBlocks', () => {
2678
+ it('generates request', () => {
2679
+ return api.listLogicBlocks(propsWithOrg).then((results) => {
2680
+ results.should.match({
2681
+ method: 'get',
2682
+ uri: `/v1/orgs/${org}/blocks`,
2683
+ auth: props.auth
2684
+ });
2685
+ });
2686
+ });
2687
+ });
2688
+
2689
+ describe('.listBlockRuns', () => {
2690
+ it('generates request', () => {
2691
+ return api.listBlockRuns(propsWithOrg).then((results) => {
2692
+ results.should.match({
2693
+ method: 'get',
2694
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}/runs`,
2695
+ auth: props.auth,
2696
+ });
2697
+ });
2698
+ });
2699
+ });
2700
+
2701
+ describe('.getBlockRun', () => {
2702
+ it('generates request', () => {
2703
+ return api.getBlockRun(propsWithOrg).then((results) => {
2704
+ results.should.match({
2705
+ method: 'get',
2706
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}/runs/${props.runId}`,
2707
+ auth: props.auth,
2708
+ });
2709
+ });
2710
+ });
2711
+ });
2712
+
2713
+ describe('.getBlockRunLog', () => {
2714
+ it('generates request', () => {
2715
+ return api.getBlockRunLog(propsWithOrg).then((results) => {
2716
+ results.should.match({
2717
+ method: 'get',
2718
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}/runs/${props.runId}/logs`,
2719
+ auth: props.auth,
2720
+ });
2721
+ });
2722
+ });
2723
+ });
2724
+
2540
2725
  describe('.deleteUser', () => {
2541
2726
  it('sends request to delete the current user', () => {
2542
2727
  return api.deleteUser(props).then(result => {
@@ -2550,6 +2735,135 @@ describe('ParticleAPI', () => {
2550
2735
  });
2551
2736
  });
2552
2737
  });
2738
+
2739
+ describe('.createLedger', () => {
2740
+ it('generates request', () => {
2741
+ return api.createLedger(propsWithOrg).then((results) => {
2742
+ results.should.match({
2743
+ method: 'post',
2744
+ uri: `/v1/orgs/${org}/ledgers`,
2745
+ auth: props.auth,
2746
+ data: {
2747
+ ledger: {
2748
+ scope: 'Owner',
2749
+ name: 'myledger',
2750
+ description: 'my ledger',
2751
+ direction: 'Downstream'
2752
+ }
2753
+ }
2754
+ });
2755
+ });
2756
+ });
2757
+ });
2758
+
2759
+ describe('.getLedger', () => {
2760
+ it('generates request', () => {
2761
+ return api.getLedger(propsWithOrg).then((results) => {
2762
+ results.should.match({
2763
+ method: 'get',
2764
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}`,
2765
+ auth: props.auth
2766
+ });
2767
+ });
2768
+ });
2769
+ });
2770
+
2771
+ describe('.updateLedger', () => {
2772
+ it('generates request', () => {
2773
+ return api.updateLedger(propsWithOrg).then((results) => {
2774
+ results.should.match({
2775
+ method: 'put',
2776
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}`,
2777
+ auth: props.auth,
2778
+ data: {
2779
+ ledger: {
2780
+ scope: 'Owner',
2781
+ name: 'myledger',
2782
+ description: 'my ledger',
2783
+ direction: 'Downstream'
2784
+ }
2785
+ }
2786
+ });
2787
+ });
2788
+ });
2789
+ });
2790
+
2791
+ describe('.archiveLedger', () => {
2792
+ it('generates request', () => {
2793
+ return api.archiveLedger(propsWithOrg).then((results) => {
2794
+ results.should.match({
2795
+ method: 'delete',
2796
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}`,
2797
+ auth: props.auth
2798
+ });
2799
+ });
2800
+ });
2801
+ });
2802
+
2803
+ describe('.listLedgers', () => {
2804
+ it('generates request', () => {
2805
+ return api.listLedgers(propsWithOrg).then((results) => {
2806
+ results.should.match({
2807
+ method: 'get',
2808
+ uri: `/v1/orgs/${org}/ledgers`,
2809
+ auth: props.auth
2810
+ });
2811
+ });
2812
+ });
2813
+ });
2814
+
2815
+ describe('.getLedgerInstance', () => {
2816
+ it('generates request', () => {
2817
+ return api.getLedgerInstance(propsWithOrg).then((results) => {
2818
+ results.should.match({
2819
+ method: 'get',
2820
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}/instances/${props.scopeValue}`,
2821
+ auth: props.auth
2822
+ });
2823
+ });
2824
+ });
2825
+ });
2826
+
2827
+ describe('.setLedgerInstance', () => {
2828
+ it('generates request', () => {
2829
+ return api.setLedgerInstance(propsWithOrg).then((results) => {
2830
+ results.should.match({
2831
+ method: 'put',
2832
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}/instances/${props.scopeValue}`,
2833
+ auth: props.auth,
2834
+ data: {
2835
+ data: {
2836
+ sentient: true
2837
+ }
2838
+ }
2839
+ });
2840
+ });
2841
+ });
2842
+ });
2843
+
2844
+ describe('.deleteLedgerInstance', () => {
2845
+ it('generates request', () => {
2846
+ return api.deleteLedgerInstance(propsWithOrg).then((results) => {
2847
+ results.should.match({
2848
+ method: 'delete',
2849
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}/instances/${props.scopeValue}`,
2850
+ auth: props.auth
2851
+ });
2852
+ });
2853
+ });
2854
+ });
2855
+
2856
+ describe('.listLedgerInstances', () => {
2857
+ it('generates request', () => {
2858
+ return api.listLedgerInstances(propsWithOrg).then((results) => {
2859
+ results.should.match({
2860
+ method: 'get',
2861
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}/instances`,
2862
+ auth: props.auth
2863
+ });
2864
+ });
2865
+ });
2866
+ });
2553
2867
  });
2554
2868
 
2555
2869
  describe('backwards-compatibility function aliases', () => {
@@ -1,16 +1,8 @@
1
- /* In order for the tests to run in the browser the fixture files must
2
- * be loaded statically into an object. The 'brfs' module will replace
3
- * the fs.readFileSync('static_path') call by the contents of the file.
4
- */
5
- const fs = require('fs'); // import syntax doesn't work inside karma
6
-
7
1
 
8
2
  const fixtures = {
9
- 'libraries.json': fs.readFileSync(__dirname + '/libraries.json'),
10
- 'library.json': fs.readFileSync(__dirname + '/library.json'),
11
- 'libraryVersions.json': fs.readFileSync(__dirname + '/libraryVersions.json'),
12
- 'test-library-publish-0.0.1.tar.gz': fs.readFileSync(__dirname + '/test-library-publish-0.0.1.tar.gz'),
13
- 'test-library-publish-0.0.2.tar.gz': fs.readFileSync(__dirname + '/test-library-publish-0.0.2.tar.gz'),
3
+ 'libraries.json': require('./libraries.json'),
4
+ 'library.json': require('./library.json'),
5
+ 'libraryVersions.json': require('./libraryVersions.json')
14
6
  };
15
7
 
16
8
  function read(filename) {
@@ -20,10 +12,4 @@ function read(filename) {
20
12
  return fixtures[filename];
21
13
  }
22
14
 
23
- function readJSON(filename) {
24
- return JSON.parse(read(filename));
25
- }
26
-
27
- export {
28
- read, readJSON
29
- };
15
+ module.exports = { read };
@@ -1,9 +1,9 @@
1
1
  // Serve files from the fixture folder
2
- import express from 'express';
3
- import * as fixtures from '../fixtures';
2
+ const express = require('express');
3
+ const fixtures = require('../fixtures');
4
4
 
5
5
 
6
- export default class FixtureHttpServer {
6
+ class FixtureHttpServer {
7
7
  constructor(){
8
8
  this.app = express();
9
9
  this.app.get('/:filename', (req, res) => {
@@ -23,3 +23,5 @@ export default class FixtureHttpServer {
23
23
  return `http://localhost:${this.server.address().port}`;
24
24
  }
25
25
  }
26
+
27
+ module.exports = FixtureHttpServer;
@@ -1,16 +1,16 @@
1
1
  // Set up the Mocha test framework with the Chai assertion library and
2
2
  // the Sinon mock library
3
3
 
4
- import chai from 'chai';
5
- import sinon from 'sinon';
6
- import sinonChai from 'sinon-chai';
7
- import chaiAsPromised from 'chai-as-promised';
4
+ const chai = require('chai');
5
+ const sinon = require('sinon');
6
+ const sinonChai = require('sinon-chai');
7
+ const chaiAsPromised = require('chai-as-promised');
8
8
 
9
9
  chai.use(sinonChai);
10
10
  chai.use(chaiAsPromised);
11
11
  const expect = chai.expect;
12
12
 
13
- export {
13
+ module.exports = {
14
14
  chai,
15
15
  sinon,
16
16
  expect
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "target": "es6",
5
+ "allowJs": true,
6
+ "checkJs": true,
7
+ "skipLibCheck": true,
8
+ "esModuleInterop": true,
9
+ "resolveJsonModule": true
10
+ },
11
+ "types": ["node"],
12
+ "include": [ "src" ],
13
+ "exclude": ["node_modules"]
14
+ }
@@ -0,0 +1,45 @@
1
+ const path = require('path');
2
+ const webpack = require('webpack');
3
+ const TerserPlugin = require('terser-webpack-plugin');
4
+
5
+ module.exports = (env) => {
6
+ return {
7
+ mode: env.mode,
8
+ target: 'web',
9
+ entry: './src/Particle.js',
10
+ devtool: 'source-map',
11
+ output: {
12
+ filename: `particle${env.mode === 'production' ? '.min' : ''}.js`,
13
+ path: path.resolve(__dirname, 'dist'),
14
+ clean: true,
15
+ library: {
16
+ name: 'Particle',
17
+ type: 'var'
18
+ }
19
+ },
20
+ optimization: {
21
+ minimize: env.mode === 'production',
22
+ minimizer: [new TerserPlugin({
23
+ extractComments: false,
24
+ terserOptions: {
25
+ format: {
26
+ comments: false
27
+ }
28
+ }
29
+ })]
30
+ },
31
+ resolve: {
32
+ fallback: {
33
+ buffer: require.resolve('buffer'),
34
+ events: require.resolve('events'),
35
+ url: require.resolve('url')
36
+ }
37
+ },
38
+ plugins: [
39
+ new webpack.ProvidePlugin({
40
+ Buffer: ['buffer', 'Buffer'],
41
+ process: 'process/browser',
42
+ })
43
+ ]
44
+ };
45
+ };