Permalink
Browse files

Adds `grunt-counter-app` example.

  • Loading branch information...
Paul Cuthbertson
Paul Cuthbertson committed Apr 5, 2016
1 parent ab663c9 commit f4baf44f7622c6c4620526802e370c6e74d9e073
@@ -0,0 +1,28 @@
module.exports = function(grunt) {
grunt.initConfig({
starlight: {
counter: {
src: 'src/counter-app.lua',
dest: 'dist/counter-app.es6.js',
}
},
babel: {
options: {
plugins: ['transform-es2015-destructuring']
},
counter: {
src: 'dist/counter-app.es6.js',
dest: 'dist/counter-app.js',
}
}
});
grunt.loadNpmTasks('grunt-starlight');
grunt.loadNpmTasks('grunt-babel');
// Default task.
grunt.registerTask('default', ['starlight:counter', 'babel:counter']);
};
@@ -0,0 +1,17 @@
# grunt-counter-app
A simple example that uses `grunt-starlight` to precompile a Lua script into JavaScript and use in a webpage.
## Instructions.
Navigate to the `grunt-counter-app` directory in a terminal, then install dependencies and run the build.
This will compile `/src/counter-app.lua` to `/dist/counter-app.js`.
```
npm install
grunt
```
When the build is successful, view `/index.html` in your browser and you should see the app.
Make sure you load the page through a local web server, as XHR requests will not work when viewed from your file system.
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<body>
<h1>Counter app</h1>
<p class="result">0</p>
<p><button>+1</button></p>
<script src="http://paulcuth.me.uk/starlight/browser-lib/starlight.js"></script>
<script src="dist/counter-app.js"></script>
</body>
</html>
@@ -0,0 +1,27 @@
{
"name": "grunt-starlight-counter-app",
"version": "1.0.0",
"description": "A simple working example of using `grunt-starlight`.",
"repository": {
"type": "git",
"url": "git+https://github.com/paulcuth/starlight-examples.git"
},
"keywords": [
"Lua",
"JavaScript",
"Grunt",
"examples"
],
"author": "Paul Cuthbertson",
"license": "MIT",
"bugs": {
"url": "https://github.com/paulcuth/starlight-examples/issues"
},
"homepage": "https://github.com/paulcuth/starlight-examples#readme",
"devDependencies": {
"babel-plugin-transform-es2015-destructuring": "^6.6.5",
"grunt-babel": "^6.0.0",
"grunt-cli": "^1.1.0",
"grunt-starlight": "^0.1.7"
}
}
@@ -0,0 +1,26 @@
window.extract()
local counter = 0
local ui = {
button = document:getElementsByTagName('button')[1],
result = document:querySelector('.result'),
}
function updateUI ()
ui.result.textContent = counter
end
function increment ()
counter = counter + 1
updateUI()
end
function init ()
updateUI()
ui.button:addEventListener('click', increment)
end
init()

0 comments on commit f4baf44

Please sign in to comment.