Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Escalante committed Sep 18, 2012
0 parents commit 5b3b935
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
.DS_Store
1 change: 1 addition & 0 deletions assets/js/app.coffee
@@ -0,0 +1 @@
console.log 'hello world'
28 changes: 28 additions & 0 deletions bin/roots
@@ -0,0 +1,28 @@
#!/usr/bin/env node

var fs = require('fs');
var path = require('path');
var colors = require('colors');
var watch = require('watch');
var coffeescript = require('../lib/compilers/coffee');

var current_directory = path.normalize(process.cwd());
var dir_contents = fs.readdirSync(current_directory);
var get_files = function(dir){ return fs.readdirSync(path.join(current_directory, dir)); }

// make sure this is a roots project

if (dir_contents.indexOf('app.coffee') > 0) {
// console.log('we have a legit app'.green);
} else {
// console.log('looks like youre missing the app.js file, try running roots new `name` to create a new project'.red);
}

// compile all the things!
coffeescript.compile(get_files('assets/js'));

// serve to public and open the browser

// create a watch task that does this on file change

// create a websockets server to interact with livereload and push changes live
23 changes: 23 additions & 0 deletions lib/compilers/coffee.js
@@ -0,0 +1,23 @@
var coffee = require('coffee-script');
var path = require('path');
var fs = require('fs');
var helpers = require('../helpers');
var current_directory = path.normalize(process.cwd());

exports.compile = function(files){
files.forEach(function(file, index){

// get all the info we need for the paths
var dir = path.normalize(path.dirname(file));
var basename = path.normalize(path.basename(file, '.coffee'));
var file_contents = fs.readFileSync(path.join(current_directory, '/assets/js', file), 'utf8');
var compiled_path = path.join(current_directory, 'public/js', dir, (basename + '.js'));
var compiled_js = coffee.compile(file_contents);

// create directories if needed
helpers.mkdirp(path.join(current_directory, 'public/js', dir), '0777', function(){
fs.writeFileSync(compiled_path, compiled_js); // then write the file
});

});
}
17 changes: 17 additions & 0 deletions lib/helpers.js
@@ -0,0 +1,17 @@
// mkdir -p
// http://lmws.net/making-directory-along-with-missing-parents-in-node-js

var fs = require('fs');
var path = require('path');

exports.mkdirp = function(dirPath, mode, callback) {
var self = this;
fs.mkdir(dirPath, mode, function(error) {
if (error && error.errno === 34) {
self.mkdirp(path.dirname(dirPath), mode, callback);
self.mkdirp(dirPath, mode, callback);
} else {
callback();
}
});
}
15 changes: 15 additions & 0 deletions lib/server.js
@@ -0,0 +1,15 @@
// config
var port = 3000;

var connect = require('connect');
var colors = require('colors');
var open = require('open');
// might want to add supervisor for view reloads

var app = connect()
.use(connect.logger('dev'))
.use(connect.static('/Users/jeffescalante/Desktop/public'));

console.log(('\nserver started on port ' + port + '\n').green);
app.listen(port);
open('http://localhost:' + port);
37 changes: 37 additions & 0 deletions package.json
@@ -0,0 +1,37 @@
{
"name": "roots",
"version": "1.0.0",
"description": "Roots is where it all begins",
"keywords": [
"front-end",
"development",
"css",
"build",
"library",
"tool"
],
"homepage": "http://roots.carrotbeta.com",
"bugs": "https://github.com/roots/roots-static/issues",
"author": "Jeff Escalante",
"main": "./roots",
"bin": {
"roots": "./bin/roots"
},
"repository": {
"type": "git",
"url": "git://github.com/carrot/roots-static.git"
},
"scripts": {
"uninstall": "rm -rf ~/.roots"
},
"dependencies": {
"connect": "latest",
"colors": "latest",
"open": "latest",
"coffee-script": "~1.3.3",
"watch": "~0.5.1"
},
"engines": {
"node": ">=0.8.0"
}
}
5 changes: 5 additions & 0 deletions public/js/app.js
@@ -0,0 +1,5 @@
(function() {

console.log('hello world');

}).call(this);
5 changes: 5 additions & 0 deletions readme.md
@@ -0,0 +1,5 @@
# Roots CLI

This is the beginnings of a really fantastic command line build tool. Super super alpha, don't even think about attempting to install this.

The assets folder is temporary, just used for example files and convenience during development.

0 comments on commit 5b3b935

Please sign in to comment.