-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
121 lines (93 loc) · 3.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
const writeFile = require('broccoli-file-creator');
const mergeTrees = require('broccoli-merge-trees');
const primitiveDefinitions = {};
let defaultAttributes;
let aframe;
function runAFrame() {
const { dasherize } = require('ember-cli-string-utils');
const { JSDOM } = require('jsdom');
let _window = global.window = new JSDOM().window;
global.navigator = _window.navigator;
global.document = _window.document;
global.HTMLElement = _window.HTMLElement;
global.screen = _window.screen;
// Object.defineProperty(_window, 'WebVRConfig', {
// get () {
// return global.WebVRConfig;
// },
// set (WebVRConfig) {
// global.WebVRConfig = WebVRConfig;
// }
// });
const primitives = require('aframe/src/extras/primitives/primitives');
const { registerPrimitive } = primitives;
primitives.registerPrimitive = function(name, definition) {
primitiveDefinitions[name] = definition;
return registerPrimitive.apply(this, arguments);
};
aframe = require('aframe/src');
primitives.registerPrimitive = registerPrimitive;
const { propertyTypes } = require('aframe/src/core/propertyTypes');
defaultAttributes = JSON.stringify(Object.keys(propertyTypes).map(dasherize));
delete global.window;
delete global.navigator;
delete global.document;
delete global.HTMLElement;
delete global.screen;
// delete global.WebVRConfig;
}
module.exports = {
name: require('./package').name,
included() {
runAFrame();
return this._super.included.apply(this, arguments);
},
treeForAddon(tree) {
let trees = [tree];
trees.push(writeFile('utils/attributes.js', `
const defaultAttributes = ${defaultAttributes};
export { defaultAttributes };
`));
Object.keys(aframe.primitives.primitives).forEach(name => {
let attributeBindings = [];
let definition = primitiveDefinitions[name];
// let defaultComponents = definition.defaultComponents;
// if (defaultComponents) {
// let geometry = defaultComponents.geometry;
// if (geometry) {
// let primitive = geometry.primitive;
// if (primitive) {
// attributeBindings = Object.keys(aframe.geometries[primitive].schema);
// }
// }
// }
let { mappings } = definition;
if (mappings) {
attributeBindings = Object.keys(mappings).sort();
}
attributeBindings = JSON.stringify(attributeBindings);
trees.push(writeFile(`components/${name}.js`, `
import AEntity from './a-entity';
export default AEntity.extend({
tagName: '${name}',
attributeBindings: ${attributeBindings}
});
`));
});
tree = mergeTrees(trees);
tree = this._super.treeForAddon.call(this, tree);
return tree;
},
treeForApp(tree) {
tree = this._super.treeForApp.call(this, tree);
let trees = [tree];
Object.keys(aframe.primitives.primitives).forEach(name => {
trees.push(writeFile(`components/${name}.js`, `
export { default } from 'ember-aframe/components/${name}';
`));
});
tree = mergeTrees(trees);
return tree;
}
};