commonplace
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -9,19 +9,9 @@ #!/usr/bin/env node | ||
// Compilation dependencies | ||
var L10n = require('./L10n.js'); | ||
var opts = require('./utils.js').opts; | ||
var glob = require('./utils.js').globSync; | ||
var utils = require('./utils'); | ||
var srcdir = require('./info').src_dir(); | ||
var args = process.argv; | ||
if (args) { | ||
// Remove the "node compile_templates.js" arguments | ||
args.shift(); | ||
args.shift(); | ||
} | ||
function process(folder, output_file, locale_file, opts) { | ||
function process(folder, output_file, callback) { | ||
var extensions = require('./deferparser').extensions || []; | ||
glob(folder, '.html', function(err, templates) { | ||
utils.glob(folder, '.html', function(err, templates) { | ||
var template_strings = ( | ||
@@ -39,9 +29,3 @@ '(function() {' + | ||
var cinst = new compiler.Compiler(extensions); | ||
// TODO: We probably won't need it, but preprocessing should | ||
// be added here. | ||
var parseTree = parser.parse(src, extensions); | ||
if (opts.l10n) { | ||
L10n.extract_template(src, parseTree, templates[i]); | ||
} | ||
cinst.compile(parseTree) | ||
cinst.compile(parser.parse(src, extensions)); | ||
template_strings += cinst.getCode(); | ||
@@ -76,28 +60,8 @@ }; | ||
fs.writeFile(output_file, template_strings); | ||
fs.writeFile(output_file, template_strings, callback); | ||
}); | ||
if (opts.compile || opts.l10n) { | ||
glob(__dirname + '/../hearth/media/js', '.js', function(err, js_files) { | ||
var fireplace_root = path.normalize(__dirname + '/../'); | ||
js_files.forEach(function(file) { | ||
var js_data = fs.readFileSync(file) + ''; | ||
L10n.extract_js(js_data, file.replace(fireplace_root, '')); | ||
}); | ||
}); | ||
L10n.save_po(locale_file); | ||
} | ||
} | ||
if (args && args.length >= 3) { | ||
var folder = args[0]; | ||
var output_file = args[1]; | ||
var locale_file = args[2]; | ||
var opts = opts(args.slice(3), {l10n: false}); | ||
process(folder, output_file, locale_file, opts); | ||
} else { | ||
module.exports.process = process; | ||
} | ||
module.exports.process = process; |
131
lib/utils.js
@@ -16,3 +16,3 @@ var fs = require('fs'); | ||
} | ||
if (last) {out[last] = true;} | ||
if (last) out[last] = true; | ||
return out; | ||
@@ -71,1 +71,130 @@ }; | ||
}; | ||
module.exports.copyDir = function(src, dest) { | ||
// `dest` is expected to be the path to a directory. | ||
// `src` is expected to be the path to a directory. | ||
if (!fs.existsSync(src)) { | ||
console.error('Source directory "' + src + '" doesn\'t exist.'); | ||
return; | ||
} | ||
function mkdirRecursive(dir) { | ||
var parent = path.resolve(dir, '../'); | ||
if (!fs.existsSync(parent)) { | ||
mkdirRecursive(parent); | ||
} | ||
fs.mkdirSync(dir); | ||
} | ||
if (!fs.existsSync(dest)) { | ||
mkdirRecursive(dest); | ||
} | ||
if (src.substr(src.length - 1) !== '/') { | ||
src += '/'; | ||
} | ||
if (dest.substr(dest.length - 1) !== '/') { | ||
dest += '/'; | ||
} | ||
var files_copied = 0; | ||
utils.globSync(src, '*', function(err, files) { | ||
files.forEach(function(file) { | ||
var interim_path = file.substr(src.length); | ||
var dest_file = dest + interim_path; | ||
var dir = path.dirname(dest_file); | ||
if (!fs.existsSync(dir)) { | ||
console.log(dir); | ||
mkdirRecursive(dir); | ||
} | ||
files_copied++; | ||
fs.readFile(file, function(err, data) { | ||
if (err) {return;} | ||
fs.writeFile(dest_file, data, function(err) { | ||
if (err) { | ||
console.warn('Error copying ' + interim_path, err); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
return files_copied; | ||
}; | ||
module.exports.removeFile = function(path, callback, silent) { | ||
fs.exists(path, function(exists) { | ||
if (!exists) { | ||
if (!silent) { | ||
console.warn('Cannot remove non-existing file: ' + path); | ||
} | ||
return; | ||
} | ||
fs.unlink(path, function(err) { | ||
if (!silent) { | ||
if (err) { | ||
console.warn('Unable to delete file: ' + path, err); | ||
} | ||
} | ||
if (callback) callback(err); | ||
}); | ||
}); | ||
}; | ||
module.exports.rmdirRecursive = function(path_, callback) { | ||
function rmdir(done) { | ||
fs.readdir(path_, function(err, list) { | ||
if (err) return done(err); | ||
var pending = list.length; | ||
if (!pending) return done(null); | ||
list.forEach(function(file) { | ||
file = path.resolve(path_, file); | ||
fs.stat(file, function(err, stat) { | ||
if (stat && stat.isDirectory()) { | ||
module.exports.rmdirRecursive(file, function() { | ||
if (!--pending) done(null); | ||
}); | ||
} else { | ||
fs.unlink(file, function() { | ||
if (!--pending) done(null); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
fs.exists(path_, function(exists) { | ||
if (!exists) { | ||
console.warn('Specified path does not exist: ' + path_); | ||
return; | ||
} | ||
rmdir(function(err) { | ||
if (err) return; | ||
fs.rmdir(path_, callback); | ||
}); | ||
}); | ||
}; | ||
module.exports.rmdirRecursiveSync = function(path) { | ||
// Recursive directory deletion. | ||
if (!fs.existsSync(path)) { | ||
console.warn('Specified path does not exist: ' + path); | ||
return; | ||
} | ||
var list = fs.readdirSync(path); | ||
list.forEach(function(file) { | ||
file = path + '/' + file; | ||
var stat = fs.statSync(file); | ||
if (stat && stat.isDirectory()) { | ||
rmdir(file); | ||
} else { | ||
fs.unlinkSync(file); | ||
} | ||
}); | ||
fs.rmdir(path); | ||
console.log('Removed: ' + path); | ||
}; |
{ | ||
"name": "commonplace", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "url": "git://github.com/mozilla/commonplace.git", |
@@ -43,5 +43,3 @@ # Commonplace | ||
* `commonplace update` | ||
* `commonplace lint` | ||
* L10n tools | ||
* a bunch of other stuff |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67
9604
784184
45
8
6