Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
app and vendor based on ember-app-kit.
  • Loading branch information
joliss committed Nov 8, 2013
1 parent 32b7db1 commit c4e1ae0
Show file tree
Hide file tree
Showing 36 changed files with 59,213 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.tmp
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013 Jo Liss

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Broccoli

A fast, reliable asset builder. Hard-coded to build Ember apps for now, to be
generalized later.

Work in progress, not usable for anything yet.
2 changes: 2 additions & 0 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var FixtureAdapter = DS.FixtureAdapter.extend();
export default FixtureAdapter;
22 changes: 22 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Resolver from 'resolver';

var App = Ember.Application.extend({
LOG_ACTIVE_GENERATION: true,
LOG_MODULE_RESOLVER: true,
LOG_TRANSITIONS: true,
LOG_TRANSITIONS_INTERNAL: true,
LOG_VIEW_LOOKUPS: true,
modulePrefix: 'appkit', // TODO: loaded via config
Resolver: Resolver.default
});

Ember.RSVP.configure('onerror', function(error) {
// ensure unhandled promises raise awareness.
// may result in false negatives, but visibility is more imporant
if (error instanceof Error) {
Ember.Logger.assert(false, error);
Ember.Logger.error(error.stack);
}
});

export default App;
Empty file added app/components/.gitkeep
Empty file.
9 changes: 9 additions & 0 deletions app/components/pretty-color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var PrettyColor = Ember.Component.extend({
classNames: ['pretty-color'],
attributeBindings: ['style'],
style: function(){
return 'color: ' + this.get('name') + ';';
}.property('name')
});

export default PrettyColor;
Empty file added app/controllers/.gitkeep
Empty file.
Empty file added app/helpers/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions app/helpers/reverse-word.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var reverseWord = Ember.Handlebars.makeBoundHelper(function(word) {
return word.split('').reverse().join('');
});

export default reverseWord;
80 changes: 80 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!DOCTYPE html>
<html>
<head>
<title>App</title>

<!-- build:css(tmp/result) assets/app.min.css -->
<link rel="stylesheet" href="/assets/app.css">
<!-- endbuild -->


<!-- for more details visit: https://github.com/yeoman/grunt-usemin -->

<!-- build:js(tmp/result) assets/vendor.min.js -->

<script src="/vendor/jquery/jquery.js"></script>

<!-- @if dist=false -->
<script src="/vendor/handlebars/handlebars.js"></script>
<script src="/vendor/ember/ember.js"></script>
<!-- @endif --><!-- @if dist=true -->
<script src="/vendor/handlebars/handlebars.runtime.js"></script>
<script src="/vendor/ember/ember.prod.js"></script>
<!-- @endif -->

<script src="/vendor/ember-data-shim/ember-data.js"></script>
<script src="/vendor/almond.js"></script>
<script src="/vendor/ember-resolver/dist/ember-resolver.js"></script>

<!-- endbuild -->

<!-- build:js(tmp/result) assets/app.min.js -->

<script src="app.js"></script>
<script src="/assets/templates.js"></script>

<!-- endbuild -->

<!-- @if tests=true -->
<link rel="stylesheet" href="/vendor/qunit/qunit/qunit.css">
<script src="/vendor/qunit/qunit/qunit.js"></script>

<style>
#ember-testing-container {
position: absolute;
background: white;
bottom: 0;
right: 0;
width: 640px;
height: 384px;
overflow: auto;
z-index: 9999;
border: 1px solid #ccc;
}
#ember-testing {
zoom: 50%;
}
</style>
<!-- @endif -->

</head>
<body>

OK

<!-- @if tests=true -->
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="/tests/tests.js"></script>
<script src="/tests/test_helper.js"></script>
<script src="/tests/test_loader.js"></script>
<!-- @endif -->

<!-- @if tests=false -->
<script>
window.App = require('appkit/app').default.create();
</script>
<!-- @endif -->

</body>
</html>
Empty file added app/models/.gitkeep
Empty file.
11 changes: 11 additions & 0 deletions app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var Router = Ember.Router.extend(); // ensure we don't share routes between all Router instances

Router.map(function() {
this.route('component-test');
this.route('helper-test');
// this.resource('posts', function() {
// this.route('new');
// });
});

export default Router;
Empty file added app/routes/.gitkeep
Empty file.
8 changes: 8 additions & 0 deletions app/routes/component_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var ComponentTestRoute = Ember.Route.extend({
model: function() {
return ['purple', 'green', 'orange'];
}
});

export default ComponentTestRoute;

9 changes: 9 additions & 0 deletions app/routes/helper_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var HelperTestRoute = Ember.Route.extend({
model: function() {
return {
name: "rebmE"
};
}
});

export default HelperTestRoute;
7 changes: 7 additions & 0 deletions app/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var IndexRoute = Ember.Route.extend({
model: function() {
return ['red', 'yellow', 'blue'];
}
});

export default IndexRoute;
Empty file added app/styles/.gitkeep
Empty file.
8 changes: 8 additions & 0 deletions app/styles/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Put your CSS here */
html, body {
margin: 20px;
}

