mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Added CLI for compiling rhtml files
This commit is contained in:
parent
cf6219d068
commit
bc778841d6
2
bin/rhtmlc
Executable file
2
bin/rhtmlc
Executable file
@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
require('./rhtmlc.js');
|
||||
82
bin/rhtmlc.js
Normal file
82
bin/rhtmlc.js
Normal file
@ -0,0 +1,82 @@
|
||||
var raptorTemplatesCompiler = require('../compiler');
|
||||
var glob = require("glob");
|
||||
var optimist = require('optimist');
|
||||
var fs = require('fs');
|
||||
var globPatterns;
|
||||
var raptorPromises = require('raptor-promises');
|
||||
|
||||
var argv = optimist
|
||||
.alias('n', 'name')
|
||||
.describe('n', 'The name of the page being optimized (e.g. "my-page")')
|
||||
.usage('Usage: $0 <pattern> [options]\nExamples:\n' +
|
||||
' Compile a single template:\n' +
|
||||
' $0 rhtml template.rhtml\n\n' +
|
||||
' Compile all templates in the directory tree:\n' +
|
||||
' $0 rhtml **/*.rhtml')
|
||||
.check(function(argv) {
|
||||
if (!argv._) {
|
||||
throw '';
|
||||
}
|
||||
})
|
||||
.argv;
|
||||
|
||||
globPatterns = argv._;
|
||||
var found = {};
|
||||
var promises = [];
|
||||
|
||||
function compile(path) {
|
||||
if (found[path]) {
|
||||
return;
|
||||
}
|
||||
|
||||
var deferred = raptorPromises.defer();
|
||||
|
||||
var outPath = path + '.js';
|
||||
console.log('Compiling "' + path + '" to "' + outPath + '"...');
|
||||
raptorTemplatesCompiler.compileFile(path, function(err, src) {
|
||||
if (err) {
|
||||
console.log('Failed to compile "' + path + '". Error: ' + (err.stack || err));
|
||||
deferred.reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
fs.writeFile(outPath, src, {encoding: 'utf8'}, function(err, src) {
|
||||
if (err) {
|
||||
console.log('Failed to write "' + path + '". Error: ' + (err.stack || err));
|
||||
deferred.reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
deferred.resolve();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
globPatterns.forEach(function(globPattern) {
|
||||
var deferred = raptorPromises.defer();
|
||||
|
||||
glob(globPattern, function (err, files) {
|
||||
if (err) {
|
||||
deferred.reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var compilePromises = files.map(compile);
|
||||
deferred.resolve(raptorPromises.all(compilePromises));
|
||||
});
|
||||
|
||||
|
||||
promises.push(deferred.promise);
|
||||
});
|
||||
|
||||
console.log('Promises: ', promises.length);
|
||||
raptorPromises.all(promises).then(
|
||||
function() {
|
||||
console.log('Done!');
|
||||
},
|
||||
function(err) {
|
||||
console.log('One or more templates failed to compile');
|
||||
});
|
||||
@ -43,10 +43,12 @@
|
||||
"raptor-cache": "^0.2.0-beta"
|
||||
},
|
||||
"license": "Apache License v2.0",
|
||||
"bin": {},
|
||||
"bin": {
|
||||
"rhtmlc": "bin/rhtmlc"
|
||||
},
|
||||
"main": "runtime/lib/raptor-templates.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"version": "0.2.13-beta"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user