Skip to content

Commit 4fe0263

Browse files
authored
Merge pull request #68 from ibmtjbot/dev
new packaging as a hybrid ES6 / CommonJS module
2 parents 815e390 + 105e150 commit 4fe0263

19 files changed

+4527
-26
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"extends": [
77
"airbnb-base"
88
],
9+
"ignorePatterns": ["dist/**"],
910
"parser": "babel-eslint",
1011
"parserOptions": {
1112
"ecmaVersion": 12,

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ out
8282

8383
# Nuxt.js build / generate output
8484
.nuxt
85-
dist
85+
#dist
8686

8787
# Gatsby files
8888
.cache/

.jsdoc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"dictionaries": ["jsdoc"]
55
},
66
"source": {
7-
"include": ["lib", "package.json", "README.md"],
7+
"include": ["src", "package.json", "README.md"],
88
"includePattern": ".js$",
9-
"excludePattern": "(node_modules/|docs)"
9+
"excludePattern": "(node_modules/|docs|dist|__tests__)"
1010
},
1111
"plugins": [
1212
"plugins/markdown"

MIGRATING.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
## Migrating from 1.x to 2.x
44
There have been several significant changes to the 2.x release of TJBotLib that break compatability with the 1.x release. Please use this guide, the new [TJBot API docs](https://ibmtjbot.github.io/docs/tjbot/2.0.1/), and the [updated recipes](https://github.com/ibmtjbot/tjbot/tree/master/recipes) in the `tjbot` repository, to help you migrate your recipes to the new 2.x API.
55

6-
### ES6 Module
7-
TJBot is now packaged as an ES6 module, meaning it can be imported as follows:
6+
### ES6 / CommonJS Hybrid Module
7+
TJBotLib is now packaged as hybrid ES6 / CommonJS module, meaning it can be imported as follows:
88

9-
import TJBot from 'tjbot';
9+
import TJBot from 'tjbot'; // ES6
1010

11-
Because of this new packaging, TJBotLib requires Node 15.x.
11+
const TJBot = require('tjbot').default; // CommonJS
12+
13+
Node 15.x+ is required to use TJBotLib as an ES6 module.
1214

1315
### `async`/`await` Semantics
1416
TJBot now uses `async`/`await` semantics rather than `Promise` semantics. This change has resulted in much cleaner, and easier to understand code. Thus, functions that used to return promises (e.g. `tj.analyzeTone()`) should now be called with `await`.

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,27 @@ $ npm install --save tjbot
1818

1919
> 💡 Note: The TJBot library was developed for use on Raspberry Pi. It may be possible to develop and test portions of this library on other Linux-based systems (e.g. Ubuntu), but this usage is not officially supported.
2020
21-
2. Instantiate the `TJBot` object.
21+
2. Import the TJBot library.
22+
23+
TJBot is packaged as both an ES6 and a CommonJS module (explained in [this guide](https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html)), which means you may import it using either the ES6 `import` statement or the CommonJS `require` method.
24+
25+
For ES6, import TJBot as follows:
2226

2327
```
2428
import TJBot from 'tjbot';
29+
```
30+
31+
For CommonJS, import TJBot as follows:
32+
33+
```
34+
const TJBot = require('tjbot').default;
35+
```
36+
37+
> 💡 Note: For CommonJS, the `TJBot` class is exported under a `.default` reference.
38+
39+
3. Instantiate the `TJBot` object.
40+
41+
```
2542
const tj = new TJBot();
2643
tj.initialize([TJBot.HARDWARE.LED_NEOPIXEL, TJBot.HARDWARE.SERVO, TJBot.HARDWARE.MICROPHONE, TJBot.HARDWARE.SPEAKER]);
2744
```
@@ -123,7 +140,7 @@ The full list of capabilities can be accessed programatically via `TJBot.CAPABIL
123140

124141
## TJBot API
125142

126-
Please see [the API docs](https://ibmtjbot.github.io/docs/tjbot/2.0.1/) for documentation of the TJBot API.
143+
Please see [the API docs](https://ibmtjbot.github.io/docs/tjbot/2.0.2/) for documentation of the TJBot API.
127144

128145
> 💡 Please see the [Migration Guide](MIGRATING.md) for guidance on migrating your code to the latest version of the TJBot API.
129146

dist/cjs/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

0 commit comments

Comments
 (0)