Skip to content

Commit

Permalink
Merge pull request #10 from magic-script/npm-polyfills
Browse files Browse the repository at this point in the history
Convert many samples to being based on new template.
  • Loading branch information
creationix committed Feb 8, 2019
2 parents 77ea88b + 6706b9b commit a740143
Show file tree
Hide file tree
Showing 89 changed files with 907 additions and 4,762 deletions.
15 changes: 14 additions & 1 deletion sample-audio/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ module.exports = {
"es6": true
},
globals: {
// These globals are provided by the vm itself.
"print": true,
"globalThis": true,
// The following globals are provided by `magic-script-polyfills`
"setTimeout": true,
"clearTimeout": true,
"setInterval": true,
"clearInterval": true,
"setImmediate": true,
"clearImmediate": true,
"fetch": true,
"Headers": true,
"Request": true,
"Response": true,

},
extends: "eslint:recommended",
parserOptions: {
Expand All @@ -23,7 +36,7 @@ module.exports = {
],
"quotes": [
"error",
"double"
"single"
],
"semi": [
"error",
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions sample-audio/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach Program",
"address": "127.0.0.1",
"port": 9229,
"localRoot": "${workspaceFolder}/bin",
"remoteRoot": ".",
"protocol": "inspector"
}
]
}
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions sample-audio/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<manifest xmlns:ml="magicleap"
ml:package="com.magicscript.sample.audio"
ml:version_name="0.0.0.1"
ml:version_name="0.0.1"
ml:version_code="1">
<application ml:visible_name="Audio Sample"
<application ml:visible_name="Audio App"
ml:application_type="untrusted"
ml:sdk_version="1.0">
<component ml:name=".universe"
ml:visible_name="Audio App"
ml:binary_name="bin/main.js"
ml:binary_name="bin/index.js"
ml:type="Universe">
<mode ml:shareable="true"/>
<icon ml:model_folder=""
Expand Down
4 changes: 3 additions & 1 deletion sample-audio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"devDependencies": {
"rollup": "^1.1.2",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-executable": "^1.4.4",
"rollup-plugin-node-resolve": "^4.0.0"
},
"dependencies": {
"magic-script-polyfills": "^0.3.0"
}
}
20 changes: 9 additions & 11 deletions sample-audio/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// Rollup config for consuming some npm modules in MagicScript

import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import executable from "rollup-plugin-executable";
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';

export default {
external: ["uv", "lumin"],
input: "src/main.js",
external: ['uv', 'lumin'],
input: 'src/main.js',
preserveModules: true,
output: {
file: "bin/main.js",
intro: "#!/system/bin/script/mxs\nglobalThis.window=globalThis;",
format: "es",
sourcemap: "external"
dir: 'bin',
format: 'es'
},
plugins: [resolve(), commonjs(), executable()]
};
plugins: [resolve(), commonjs()]
};
25 changes: 25 additions & 0 deletions sample-audio/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { LandscapeApp } from 'lumin';
import { makeButton } from './button.js';

export class App extends LandscapeApp {
init() {
let prism = this.requestNewPrism([0.7, 0.5, 0.5]);
let button = null;
// Add button # 1
button = makeButton(prism, 'UIButtonStream');
button.setLocalPosition([0, 0.15, 0]);
prism.getRootNode().addChild(button);
// Add button # 2
button = makeButton(prism, 'UIButtonHeartPlus');
button.setLocalPosition([0, 0, 0]);
prism.getRootNode().addChild(button);
// Add button # 3
button = makeButton(prism, 'UIButtonBlock');
button.setLocalPosition([0, -0.15, 0]);
prism.getRootNode().addChild(button);
return 0;
}
updateLoop(delta) {
return true;
}
}
36 changes: 6 additions & 30 deletions sample-audio/src/main.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
//
import { LandscapeApp } from "lumin";
import { makeButton } from "./button.js";
// Add support for things like setTimeout, setInterval and fetch.
import 'magic-script-polyfills';

class App extends LandscapeApp {
init() {
let prism = this.requestNewPrism([0.7, 0.5, 0.5]);
let button = null;
// Add button # 1
button = makeButton(prism, "UIButtonStream");
button.setLocalPosition([0, 0.15, 0]);
prism.getRootNode().addChild(button);
// Add button # 2
button = makeButton(prism, "UIButtonHeartPlus");
button.setLocalPosition([0, 0, 0]);
prism.getRootNode().addChild(button);
// Add button # 3
button = makeButton(prism, "UIButtonBlock");
button.setLocalPosition([0, -0.15, 0]);
prism.getRootNode().addChild(button);
return 0;
}
updateLoop(delta) {
return true;
}
eventListener(event) {
return true;
}
}
// Import our main app
import { App } from './App.js';

