Allow script to be run from anywhere

This commit is contained in:
Tim Schaub
2015-04-06 04:06:31 -06:00
parent 80048bd290
commit 8afb5698f1
+10 -6
View File
@@ -1,4 +1,5 @@
/*global Buffer */ /*global Buffer */
var path = require('path');
var Metalsmith = require('metalsmith'); var Metalsmith = require('metalsmith');
var templates = require('metalsmith-templates'); var templates = require('metalsmith-templates');
@@ -11,6 +12,10 @@ var cleanupJSRegEx = /.*(goog\.require(.*);|.*renderer: exampleNS\..*,?)[\n]*/g;
var isCssRegEx = /\.css$/; var isCssRegEx = /\.css$/;
var isJsRegEx = /\.js$/; var isJsRegEx = /\.js$/;
var srcDir = path.join(__dirname, '..', 'examples_src');
var destDir = path.join(__dirname, '..', 'examples');
var templatesDir = path.join(__dirname, '..', 'config', 'examples');
function main(callback) { function main(callback) {
function build(files) { function build(files) {
@@ -30,10 +35,9 @@ function main(callback) {
file.ol_version = pjson.version; file.ol_version = pjson.version;
file.js_resource = '<script src="loader.js?id=' + match[1] + file.js_resource = '<script src="loader.js?id=' + match[1] +
'"></script>'; '"></script>';
var js = fs.readFileSync(__dirname + '/../examples_src/' + var js = fs.readFileSync(path.join(srcDir, match[1] + '.js'), 'utf8');
match[1] + '.js', 'utf8');
file.js_inline = js.replace(cleanupJSRegEx, ''); file.js_inline = js.replace(cleanupJSRegEx, '');
var cssFile = __dirname + '/../examples_src/' + match[1] + '.css'; var cssFile = path.join(srcDir, match[1] + '.css');
if (fs.existsSync(cssFile)) { if (fs.existsSync(cssFile)) {
file.css_resource = '<link rel="stylesheet" href="' + match[1] + file.css_resource = '<link rel="stylesheet" href="' + match[1] +
'.css">'; '.css">';
@@ -65,12 +69,12 @@ function main(callback) {
new Metalsmith('.') new Metalsmith('.')
.source('examples_src') .source(srcDir)
.destination('examples') .destination(destDir)
.use(build) .use(build)
.use(templates({ .use(templates({
engine: 'handlebars', engine: 'handlebars',
directory: 'config/examples' directory: templatesDir
})) }))
.build(function(err) { .build(function(err) {
callback(err); callback(err);