@keyframes domChanged { from { background: yellow; } }
@-webkit-keyframes domChanged { from { background: yellow; } }
.ember-view { animation: domChanged 1s; -webkit-animation: domChanged 1s; }
Empty file added app/templates/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h2 id='title'>Welcome to Ember.js</h2>

{{outlet}}
3 changes: 3 additions & 0 deletions app/templates/component-test.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#each}}
{{pretty-color name=this}}
{{/each}}
Empty file.
1 change: 1 addition & 0 deletions app/templates/components/pretty-color.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pretty Color: {{name}}
1 change: 1 addition & 0 deletions app/templates/helper-test.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h3>My name is {{reverse-word name}}.</h3>
5 changes: 5 additions & 0 deletions app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul>
{{#each}}
<li>{{this}}</li>
{{/each}}
</ul>
Empty file added app/utils/.gitkeep
Empty file.
Empty file added app/views/.gitkeep
Empty file.
154 changes: 154 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
var fs = require('fs')
var path = require('path')
var mktemp = require('mktemp')
var rimraf = require('rimraf')
var walk = require('walk')
var hapi = require('hapi')
var synchronized = require('synchronized')
var Gaze = require('gaze').Gaze
var es6Compiler = require("es6-module-transpiler").Compiler;


var Generator
exports.Generator = Generator = function (src) {
this.src = src
}

Generator.prototype.regenerate = function () {
var self = this
// Should debounce, e.g. when you do `touch *`
synchronized(this, function (done) {
self.cleanup()
self.createDest()

self.writeAppJs(function () {
self.copyHtmlFiles(function () {
console.log('Regenerated')
done()
})
})
})
}

Generator.prototype.writeAppJs = function (callback) {
appJs = fs.createWriteStream(this.dest + '/app.js')

// Write vendor files (this needs to go away)
var files = fs.readdirSync(__dirname + '/vendor')
for (var i = 0; i < files.length; i++) {
contents = fs.readFileSync(__dirname + '/vendor/' + files[i])
appJs.write(contents)
}

// Write app files
var modulePrefix = 'appkit/'
walkFiles(this.src, 'js', function (fileInfo, fileStats, next) {
var fileContents = fs.readFileSync(fileInfo.fullPath).toString()
var compiler = new es6Compiler(fileContents, modulePrefix + fileInfo.moduleName)
var output = compiler.toAMD() // ERR: handle exceptions
appJs.write(output + "\n")
next()
}, function () {
appJs.end()
callback()
})
}

Generator.prototype.copyHtmlFiles = function (callback) {
var self = this
walkFiles(this.src, 'html', function (fileInfo, fileStats, next) {
var contents = fs.readFileSync(fileInfo.fullPath)
fs.writeFileSync(self.dest + '/' + fileInfo.relativePath, contents)
next()
}, function () {
callback()
})
}

Generator.prototype.createDest = function () {
if (this.dest == null) {
this.dest = mktemp.createDirSync('broccoli-XXXXXX.tmp')
}
return this.dest
}

Generator.prototype.cleanup = function () {
if (this.dest != null) {
// This is asynchronous, but we don't wait for the directory to disappear
rimraf(this.dest, function () { })
}
this.dest = null
}

Generator.prototype.serve = function () {
var self = this

this.regenerate()

var gaze = new Gaze([this.src + '/**/*', __dirname + '/vendor/**/*']);
gaze.on('all', function () {
self.regenerate()
})

var server = hapi.createServer('localhost', 8000);

// Add the route
server.route({
method: 'GET',
path: '/{path*}',
handler: {
directory: {
path: function (request) {
return self.dest
}
}
}
});

server.ext('onRequest', function (request, next) {
// `synchronized` delays serving until we've finished regenerating
synchronized(self, function (done) {
next()
done()
})
})

// Start the server
server.start();
}


// Tree recursion helper to iterate over files with given extension
var walkFiles = function (root, extension, fileCallback, endCallback) {
var walker = walk.walk(root, {})

walker.on('names', function (fileRoot, nodeNamesArray) {
nodeNamesArray.sort()
})

walker.on('file', function (fileRoot, fileStats, next) {
if (fileStats.name.slice(-(extension.length + 1)) === '.' + extension) {
var fileInfo = {}
fileInfo.fullPath = fileRoot + '/' + fileStats.name
fileInfo.relativePath = fileInfo.fullPath.slice(root.length + 1)
fileInfo.moduleName = fileInfo.relativePath.slice(0, -(extension.length + 1))
fileCallback(fileInfo, fileStats, next)
} else {
next()
}
})

walker.on('errors', function (fileRoot, nodeStatsArray, next) {
// ERR
console.error('Warning: unhandled error(s)', nodeStatsArray)
next()
})

walker.on('end', function () {
endCallback()
})
}


var generator = new Generator('app')
generator.serve()
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "broccoli",
"description": "Fast client-side asset builder",
"version": "0.0.2",
"author": "Jo Liss <joliss42@gmail.com>",
"main": "index.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/joliss/broccoli"
},

"dependencies" : {
"mktemp": "latest",
"rimraf": "latest",
"walk": "latest",
"hapi": "latest",
"gaze": "latest",
"es6-module-transpiler": "latest",
"synchronized": "latest"
}
}
Loading

0 comments on commit c4e1ae0

Please sign in to comment.