Skip to content

Commit a816d67

Browse files
keegojihoonl
authored andcommitted
Add ES6 module support (#214)
* Added Rollup * Added yarn lockfile * Removed references to COLLADA_LOADER_2 * Added es6 transpiler and rollup config, working on transpiling * Touched up a couple potential mistypes prevent transpiler from working. 1 - removed explicit super.super() call from InteractiveMarker. 2 - Made Particles explicitly derive from THREE.Object3D. * Rewrote Particles' method signatures in format consistent with rest of codebase * Refactored updateMatrixWorld to be more statically analyzable * ES6 modules properly compiling, Working on runtime errors * Moved 'that' assignments happen *after* calls super constructors in derived classes * Added missing super constructor call * Removed assignment to read-only property causing a runtime error, added a relevant comment * Moved all super constructor calls to preceed any use of 'this' * Added shims for THREE and THREE extensions to support es6 compatible module extensions * Cleanup and added examples for single page applications and using html imports in browsers * Moved es6 support files to es6-support folder and renamed destination for es6 transpiled output * Moved shims to top level * Added build output * Removed extra log * Added angular app example * Added react app example and touched up other SPA examples * Updated ROSLIB import semantics * Switched ColladaLoader shim from official ColladaLoader to the ros3djs fork * Updated html-import example to use yarn like the other examples * Updated outdated grunt plugins * Fixed linter errors * Updated grunt build process to build es6 output * Switched from jshint to eslint, migrating rules and fixing lint issues * Updated commonjs target to be es5 * Fixed pkg.module to use es6 module syntax, but es5 language features * Fixed bug in Points class * Switched from const to var for es5 compatibility * Added PointCloud2 example for angular app * Updated node version use by CI server
1 parent b1f8247 commit a816d67

File tree

106 files changed

+193906
-4722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+193906
-4722
lines changed

.eslintrc

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"es6": true,
6+
"mocha": true
7+
},
8+
"globals": {
9+
"EventEmitter2": true,
10+
"THREE": true,
11+
"ROS3D": true,
12+
"ROSLIB": true,
13+
"requestAnimationFrame": true,
14+
"cancelAnimationFrame": true
15+
},
16+
"parserOptions": {
17+
"ecmaFeatures": {
18+
"experimentalObjectRestSpread": true
19+
},
20+
"ecmaVersion": 5,
21+
"sourceType": "module"
22+
},
23+
"rules": {
24+
"semi": ["warn", "always"],
25+
"curly": "error",
26+
"eqeqeq": "error",
27+
"wrap-iife": ["error", "any"],
28+
"no-use-before-define": "off",
29+
"new-cap": "error",
30+
"no-caller": "error",
31+
"dot-notation": "off",
32+
"no-undef": "error",
33+
"no-cond-assign": "off",
34+
"no-eq-null": "off",
35+
"no-proto": "off",
36+
"strict": "off",
37+
"quotes": ["error", "single"],
38+
"linebreak-style": "error"
39+
}
40+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.vagrant
33
node_modules
44
doc
5+
src-esm

.jshintrc

-30
This file was deleted.

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22

33
node_js:
4-
- "0.10"
4+
- "8.9.4"
55

66
branches:
77
only:

Gruntfile.js

