Skip to content

Commit f2f7aba

Browse files
committed
add scripts for specifically running integration tests, remove one last CDN link to aws-sdk and use the local version, and update docs as needed for the new ESM format without a required build
1 parent f41abf0 commit f2f7aba

File tree

11 files changed

+186
-75
lines changed

11 files changed

+186
-75
lines changed

CONTRIBUTING.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ npm install
6666

6767
### Building
6868

69-
To build all packages in the repository, run:
69+
The Host libraries work without a build. Only the Babylon Hosts library has a build step for generating type definition files, which is totally optional for use in TypeScript projects.
70+
71+
To run the build (which runs only the Babylon Host lib's type declaration build step), run:
7072
```
7173
npm run build
7274
```
73-
Distributable build artifacts will be generated into a `dist/` directory within each package folder.
75+
76+
Distributable build artifacts (type declaration files) will be generated into a `dist/` directory inside the Babylon Host lib.
7477

7578
### Testing
7679

@@ -82,12 +85,14 @@ Example applications for Babylon.js can be found in the `packages/demos-babylon/
8285

8386
#### Unit Tests
8487

85-
If you've already built the packages, you can execute the unit tests for all packages using the command:
88+
You can execute the unit tests for all packages using the command:
8689
```
87-
npm run test
90+
npm test
8891
```
8992

90-
Alternately, you can both build and run the unit tests with a single command:
93+
Running the build is not necessary for running tests, as all source files as JavaScript modules that work as-is without transformation.
94+
95+
You can run both the Babylon build and the unit tests with a single command to ensure both work at the same time:
9196
```
9297
npm run build-test
9398
```

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
Amazon Sumerian Hosts (Hosts) is an experimental open source project that aims to make it easy to create interactive animated 3D characters for Babylon.js, three.js, and other web 3D frameworks. It leverages AWS services including [Amazon Polly](https://aws.amazon.com/polly/) (text-to-speech) and [Amazon Lex](https://aws.amazon.com/lex/) (chatbot).
44

5+
<!-- CONTINUE Update this after the Babylon fix -->
56
> **Compatibility**
67
>
7-
> ⚠️ Hosts is currently compatible with **BabylonJS v4** (4.2.1+). There are know issues if you try to use Hosts with BabylonJS v5. If you would like to see support for BabylonJS v5 added, comment on [this enhancement request issue](https://github.com/aws-samples/amazon-sumerian-hosts/issues/155).
8+
> ⚠️ Hosts is currently compatible with **BabylonJS v4** (4.2.1+). There are known issues if you try to use Hosts with BabylonJS v5. If you would like to see support for BabylonJS v5 added, comment on [this enhancement request issue](https://github.com/aws-samples/amazon-sumerian-hosts/issues/155).
89
>
910
> ✏️ Hosts have been tested with **Three.js v0.127.0**.
1011
@@ -34,7 +35,7 @@ The easiest way to get started using the hosts is by using plugins we provide fo
3435

3536
Visit the [aws-tools-for-babylonjs-editor](https://github.com/aws-samples/aws-tools-for-babylonjs-editor/blob/main/README.md) repository for more details.
3637

37-
#### Using pre-built NPM modules
38+
#### Using NPM modules
3839

3940
If you are creating applications outside of the Babylon.JS Editor, you can easily install the relevant Hosts module using NPM.
4041

@@ -56,7 +57,20 @@ For full detail on the classes and methods available, see the [API Documentation
5657

5758
#### Building from source
5859

59-
Building from source is considered an advanced option. It is not recommended unless you need to heavily customize the core Hosts functionality. Instructions on how to build from source can be found in the [CONTRIBUTING](CONTRIBUTING.md) document.
60+
Both the core Host lib and the Three.js Host lib do not have a build. You can
61+
customize them by simply editing the .js files in your own fork, and simply
62+
running a static server to run the apps.
63+
64+
The Babylon Host lib has a TypeScript build step *only* for creating output
65+
type definitions from its .js files, and is otherwise not required for running
66+
the Babylon demos: simply edit the JavaScript files, and start the static
67+
server to run the demos.
68+
69+
If you need to build the type definitions for consumption in a TypeScript
70+
project, then run `npm run build` at the root of the repo (after first running
71+
`npm install` if you haven't already).
72+
73+
Find more details in [CONTRIBUTING](CONTRIBUTING.md).
6074

6175
## Demos
6276

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"start": "five-server .",
3030
"start-core": "five-server . --open=./packages/amazon-sumerian-hosts-core/test/integration_test/core",
3131
"start-three": "five-server . --open=./packages/amazon-sumerian-hosts-three/examples/",
32-
"start-babylon": "five-server . --open=./packages/demos-babylon/src/"
32+
"start-three-tests": "five-server . --open=./packages/amazon-sumerian-hosts-three/test/integration_test/three.js/",
33+
"start-babylon": "five-server . --open=./packages/demos-babylon/src/",
34+
"start-babylon-tests": "five-server . --open=./packages/demos-babylon/src/"
3335
},
3436
"devDependencies": {
3537
"cross-env": "^7.0.3",

packages/amazon-sumerian-hosts-babylon/README.md

Lines changed: 70 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,77 @@ More details can be found in [demos-babylon](https://github.com/aws-samples/amaz
2222

2323
Before you use Hosts in your applications, you will need to set up a few thing in your AWS account. For step-by-step instructions on setting up this required infrastructure, see [AWS-Infrastructure-Setup.md](https://github.com/aws-samples/amazon-sumerian-hosts/tree/mainline2.0/AWS-Infrastructure-Setup.md) in the root of this repository.
2424

25-
### Configurating the AWS SDK
25+
## Configurating the Babylon HOST app
2626

27-
## Configuring Webpack
28-
29-
We recommend using a module bundler such as [Webpack](https://webpack.js.org/) to package and distribute your code. As BabylonJS relies on static singletons for certain features, it may be necessary to configure Webpack so that all modules and submodules use the same instance of BabylonJS. Add the following to `module.exports.resolve`:
30-
31-
```
32-
resolve: {
33-
...
34-
modules: ['node_modules'],
35-
alias: {
36-
// configure all modules to point at the same instance of BabylonJS
37-
'@babylonjs/core': path.resolve('./node_modules/@babylonjs/core')
38-
}
39-
},
27+
### Step 1. Adding Script Dependencies
4028

41-
```
29+
Here we will take a look at the scripts necessary for the example code to function:
4230

43-
### Step 1. Adding Script Dependencies
31+
> [!Note] Before you continue, make sure you've ran `npm install` at the root of
32+
the repo so that dependencies are installed locally.
4433

45-
One way to configure AWS SDK is to include dependency script:
4634

4735
- ```html
48-
<!--Text to speech dependency-->
49-
<script
50-
type="text/javascript"
51-
src="https://sdk.amazonaws.com/js/aws-sdk-2.645.0.min.js"
52-
></script>
36+
<!-- This fetches the AWS SDK for JavaScript, and installs it as a global `AWS` variable. -->
37+
<script src="../../../node_modules/aws-sdk/dist/aws-sdk.min.js"></script>
5338
```
5439

55-
The hosts will need to connect to Amazon Polly to convert text into audio assets. https://sdk.amazonaws.com/js/aws-sdk-2.645.0.min.js is a minified build of the AWS SDK for Javascript. For the latest version, see the [AWS SDK for JavaScript API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/).
56-
57-
And then configure the AWS SDK with our region and credentials:
40+
This file has to be included first, so that it is available by the time the
41+
rest of our code runs.
5842

59-
- ```javascript
60-
// Initialize AWS and create Polly service objects
61-
AWS.config.region = 'us-west-2';
62-
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
63-
IdentityPoolId: '<Enter Cognito Identity Pool ID here>',
64-
});
43+
- ```html
44+
<!-- Define the locations for each of the libraries that we've installed so we can import them. -->
45+
<script type="importmap">
46+
{
47+
"imports": {
48+
"three": "https://cdn.jsdelivr.net/npm/three@0.127.0/build/three.module.js",
49+
"three/": "https://cdn.jsdelivr.net/npm/three@0.127.0/",
50+
"@amazon-sumerian-hosts/core": "../../../node_modules/@amazon-sumerian-hosts/core/src/core/index.js",
51+
"@amazon-sumerian-hosts/three": "../../../node_modules/@amazon-sumerian-hosts/three/src/three.js/index.js",
52+
"compare-versions": "../../../node_modules/compare-versions/lib/esm/index.js",
53+
"aws-sdk": "../../demos-babylon/src/aws-sdk-global.js"
54+
}
55+
}
56+
</script>
6557
```
6658

