Browse files

first commit

  • Loading branch information...
0 parents commit 667feb90543eb4eccda0312b7e4ed0dad23567f4 @diffsky committed Feb 13, 2013
Showing with 183 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 .npmignore
  3. +22 −0 LICENSE
  4. +30 −0 README.md
  5. +32 −0 bin/dusting
  6. +68 −0 index.js
  7. +29 −0 package.json
1 .gitignore
@@ -0,0 +1 @@
+node_modules
1 .npmignore
@@ -0,0 +1 @@
+node_modules
22 LICENSE
@@ -0,0 +1,22 @@
+MIT License
+===========
+
+Copyright (c) 2013 Matt Hadley <matthew.hadley@gmail.com>
+
+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.
30 README.md
@@ -0,0 +1,30 @@
+# dusting
+
+compiles dust.js templates
+
+## installation
+
+For use in other node projects:
+
+ npm install dusting
+
+As a command line tool:
+
+ npm install dusting -g
+
+## usage
+
+in a node project (designed to be used synchronously):
+
+ var dusting = require('dusting');
+ dusting({
+ input: <input>,
+ output: <output>
+ });
+
+command line:
+
+ dusting <input> [output]
+
+ - `<input>` path to a directory containing dust.js templates (`*.dust`).
+ - `[output]` directory to write output to, defaults to cwd
32 bin/dusting
@@ -0,0 +1,32 @@
+#!/usr/bin/env node
+
+var program = require('commander'),
+ path = require('path'),
+ dusting = require('../');
+
+program
+ .version(require('../package.json').version)
+ .on('--help', function(){
+ console.log(' Example usage:');
+ console.log('');
+ console.log(' $ dusting inputdir [outputdir]');
+ console.log('');
+ })
+ .parse(process.argv);
+
+if (! program.args[0]) {
+ console.log("dusting ERROR: no input dir");
+ process.exit(1);
+}
+
+if (! program.args[1]) {
+ program.args[1] = '.';
+ console.log("dusting WARN: no output specified, using current directory");
+ console.log();
+}
+
+var config = {
+ source: program.args[0],
+ output: program.args[1]
+};
+dusting(config);
68 index.js
@@ -0,0 +1,68 @@
+var diveSync = require('diveSync')
+ , fs = require('fs')
+ , path = require('path')
+ , compile = { root:[], sub:{}}
+ , dust = require('dustjs-helpers')
+ , output = '', name, dir, filename;
+
+function dustify(file, basename) {
+ filename = path.basename(file, '.dust');
+ return dust.compile(fs.readFileSync(file, 'utf-8'), basename+filename);
+}
+
+module.exports = function(config) {
+ var cwd = process.cwd();
+
+ config.source = path.normalize(path.join(cwd, config.source));
+ config.output = path.normalize(path.join(cwd, config.output));
+ config.rootOutput = config.rootOutput || 'templates.js';
+ config.rootOutput = path.normalize(path.join(config.output, config.rootOutput));
+
+ diveSync(config.source, {recursive: true, directories: false}, function(err, file) {
+ // only work with dust files
+ if( path.extname(file) !== '.dust') return false;
+ basename = path.relative(config.source, file);
+ dir = '';
+ if(basename.indexOf(path.sep) !== -1) {
+ dir = path.dirname(basename);
+ dir = dir.replace(/\//g, ".")
+ }
+ if(dir) {
+ compile.sub[dir] = compile.sub[dir] || [];
+ compile.sub[dir].push({name:basename,fn:dustify(file, dir+'.')});
+ } else {
+ compile.root.push({name:basename,fn:dustify(file, dir)});
+ }
+ });
+
+ console.log('dusting');
+ console.log('source: '+config.source);
+ console.log('output: '+config.output);
+ console.log();
+ compile.root.forEach(function(file){
+ output = output + file.fn + "\n";
+ console.log('+ '+file.name);
+ });
+
+ if(output) {
+ fd = fs.openSync(config.rootOutput, "w");
+ fs.writeSync(fd, output, 0, "utf8");
+ console.log('|');
+ console.log('`---> '+path.relative(cwd, config.rootOutput));
+ console.log('');
+ }
+
+ for (var dir in compile.sub) {
+ output = '';
+ compile.sub[dir].forEach(function(file){
+ output = output + file.fn + "\n";
+ console.log('+ '+file.name);
+ });
+ filename = path.join(config.output, dir + '.js');
+ fd = fs.openSync(filename, "w");
+ fs.writeSync(fd, output, 0, "utf8");
+ console.log('|');
+ console.log('`---> '+path.relative(cwd, filename));
+ console.log('');
+ };
+}
29 package.json
@@ -0,0 +1,29 @@
+{
+ "name": "dusting",
+ "version": "0.0.1",
+ "description": "cli and node module to compile dust.js templates",
+ "main": "dusting.js",
+ "dependencies": {
+ "commander": "~1.0.4",
+ "diveSync": "0.2.0",
+ "dustjs-linkedin": "1.1.1",
+ "dustjs-helpers": "1.1.0"
+ },
+ "devDependencies": {},
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "bin": {
+ "dusting": "bin/dusting"
+ },
+ "keywords": [
+ "dust",
+ "dust.js",
+ "linkedin",
+ "compile",
+ "precompile"
+ ],
+ "author": "Matt Hadley <matthew.hadley@gmail.com>",
+ "license": "MIT",
+ "readmeFilename": "README.md"
+}

0 comments on commit 667feb9

Please sign in to comment.