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
* 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.
*
*
* ***** END LICENSE BLOCK ***** */
var fs = require("fs");
@ -174,16 +174,21 @@ function demo() {
ref = "";
version = "";
}
var changeComments = function(data) {
return (data
.replace(/<!\-\-DEVEL[\d\D]*?DEVEL\-\->/g, "")
.replace(/PACKAGE\-\->|<!\-\-PACKAGE/g, "")
.replace(/\/\*DEVEL[\d\D]*?DEVEL\*\//g, "")
.replace(/PACKAGE\*\/|\/\*PACKAGE/g, "")
.replace("%version%", version)
.replace("%commit%", ref)
);
}
function changeComments(data) {
return (data
.replace(/<!\-\-DEVEL[\d\D]*?DEVEL\-\->/g, "")
.replace(/PACKAGE\-\->|<!\-\-PACKAGE/g, "")
.replace(/\/\*DEVEL[\d\D]*?DEVEL\*\//g, "")
.replace(/PACKAGE\*\/|\/\*PACKAGE/g, "")
.replace("%version%", version)
.replace("%commit%", ref)
);
};
function fixDocPaths(data) {
return data.replace(/"(demo|build)\//g, "\"");
}
copy({
source: ACE_HOME + "/kitchen-sink.html",
@ -210,9 +215,7 @@ function demo() {
copy({
source: ACE_HOME + "/demo/kitchen-sink/demo.js",
dest: demo,
filter: [changeComments, function(data) {
return data.replace(/"(demo|build)\//g, "\"");
}, function(data) {
filter: [changeComments, fixDocPaths, function(data) {
return data.replace("define(", "define('kitchen-sink/demo',");
}]
});
@ -237,6 +240,14 @@ function buildAce(options) {
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 = {
targetDir: BUILD_DIR + "/src",
ns: "ace",
@ -246,13 +257,8 @@ function buildAce(options) {
noconflict: false,
suffix: null,
name: "ace",
modes: 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; }),
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; }),
modes: modeNames,
themes: themeNames,
workers: ["javascript", "coffee", "css", "json", "xquery"],
keybindings: ["vim", "emacs"]
};
@ -275,7 +281,6 @@ function buildAce(options) {
var filters = [
copy.filter.moduleDefines,
filterTextPlugin,
removeUseStrict,
removeLicenceCmments
];
@ -376,7 +381,6 @@ function buildAce(options) {
filters = [
copy.filter.moduleDefines,
filterTextPlugin,
removeUseStrict,
removeLicenceCmments
];
@ -431,6 +435,22 @@ function cloneProject(project) {
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) {
var BUF_LENGTH = 64*1024,
buf = new Buffer(BUF_LENGTH),
@ -457,16 +477,12 @@ function quoteString(str) {
return '"' + str.replace(/\\/, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\\n") + '"';
}
function filterTextPlugin(text) {
return text.replace(/(['"])ace\/requirejs\/text\!/g, "$1text!");
}
function removeUseStrict(text) {
return text.replace(/['"]use strict['"];/g, "");
}
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) {

View file

@ -204,4 +204,11 @@ function exportAce(ns) {
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 ACE_HOME = __dirname;
try {
var aceProject = {
roots: [
ACE_HOME + '/lib',
ACE_HOME + '/demo'
],
textPluginPattern: /^ace\/requirejs\/text!/
};
buildAce(aceProject, {
buildAce({
compress: false,
noconflict: false,
suffix: "",
compat: true,
name: "ace"
});
} catch (e) {