+101-26
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1+
const {
2+
debugRules,
3+
dependencies,
4+
inheritance,
5+
injectImports,
6+
transpileToEs6
7+
} = require('./es6-transpiler');
8+
9+
// Export Grunt config
110
module.exports = function(grunt) {
211

312
grunt.initConfig({
413
pkg: grunt.file.readJSON('package.json'),
5-
concat: {
6-
build: {
7-
src : ['./src/*.js', './src/**/*.js'],
8-
dest : './build/ros3d.js'
14+
eslint: {
15+
lint: {
16+
options: {
17+
configFile: '.eslintrc',
18+
},
19+
src: [
20+
'Gruntfile.js',
21+
'./src/*.js',
22+
'./src/**/*.js',
23+
'./tests/*.js'
24+
],
25+
},
26+
fix: {
27+
options: {
28+
configFile: '<%= eslint.lint.options.configFile %>',
29+
fix: true
30+
},
31+
src: '<%= eslint.lint.src %>',
932
}
1033
},
11-
jshint: {
12-
options: {
13-
jshintrc: '.jshintrc'
14-
},
15-
files: [
16-
'Gruntfile.js',
17-
'./build/ros3d.js',
18-
'./tests/*.js'
19-
]
34+
shell: {
35+
build: {
36+
command: 'rollup -c'
37+
}
2038
},
2139
karma: {
2240
build: {
@@ -25,15 +43,6 @@ module.exports = function(grunt) {
2543
browsers: ['PhantomJS']
2644
}
2745
},
28-
uglify: {
29-
options: {
30-
report: 'min'
31-
},
32-
build: {
33-
src: './build/ros3d.js',
34-
dest: './build/ros3d.min.js'
35-
}
36-
},
3746
watch: {
3847
dev: {
3948
options: {
@@ -51,7 +60,7 @@ module.exports = function(grunt) {
5160
},
5261
files: [
5362
'Gruntfile.js',
54-
'.jshintrc',
63+
'.eslintrc',
5564
'./src/*.js',
5665
'./src/**/*.js'
5766
],
@@ -75,19 +84,85 @@ module.exports = function(grunt) {
7584
configure: 'jsdoc_conf.json'
7685
}
7786
}
87+
},
88+
pipe: {
89+
transpile: {
90+
options: {
91+
process: transpileToEs6,
92+
},
93+
files: [{
94+
expand: true,
95+
cwd: 'src',
96+
src: [
97+
'*.js',
98+
'**/*.js',
99+
],
100+
dest: 'src-esm/',
101+
}]
102+
},
103+
transpile_imports: {
104+
options: {
105+
process: injectImports,
106+
},
107+
files: [{
108+
expand: true,
109+
cwd: 'src-esm',
110+
src: [
111+
'*.js',
112+
'**/*.js',
113+
],
114+
dest: 'src-esm/',
115+
}]
116+
},
117+
transpile_index: {
118+
files: [{
119+
expand: true,
120+
cwd: 'es6-support',
121+
src: [
122+
'index.js'
123+
],
124+
dest: 'src-esm/'
125+
}]
126+
}
127+
},
128+
execute: {
129+
transpile: {
130+
call: (grunt, options) => {
131+
console.log();
132+
if (debugRules.logInternalDepsAtEnd) {
133+
console.log('Internal dependencies');
134+
console.log(dependencies.internalToString());
135+
}
136+
if (debugRules.logExternalDepsAtEnd) {
137+
console.log('External dependencies');
138+
console.log(dependencies.externalToString());
139+
}
140+
if (debugRules.logInheritanceAtEnd) {
141+
console.log('Inheritance hierarchy');
142+
console.log(inheritance.toString());
143+
}
144+
145+
console.log();
146+
},
147+
}
78148
}
79149
});
80150

81151
grunt.loadNpmTasks('grunt-contrib-concat');
82-
grunt.loadNpmTasks('grunt-contrib-jshint');
83152
grunt.loadNpmTasks('grunt-contrib-watch');
84-
grunt.loadNpmTasks('grunt-contrib-uglify');
85153
grunt.loadNpmTasks('grunt-contrib-clean');
86154
grunt.loadNpmTasks('grunt-jsdoc');
87155
grunt.loadNpmTasks('grunt-karma');
156+
grunt.loadNpmTasks('grunt-pipe');
157+
grunt.loadNpmTasks('grunt-execute');
158+
grunt.loadNpmTasks('grunt-shell');
159+
grunt.loadNpmTasks('gruntify-eslint');
88160

89161
grunt.registerTask('dev', ['concat', 'watch']);
90-
grunt.registerTask('build', ['concat', 'jshint', 'uglify']);
162+
grunt.registerTask('transpile', ['pipe', 'execute']);
163+
grunt.registerTask('build', ['eslint:lint', 'pipe', 'shell']);
91164
grunt.registerTask('build_and_watch', ['watch']);
92165
grunt.registerTask('doc', ['clean', 'jsdoc']);
166+
grunt.registerTask('lint', ['eslint:lint',]);
167+
grunt.registerTask('lint-fix', ['eslint:fix',]);
93168
};

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ Utilizes [mocha](https://mochajs.org/) and [chai](http://chaijs.com/) for in bro
9494

9595
To run tests simply open `tests/index.html` in a web browser
9696

97+
### Examples
98+
There are a variety of [examples](examples) of the different things that can be done with ros3djs.
99+
100+
There are also some examples of how ros3djs can be used in different environments:
101+
102+
- [Classic html script tag inclusion](examples)
103+
- [Modular html script tag inclusion](examples/html-import)
104+
- [Modular import for a Single Page Application](examples/single-page-application)
105+
97106
### License
98107
ros3djs is released with a BSD license. For full terms and conditions, see the [LICENSE](LICENSE) file.
99108

0 commit comments

Comments
 (0)