Revision bb9433616281f86936731603d9b03f14bc018ff0 authored by null-a on 18 April 2017, 12:39:35 UTC, committed by null-a on 18 April 2017, 12:55:37 UTC
1 parent 1d99c99
adify
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var path = require('path');
var adify = require('../src/transforms/adify').adify;
function findFiles(root, regex) {
function walk(dir) {
fs.readdirSync(dir).forEach(function(f) {
var p = path.join(dir, f);
if (fs.lstatSync(p).isDirectory()) {
walk(p);
} else if (f.match(regex)) {
matches.push(p);
}
});
}
var matches = [];
walk(root);
return matches;
}
var root = path.join(__dirname, '..', 'src');
function adRequirePath(srcFilename) {
var dir = path.dirname(srcFilename);
var adFileName = path.join(__dirname, '..', 'src', 'ad.js');
var adPath = path.normalize(path.dirname(path.relative(dir, adFileName)));
return adPath + '/' + 'ad.js';
}
// Don't match text editor temporary files. e.g. src/.#dists.ad.js
findFiles(root, /^(\w.*)\.ad\.js$/).forEach(function(inFile) {
var outFile = inFile.replace(/\.ad\.js$/, '.js');
var code = fs.readFileSync(inFile, 'utf8');
fs.writeFileSync(outFile, adify(code, adRequirePath(inFile)));
});
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...