Skip to content

Commit

Permalink
Build: Prepend copyright notice and release info to every JS build.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayarjo committed Feb 16, 2013
1 parent 16ccefe commit 8709035
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 41 deletions.
3 changes: 3 additions & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ task("mkjs", [], function () {
amdlc.compileSource(modules, options);
amdlc.compileDevelopment(modules, options);

var releaseInfo = tools.getReleaseInfo("./changelog.txt");
tools.addReleaseDetailsTo(targetDir, releaseInfo);

// add compatibility
if (process.env.compat !== 'no') {
tools.addCompat({
Expand Down
63 changes: 35 additions & 28 deletions build/BuildTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ var getReleaseInfo = function (srcPath) {
if (!fs.existsSync(srcPath)) {
console.info(srcPath + " cannot be found.");
process.exit(1);
}
}

var src = fs.readFileSync(srcPath).toString();

Expand All @@ -298,46 +298,53 @@ var getReleaseInfo = function (srcPath) {
process.exit(1);
}

// assume that very first file in array will have the copyright
var copyright = (function() {
var matches = fs.readFileSync(srcPath).toString().match(/^\/\*[\s\S]+?\*\//);
return matches ? matches[0] : null;
}());

return {
version: info[1],
releaseDate: info[2],
fileVersion: info[1].replace(/\./g, '_'),
headNote: copyright
};
fileVersion: info[1].replace(/\./g, '_')
}
};

// inject version details and copyright header if available to all js files in specified directory
var addReleaseDetailsTo = function (dir, info) {
var contents, filePath;

if (fs.existsSync(dir)) {
fs.readdirSync(dir).forEach(function(fileName) {
if (fileName && /\.js$/.test(fileName)) {
filePath = path.join(dir + "/" + fileName);

if (info.headNote) {
contents = info.headNote + "\n" + fs.readFileSync(filePath).toString();
}
var addReleaseDetailsTo = function (destPath, info) {
var self = this, headNote, headNotePath = "./build/headnote.txt";

contents = contents.replace(/\@@([^@]+)@@/g, function($0, $1) {
switch ($1) {
case "version": return info.version;
case "releasedate": return info.releaseDate;
}
});
function processFile(filePath) {

if (headNote) {
contents = headNote + "\n" + fs.readFileSync(filePath);
}

fs.writeFileSync(filePath, contents);
contents = contents.replace(/@@([^@]+)@@/g, function($0, $1) {
switch ($1) {
case "version": return info.version;
case "releasedate": return info.releaseDate;
}
});

fs.writeFileSync(filePath, contents);
}

function isTextFile(filePath) {
return /\.(js|txt)$/.filePath;
}

if (fs.existsSync(headNotePath)) {
headNote = fs.readFileSync(headNotePath).toString();
}

var stat = fs.statSync(destPath);

if (stat.isFile()) {
processFile(destPath);
} else if (stat.isDirectory()) {
fs.readdirSync(destPath).forEach(function(fileName) {
self.addReleaseDetailsTo(path.join(destPath, fileName), info);
});
}
};


function compileAmd(options) {
require("amdlc").compile(options);
}
Expand Down
12 changes: 12 additions & 0 deletions build/headnote.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* mOxie - multi-runtime File API & XMLHttpRequest L2 Polyfill
* v@@version@@
*
* Copyright 2013, Moxiecode Systems AB
* Released under GPL License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*
* Date: @@releasedate@@
*/
13 changes: 0 additions & 13 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,2 @@
/**
* mOxie - multi-runtime File API & XMLHttpRequest L2 Polyfill
* v@@version@@
*
* Copyright 2012, Moxiecode Systems AB
* Released under GPL License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*
* Date: @@releasedate@@
*/

Version 1.0a (2012-11-13)
First public alpha of mOxie.

0 comments on commit 8709035

Please sign in to comment.