67-
Replace `<Enter Cognito Identity Pool ID here>` with the id you created in the [Prerequisites](#Prerequisites) section. Make sure to set the region to the one you created your Cognito Identity Pool in. Using CognitoIdentityCredentials is just one example of how you can authenticate your host to access Polly. See the [AWS SDK documentation](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Credentials.html) to see other credentials classes you can use.
59+
The `importmap` script defines where dependencies are to be found, so
60+
that code that has `import` statements will receive the expected libraries. For
61+
example, the `imports.three` entry in the following import map (which is in JSON
62+
format) defines where the `three` library will be fetched from when an import
63+
statement like `import * as THREE from 'three'` is encountered in JavaScript.
64+
For more info on import maps, see [Mozilla's import map
65+
docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap)
66+
which also has links to broader concepts like JavaScript modules in general, and
67+
the [import map spec repository on GitHub](https://github.com/WICG/import-maps)
68+
which has the original ideation and links to resources for managing import maps.
69+
70+
The hosts will need to connect to Amazon Polly to convert text into audio
71+
assets. Here we map imports to `aws-sdk` to an `aws-sdk-global.js` file that
72+
exports the global `AWS` variable so that we can `import` it in our JavaScript
73+
code instead of relying on the global variable everywhere that we need to use
74+
it. For the latest version of the SDK, see the [AWS SDK for JavaScript API
75+
Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/).
76+
77+
> [!Note] The version after the `@` for the `three` URL should be the same as
78+
found in the [package.json](package.json) to guarantee that it works. Feel
79+
free to try newer versions of Three.js to see if they work, and if not then
80+
restore the known working version. If you get it working with newer Three.js
81+
(sometimes there are small tweaks needed from breaking changes in Three.js),
82+
please submit a pull request to get it updated.
83+
84+
## Configure the AWS SDK with our region and credentials:
85+
86+
```javascript
87+
// Initialize AWS and create Polly service objects
88+
AWS.config.region = 'us-west-2';
89+
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
90+
IdentityPoolId: cognitoIdentityPoolId,
91+
});
92+
```
93+
94+
> [!Note]
95+
> Here the `cognitoIdentityPoolId` variable will contain the id you created and placed inside of `demo-credentials.js` in the [Prerequisites](#Prerequisites) section. Make sure to set the region to the one you created your Cognito Identity Pool in. Using CognitoIdentityCredentials is just one example of how you can authenticate your host to access Polly. See the [AWS SDK documentation](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Credentials.html) to see other credentials classes you can use.
6896
6997
### Instantiating the Host
7098

@@ -172,6 +200,14 @@ Then, you can setup a simple button used for recording microphone input purpose
172200
LexFeature also supports text input as well as a list of other events for tracking recording state for instance. See [LexFeature](https://aws-samples.github.io/amazon-sumerian-hosts/core_LexFeature.html) for more details.
173201

174202
### Next Steps
203+
175204
Now that you've demonstrated your hosts running locally, consider publishing them to the web via one of these related tutorials:
176-
- [Publishing a Web Application Using AWS Amplify](https://docs.sumerian.amazonaws.com/tutorials/create/solutions/gltf-viewer-amplify-public/)
177-
- [Privately Publish a Web Application Using AWS Amplify](https://docs.sumerian.amazonaws.com/tutorials/create/solutions/gltf-viewer-amplify-private/)
205+
206+
- [Hosting a static site on AWS Amplify](https://aws.amazon.com/getting-started/hands-on/host-static-website/)
207+
- [Creating a static GitHub Pages site](https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site)
208+
- [Publishing a static site on Vercel from git](https://vercel.com/docs/deployments/git)
209+
210+
If you're more advanced, you probably want to set up a server that contains your
211+
AWS key privately, so that it is not served publicy in via a static website.
212+
You'd want to require user authentication, and proxy request through your server
213+
so that the client-side code does not contain the key.

packages/amazon-sumerian-hosts-babylon/test/integration_test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ npm install
1616

1717
## Running the Tests
1818

19-
Run `npm run start-babylon` from the repository root. This will start a local web server and open two tabs in your browser. One will provide a list of demos (from the `packages/demos-babylon` package.) The other will be the list of available integration tests. From this tab you can access and exercise each test.
19+
Run `npm run start-babylon-tests` from the repository root. The tab will provide a list of available integration tests. From this tab you can access and exercise each test.
2020

2121
When you're finished runnin the tests, you can quit the local dev server by pressing CTRL-C in the same terminal in which you started the server.

packages/amazon-sumerian-hosts-core/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ For a general introduction to Amazon Sumerian Hosts and examples of how to integ
44

55
Amazon Sumerian Hosts is an experimental open source project that aims to make it easy to create interactive animated 3D characters that can be rendered on the Web and leverage AWS Services such as [Amazon Polly](https://aws.amazon.com/polly/). The core API provides an abstraction layer so that these can be extended to support the Web rendering engine of your choice.
66

7-
Refer to the [API Documentation](https://aws-samples.github.io/amazon-sumerian-hosts/) for more detailed information on the classes and methods available. Amazon Sumerian Hosts is a published [npm](https://www.npmjs.com/) package, so alternatively you can install in an existing Node.js project by running `npm install --save-dev @amazon-sumerian-hosts/core`. If you'd like to pull the GitHub repository and create your own build, see [Building the Repository](https://github.com/aws-samples/amazon-sumerian-hosts/blob/mainline2.0/README.md#building-the-repository) for prerequisites and instructions on how to do that.
7+
Refer to the [API Documentation](https://aws-samples.github.io/amazon-sumerian-hosts/) for more detailed information on the classes and methods available. Amazon Sumerian Hosts is a published [npm](https://www.npmjs.com/) package, so alternatively you can install in an existing Node.js project by running `npm install --save-dev @amazon-sumerian-hosts/core`.
8+
9+
If you'd like to pull the GitHub repository and customize the hosts, a build is
10+
not required unless you want to generate type defintions for use in TypeScript,
11+
and the demos simply run on their own without a build step. See [Building from
12+
source](https://github.com/aws-samples/amazon-sumerian-hosts/blob/mainline2.0/README.md#building-from-source)
13+
for prerequisites and instructions on how to do that.
814

915
## License
1016

packages/amazon-sumerian-hosts-core/test/integration_test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ npm install
1818

1919
Run `npm run start-core` from the repository root. This will start a local web server and open a web browser tab containing a list of available integration tests. From this tab you can access and exercise each test.
2020

21-
When you're finished runnin the tests, you can quit the local dev server by pressing CTRL-C in the same terminal in which you started the server.
21+
When you're finished running the tests, you can quit the local dev server by pressing CTRL-C in the same terminal in which you started the server.
2222

2323

2424

packages/amazon-sumerian-hosts-core/test/integration_test/core/core.texttospeech.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@
88
<meta charset="UTF-8" />
99
<title>Core Host Test</title>
1010
<link rel="icon" href="data:;base64,iVBORw0KGgo=" />
11+
12+
<script src="../../../../../node_modules/aws-sdk/dist/aws-sdk.min.js"></script>
13+
1114
<script type="importmap">
1215
{
1316
"imports": {
1417
"@amazon-sumerian-hosts/core": "../../../../../node_modules/@amazon-sumerian-hosts/core/src/core/index.js",
15-
"compare-versions": "../../../../../node_modules/compare-versions/lib/esm/index.js"
18+
"compare-versions": "../../../../../node_modules/compare-versions/lib/esm/index.js",
19+
"aws-sdk": "../../../../demos-babylon/src/aws-sdk-global.js"
1620
}
1721
}
1822
</script>
1923
</head>
2024
<body>
21-
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.645.0.min.js"></script>
2225
<script type="module">
2326
import {cognitoIdentityPoolId} from '../../../../../demo-credentials.js';
2427
import * as HOST from '@amazon-sumerian-hosts/core';
28+
import AWS from 'aws-sdk';
2529

2630
async function main() {
2731
// Parse the region out of the cognito Id
@@ -41,7 +45,7 @@
4145
await TextToSpeechFeature.initializeService(
4246
polly,
4347
presigner,
44-
window.AWS.VERSION
48+
AWS.VERSION
4549
);
4650

4751
// Create the speaker who will deliver speeches

0 commit comments

Comments
 (0)