include ace/requirejs/text in build to not depend on require text plugin

fixes issue #708
This commit is contained in:
nightwing 2012-08-05 14:59:27 +04:00
commit 42219c2379
3 changed files with 53 additions and 41 deletions

View file

@ -34,7 +34,7 @@
* and other provisions required by the GPL or the LGPL. If you do not delete * and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under * the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL. * the terms of any one of the MPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
var fs = require("fs"); var fs = require("fs");
@ -174,16 +174,21 @@ function demo() {
ref = ""; ref = "";
version = ""; version = "";
} }
var changeComments = function(data) {
return (data function changeComments(data) {
.replace(/<!\-\-DEVEL[\d\D]*?DEVEL\-\->/g, "") return (data
.replace(/PACKAGE\-\->|<!\-\-PACKAGE/g, "") .replace(/<!\-\-DEVEL[\d\D]*?DEVEL\-\->/g, "")
.replace(/\/\*DEVEL[\d\D]*?DEVEL\*\//g, "") .replace(/PACKAGE\-\->|<!\-\-PACKAGE/g, "")
.replace(/PACKAGE\*\/|\/\*PACKAGE/g, "") .replace(/\/\*DEVEL[\d\D]*?DEVEL\*\//g, "")
.replace("%version%", version) .replace(/PACKAGE\*\/|\/\*PACKAGE/g, "")
.replace("%commit%", ref) .replace("%version%", version)
); .replace("%commit%", ref)
} );
};
function fixDocPaths(data) {
return data.replace(/"(demo|build)\//g, "\"");
}
copy({ copy({
source: ACE_HOME + "/kitchen-sink.html", source: ACE_HOME + "/kitchen-sink.html",
@ -210,9 +215,7 @@ function demo() {
copy({ copy({
source: ACE_HOME + "/demo/kitchen-sink/demo.js", source: ACE_HOME + "/demo/kitchen-sink/demo.js",
dest: demo, dest: demo,
filter: [changeComments, function(data) { filter: [changeComments, fixDocPaths, function(data) {
return data.replace(/"(demo|build)\//g, "\"");
}, function(data) {
return data.replace("define(", "define('kitchen-sink/demo',"); return data.replace("define(", "define('kitchen-sink/demo',");
}] }]
}); });
@ -237,6 +240,14 @@ function buildAce(options) {
textPluginPattern: /^ace\/requirejs\/text!/ textPluginPattern: /^ace\/requirejs\/text!/
}; };
var modeNames = fs.readdirSync(ACE_HOME + "/lib/ace/mode").map(function(x) {
if (x.slice(-3) == ".js" && !/_highlight_rules|_test|_worker|xml_util|_outdent|behaviour/.test(x))
return x.slice(0, -3);
}).filter(function(x) { return !!x; });
var themeNames = fs.readdirSync(ACE_HOME + "/lib/ace/theme").map(function(x){
return x.slice(-3) == ".js" && x.slice(0, -3);
}).filter(function(x){ return !!x; });
var defaults = { var defaults = {
targetDir: BUILD_DIR + "/src", targetDir: BUILD_DIR + "/src",
ns: "ace", ns: "ace",
@ -246,13 +257,8 @@ function buildAce(options) {
noconflict: false, noconflict: false,
suffix: null, suffix: null,
name: "ace", name: "ace",
modes: fs.readdirSync(ACE_HOME + "/lib/ace/mode").map(function(x) { modes: modeNames,
if (x.slice(-3) == ".js" && !/_highlight_rules|_test|_worker|xml_util|_outdent|behaviour/.test(x)) themes: themeNames,
return x.slice(0, -3);
}).filter(function(x) { return !!x; }),
themes: fs.readdirSync(ACE_HOME + "/lib/ace/theme").map(function(x){
return x.slice(-3) == ".js" && x.slice(0, -3);
}).filter(function(x){ return !!x; }),
workers: ["javascript", "coffee", "css", "json", "xquery"], workers: ["javascript", "coffee", "css", "json", "xquery"],
keybindings: ["vim", "emacs"] keybindings: ["vim", "emacs"]
}; };
@ -275,7 +281,6 @@ function buildAce(options) {
var filters = [ var filters = [
copy.filter.moduleDefines, copy.filter.moduleDefines,
filterTextPlugin,
removeUseStrict, removeUseStrict,
removeLicenceCmments removeLicenceCmments
]; ];
@ -376,7 +381,6 @@ function buildAce(options) {
filters = [ filters = [
copy.filter.moduleDefines, copy.filter.moduleDefines,
filterTextPlugin,
removeUseStrict, removeUseStrict,
removeLicenceCmments removeLicenceCmments
]; ];
@ -431,6 +435,22 @@ function cloneProject(project) {
return clone; return clone;
} }
copy.filter.addDefines = function(input, source) {
if (!source)
throw new Error('Missing filename for moduleDefines');
if (typeof input !== 'string')
input = input.toString();
var module = source.isLocation ? source.path : source;
input = input.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
input = '"' + input.replace(/\n/g, '\\n\\\n') + '"';
return 'define("ace/requirejs/text!' + module + '", [], ' + input + ');\n\n';
};
function copyFileSync(srcFile, destFile) { function copyFileSync(srcFile, destFile) {
var BUF_LENGTH = 64*1024, var BUF_LENGTH = 64*1024,
buf = new Buffer(BUF_LENGTH), buf = new Buffer(BUF_LENGTH),
@ -457,16 +477,12 @@ function quoteString(str) {
return '"' + str.replace(/\\/, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\\n") + '"'; return '"' + str.replace(/\\/, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\\n") + '"';
} }
function filterTextPlugin(text) {
return text.replace(/(['"])ace\/requirejs\/text\!/g, "$1text!");
}
function removeUseStrict(text) { function removeUseStrict(text) {
return text.replace(/['"]use strict['"];/g, ""); return text.replace(/['"]use strict['"];/g, "");
} }
function removeLicenceCmments(text) { function removeLicenceCmments(text) {
return text.replace(/(;)\s*\/\*[\d\D]*?\*\//g, "$1"); return text.replace(/(;)\s*\/\*[\d\D]*?\*\//g, "$1").replace(/\n\/\/ vim.*\n(\/\/.*\n)+/g, "");
} }
function namespace(ns) { function namespace(ns) {

View file

@ -204,4 +204,11 @@ function exportAce(ns) {
exportAce(ACE_NAMESPACE); exportAce(ACE_NAMESPACE);
})(); })();
define('ace/requirejs/text', ['require', 'exports', 'module'], function(require, exports, module) {
// this won't be called it is needed only for included text modules
exports.load = function (name, req, onLoad, config) {
require("ace/lib/net").get(req.toUrl(name), onLoad);
};
});

View file

@ -39,22 +39,11 @@
var buildAce = require("./Makefile.dryice").buildAce; var buildAce = require("./Makefile.dryice").buildAce;
var ACE_HOME = __dirname;
try { try {
var aceProject = { buildAce({
roots: [
ACE_HOME + '/lib',
ACE_HOME + '/demo'
],
textPluginPattern: /^ace\/requirejs\/text!/
};
buildAce(aceProject, {
compress: false, compress: false,
noconflict: false, noconflict: false,
suffix: "", suffix: "",
compat: true,
name: "ace" name: "ace"
}); });
} catch (e) { } catch (e) {