Updated markoc to allow custom app module paths and to use the marko module installed in the project

This commit is contained in:
Patrick Steele-Idem 2014-11-12 16:46:47 -07:00
parent 490361e2b3
commit 40ae3888e0
2 changed files with 105 additions and 71 deletions

View File

@ -1,11 +1,32 @@
var markoCompiler = require('../compiler');
var fs = require('fs'); var fs = require('fs');
var nodePath = require('path'); var nodePath = require('path');
var Minimatch = require('minimatch').Minimatch;
var cwd = process.cwd(); var cwd = process.cwd();
var resolveFrom = require('resolve-from');
// Try to use the Marko compiler installed with the project
var markoCompilerPath;
try {
markoCompilerPath = resolveFrom(process.cwd(), 'marko/compiler');
} catch(e) {}
var markoCompiler;
if (markoCompilerPath) {
markoCompiler = require(markoCompilerPath);
} else {
markoCompiler = require('../compiler');
}
var Minimatch = require('minimatch').Minimatch;
var appModulePath = require('app-module-path');
require('raptor-polyfill/string/startsWith'); require('raptor-polyfill/string/startsWith');
require('raptor-polyfill/string/endsWith'); require('raptor-polyfill/string/endsWith');
markoCompiler.defaultOptions.checkUpToDate = false;
var mmOptions = { var mmOptions = {
matchBase: true, matchBase: true,
dot: true, dot: true,
@ -34,6 +55,10 @@ var args = require('raptor-args').createParser({
'--clean -c': { '--clean -c': {
type: 'boolean', type: 'boolean',
description: 'Clean all of the *.marko.js files' description: 'Clean all of the *.marko.js files'
},
'--paths -p': {
type: 'string[]',
description: 'Additional directories to add to the Node.js module search path'
} }
}) })
.usage('Usage: $0 <pattern> [options]') .usage('Usage: $0 <pattern> [options]')
@ -65,6 +90,13 @@ var args = require('raptor-args').createParser({
.parse(); .parse();
var paths = args.paths;
if (paths && paths.length) {
paths.forEach(function(path) {
appModulePath.addPath(nodePath.resolve(cwd, path));
});
}
var ignoreRules = args.ignore; var ignoreRules = args.ignore;
if (!ignoreRules) { if (!ignoreRules) {
@ -77,7 +109,7 @@ ignoreRules = ignoreRules.filter(function (s) {
}); });
ignoreRules = ignoreRules.map(function (pattern) { ignoreRules = ignoreRules.map(function (pattern) {
return new Minimatch(pattern, mmOptions); return new Minimatch(pattern, mmOptions);
}); });
@ -93,9 +125,9 @@ function isIgnored(path, dir, stat) {
var ignoreRulesLength = ignoreRules.length; var ignoreRulesLength = ignoreRules.length;
for (var i=0; i<ignoreRulesLength; i++) { for (var i=0; i<ignoreRulesLength; i++) {
var rule = ignoreRules[i]; var rule = ignoreRules[i];
var match = rule.match(path); var match = rule.match(path);
if (!match && stat && stat.isDirectory()) { if (!match && stat && stat.isDirectory()) {
try { try {
stat = fs.statSync(path); stat = fs.statSync(path);
@ -103,9 +135,9 @@ function isIgnored(path, dir, stat) {
if (stat && stat.isDirectory()) { if (stat && stat.isDirectory()) {
match = rule.match(path + '/'); match = rule.match(path + '/');
} }
} }
if (match) { if (match) {
if (rule.negate) { if (rule.negate) {
@ -149,7 +181,7 @@ function walk(files, options, done) {
} else { } else {
done(null); done(null);
} }
} }
} }
}; };
@ -176,7 +208,7 @@ function walk(files, options, done) {
doWalk(file); doWalk(file);
} else { } else {
fileCallback(file, context); fileCallback(file, context);
} }
} }
context.endAsync(); context.endAsync();
@ -221,7 +253,7 @@ if (args.clean) {
context.endAsync(); context.endAsync();
}); });
} }
} }
}, },
@ -231,7 +263,7 @@ if (args.clean) {
} else { } else {
console.log('Deleted ' + deleteCount + ' file(s)'); console.log('Deleted ' + deleteCount + ' file(s)');
} }
}); });
} else { } else {
@ -303,7 +335,7 @@ if (args.clean) {
} else { } else {
console.log('Compiled ' + compileCount + ' templates(s)'); console.log('Compiled ' + compileCount + ' templates(s)');
} }
}); });
} }
} }

