Permalink
Browse files

Build: Prepend copyright notice and release info to every JS build.

  • Loading branch information...
1 parent 16ccefe commit 87090353d7440bf8d4dcf3b3455bc8c6fb52edc8 @jayarjo jayarjo committed Feb 16, 2013
Showing with 50 additions and 41 deletions.
  1. +3 −0 Jakefile.js
  2. +35 −28 build/BuildTools.js
  3. +12 −0 build/headnote.txt
  4. +0 −13 changelog.txt
View
@@ -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({
View
@@ -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();
@@ -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);
}
View
@@ -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@@
+ */
View
@@ -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.