let app = new App(0.016);
app.run();
// Launch our app!
new App(0.5);
63 changes: 44 additions & 19 deletions sample-external-package/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
// ESLint config for MagicScript Apps
module.exports = {
env: {
es6: true
},
globals: {
print: true,
globalThis: true
},
extends: "eslint:recommended",
parserOptions: {
ecmaVersion: 2018,
sourceType: "module"
},
rules: {
indent: ["error", 2],
"linebreak-style": ["error", "unix"],
quotes: ["error", "double"],
semi: ["error", "always"]
}
};
env: {
"es6": true
},
globals: {
// These globals are provided by the vm itself.
"print": true,
"globalThis": true,
// The following globals are provided by `magic-script-polyfills`
"setTimeout": true,
"clearTimeout": true,
"setInterval": true,
"clearInterval": true,
"setImmediate": true,
"clearImmediate": true,
"fetch": true,
"Headers": true,
"Request": true,
"Response": true,

},
extends: "eslint:recommended",
parserOptions: {
"ecmaVersion": 2018,
"sourceType": "module"
},
rules: {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
};
File renamed without changes.
18 changes: 18 additions & 0 deletions sample-external-package/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach Program",
"address": "127.0.0.1",
"port": 9229,
"localRoot": "${workspaceFolder}/bin",
"remoteRoot": ".",
"protocol": "inspector"
}
]
}
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions sample-external-package/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<manifest xmlns:ml="magicleap"
ml:package="com.magicscript.sample.externalpackage"
ml:version_name="0.0.0.1"
ml:version_name="0.0.1"
ml:version_code="1">
<application ml:visible_name="Ext. Package Sample"
<application ml:visible_name="Ext. Package App"
ml:application_type="untrusted"
ml:sdk_version="1.0">
<component ml:name=".universe"
ml:visible_name="Ext. Package App"
ml:binary_name="bin/main.js"
ml:binary_name="bin/index.js"
ml:type="Universe">
<mode ml:shareable="true"/>
<icon ml:model_folder=""
Expand Down
6 changes: 3 additions & 3 deletions sample-external-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"private": true,
"devDependencies": {
"rollup": "^1.1.2",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-executable": "^1.4.4",
"rollup-plugin-commonjs": "https://github.com/creationix/rollup-plugin-commonjs.git",
"rollup-plugin-node-resolve": "^4.0.0"
},
"dependencies": {
"lodash": "^4.17.11",
"underscore": "^1.9.1"
"underscore": "^1.9.1",
"magic-script-polyfills": "^0.3.0"
}
}
18 changes: 8 additions & 10 deletions sample-external-package/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// Rollup config for consuming some npm modules in MagicScript

import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import executable from "rollup-plugin-executable";
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';

export default {
external: ["uv", "lumin"],
input: "src/main.js",
external: ['uv', 'lumin'],
input: 'src/main.js',
preserveModules: true,
output: {
file: "bin/main.js",
intro: "#!/system/bin/script/mxs\nglobalThis.window=globalThis;",
format: "es",
sourcemap: "inline"
dir: 'bin',
format: 'es'
},
plugins: [resolve(), commonjs(), executable()]
plugins: [resolve(), commonjs()]
};
21 changes: 21 additions & 0 deletions sample-external-package/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { LandscapeApp } from 'lumin';
import { makeTextUnderscore } from './text_underscore.js';
import { makeTextLodash } from './text_lodash.js';

export class App extends LandscapeApp {
init() {
let prism = this.requestNewPrism([0.5, 0.5, 0.5]);

let text_u = makeTextUnderscore(prism);
text_u.setLocalPosition([0, 0.1, 0]);
prism.getRootNode().addChild(text_u);

let text_l = makeTextLodash(prism);
text_l.setLocalPosition([0, -0.1, 0]);
prism.getRootNode().addChild(text_l);
return 0;
}
updateLoop(delta) {
return true;
}
}
32 changes: 6 additions & 26 deletions sample-external-package/src/main.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
//
import { LandscapeApp } from "lumin";
import { makeTextUnderscore } from "./text_underscore.js";
import { makeTextLodash } from "./text_lodash.js";
// Add support for things like setTimeout, setInterval and fetch.
import 'magic-script-polyfills';

class App extends LandscapeApp {
init() {
let prism = this.requestNewPrism([0.5, 0.5, 0.5]);
// Import our main app
import { App } from './App.js';

let text_u = makeTextUnderscore(prism);
text_u.setLocalPosition([0, 0.1, 0]);
prism.getRootNode().addChild(text_u);

let text_l = makeTextLodash(prism);
text_l.setLocalPosition([0, -0.1, 0]);
prism.getRootNode().addChild(text_l);
return 0;
}
updateLoop(delta) {
return true;
}
eventListener(event) {
return true;
}
}

let app = new App(0.016);
app.run();
// Launch our app!
new App(0.5);
8 changes: 4 additions & 4 deletions sample-external-package/src/text_lodash.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//
import { ui } from "lumin";
import __ from "lodash";
import { ui } from 'lumin';
import __ from 'lodash';

export function makeTextLodash(prism) {
const { UiText, EclipseLabelType, Alignment, HorizontalAlignment } = ui;
let array = [1, 2, 3, 4, 5, 6, 7];
__.fill(array, "*", 2, 5);
__.fill(array, '*', 2, 5);
let result = __.map(array, function(num) {
return num;
});
let node = UiText.CreateEclipseLabel(
prism,
"Lodash.js result:\n" + result,
'Lodash.js result:\n' + result,
EclipseLabelType.kT7
);
node.setAlignment(Alignment.CENTER_CENTER);
Expand Down

0 comments on commit a740143

Please sign in to comment.