View File

@ -1,59 +1,61 @@
{ {
"name": "marko", "name": "marko",
"description": "Marko is an extensible, streaming, asynchronous, high performance, HTML-based templating language that can be used in Node.js or in the browser.", "description": "Marko is an extensible, streaming, asynchronous, high performance, HTML-based templating language that can be used in Node.js or in the browser.",
"keywords": [ "keywords": [
"templating", "templating",
"template", "template",
"async", "async",
"streaming" "streaming"
], ],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/raptorjs/marko.git" "url": "https://github.com/raptorjs/marko.git"
}, },
"scripts": { "scripts": {
"test": "node_modules/.bin/mocha --ui bdd --reporter spec ./test && node_modules/.bin/jshint compiler/ runtime/ taglibs/" "test": "node_modules/.bin/mocha --ui bdd --reporter spec ./test && node_modules/.bin/jshint compiler/ runtime/ taglibs/"
}, },
"author": "Patrick Steele-Idem <pnidem@gmail.com>", "author": "Patrick Steele-Idem <pnidem@gmail.com>",
"maintainers": [ "maintainers": [
"Patrick Steele-Idem <pnidem@gmail.com>" "Patrick Steele-Idem <pnidem@gmail.com>"
], ],
"dependencies": { "dependencies": {
"async-writer": "^1.1.2", "app-module-path": "^1.0.0",
"char-props": "~0.1.5", "async-writer": "^1.1.2",
"events": "^1.0.2", "char-props": "~0.1.5",
"htmlparser2": "^3.7.2", "events": "^1.0.2",
"marko-async": "^1.1.0", "htmlparser2": "^3.7.2",
"marko-layout": "^1.1.0", "marko-async": "^1.1.0",
"minimatch": "^0.2.14", "marko-layout": "^1.1.0",
"property-handlers": "^1.0.0", "minimatch": "^0.2.14",
"raptor-args": "^1.0.0", "property-handlers": "^1.0.0",
"raptor-json": "^1.0.1", "raptor-args": "^1.0.0",
"raptor-logging": "^1.0.1", "raptor-json": "^1.0.1",
"raptor-modules": "^1.0.5", "raptor-logging": "^1.0.1",
"raptor-polyfill": "^1.0.0", "raptor-modules": "^1.0.5",
"raptor-promises": "^1.0.1", "raptor-polyfill": "^1.0.0",
"raptor-regexp": "^1.0.0", "raptor-promises": "^1.0.1",
"raptor-strings": "^1.0.0", "raptor-regexp": "^1.0.0",
"raptor-util": "^1.0.0", "raptor-strings": "^1.0.0",
"sax": "^0.6.0" "raptor-util": "^1.0.0",
}, "resolve-from": "^1.0.0",
"devDependencies": { "sax": "^0.6.0"
"chai": "~1.8.1", },
"dustjs-linkedin": "^2.3.4", "devDependencies": {
"jshint": "^2.5.0", "chai": "~1.8.1",
"mocha": "~1.15.1", "dustjs-linkedin": "^2.3.4",
"raptor-cache": "^1.1.1", "jshint": "^2.5.0",
"raptor-data-providers": "^1.0.1-beta", "mocha": "~1.15.1",
"through": "^2.3.4" "raptor-cache": "^1.1.1",
}, "raptor-data-providers": "^1.0.1-beta",
"license": "Apache License v2.0", "through": "^2.3.4"
"bin": { },
"markoc": "bin/markoc" "license": "Apache License v2.0",
}, "bin": {
"main": "runtime/marko-runtime.js", "markoc": "bin/markoc"
"publishConfig": { },
"registry": "https://registry.npmjs.org/" "main": "runtime/marko-runtime.js",
}, "publishConfig": {
"version": "1.3.8" "registry": "https://registry.npmjs.org/"
} },
"version": "1.3.8"
}