Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Jun 20, 2014
1 parent e5b2eed commit 6714359
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 40 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pre_build:
build: pre_build
./Makefile.dryice.js normal
./Makefile.dryice.js demo
./Makefile.dryice.js bm

# Minimal build: call Makefile.dryice.js only if our sources changed
basic: build/src/ace.js
Expand Down
61 changes: 23 additions & 38 deletions Makefile.dryice.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,11 @@ function ace() {
function demo() {
console.log('# kitchen sink ---------');

var version, ref;
var version = "", ref = "";
try {
version = JSON.parse(fs.readFileSync(ACE_HOME + "/package.json")).version;
ref = fs.readFileSync(ACE_HOME + "/.git-ref").toString();
} catch(e) {
ref = "";
version = "";
}
} catch(e) {}

function changeComments(data) {
return (data
Expand All @@ -131,16 +128,12 @@ function demo() {
.replace("%commit%", ref)
);
}

copy(ACE_HOME + "/demo/kitchen-sink", BUILD_DIR + "/demo/kitchen-sink", {
shallow: true,
replace: [changeComments],
include: /\.(css|html)$/
});

copy(ACE_HOME +"/demo/kitchen-sink/docs/", BUILD_DIR + "/demo/kitchen-sink/docs/");

copy.file(ACE_HOME + "/demo/kitchen-sink/logo.png", BUILD_DIR + "/demo/kitchen-sink/logo.png");
copy.file(ACE_HOME + "/demo/kitchen-sink/styles.css", BUILD_DIR + "/demo/kitchen-sink/styles.css");
copy.file(ACE_HOME + "/kitchen-sink.html", BUILD_DIR + "/kitchen-sink.html", changeComments);

buildSubmodule({}, {
require: ["kitchen-sink/demo"],
Expand Down Expand Up @@ -214,9 +207,9 @@ function buildAceModule(opts, callback) {
buildAceModule.dequeue = function() {
if (buildAceModule.running) return;
var call = buildAceModule.queue.shift();
buildAceModule.running = call;
if (call)
buildAceModuleInternal.apply(null, call);
buildAceModule.running = call;
};
}

Expand All @@ -235,7 +228,7 @@ function buildAceModule(opts, callback) {

function buildAceModuleInternal(opts, callback) {
var cache = opts.cache == undefined ? CACHE : opts.cache;
var key = opts.require + "|" + opts.compress + "|" + opts.projectType;
var key = opts.require + "|" + opts.projectType;
if (cache && cache.configs && cache.configs[key])
return write(null, cache.configs[key]);

Expand All @@ -249,19 +242,23 @@ function buildAceModuleInternal(opts, callback) {
};

function write(err, result) {
if (opts.compress)
result.code = compress(result.code);

if (cache && key) {
if (cache && key && !(cache.configs && cache.configs[key])) {
cache.configs = cache.configs || Object.create(null);
cache.configs[key] = result;
result.sources = result.sources.map(function(pkg) {
return {deps: pkg.deps};
});
}
}

if (!opts.outputFile)
return callback(err, result);

var code = result.code;
if (opts.compress) {
if (!result.codeMin)
result.codeMin = compress(result.code);
code = result.codeMin;
}

var targetDir = BUILD_DIR + "/src";
if (opts.compress)
Expand All @@ -287,7 +284,6 @@ function buildAceModuleInternal(opts, callback) {
opts.noconflict ? ns : "", projectType == "ext"));
}

var code = result.code;
filters.forEach(function(f) { code = f(code); });

build.writeToFile({code: code}, {
Expand Down Expand Up @@ -331,7 +327,7 @@ function buildSubmodule(options, extra, file, callback) {
options = extend(extra, options);
getLoadedFileList(options, function(coreFiles) {
options.outputFile = file + ".js";
options.ignore = coreFiles;
options.ignore = options.ignore || coreFiles;
options.quiet = true;
buildAceModule(options, callback);
});
Expand Down Expand Up @@ -384,9 +380,10 @@ function buildAce(options) {
buildSubmodule(options, {
projectType: "worker",
require: ["ace/mode/" + name + "_worker"],
ignore: [],
additional: [{
id: "ace/worker/worker",
loaderModule: true,
transforms: [],
order: -1000
}],
}, "worker-" + name);
Expand Down Expand Up @@ -467,9 +464,7 @@ function namespace(ns) {
return function(text) {
text = text
.toString()
.replace('var ACE_NAMESPACE = "";', 'var ACE_NAMESPACE = "' + ns +'";')
// .replace(/(\.define)|([,;\n]|^\s*?)define\(/g, function(_, a, b) {
// return a || b + ns + ".define(";
.replace(/ACE_NAMESPACE\s*=\s*""/, 'ACE_NAMESPACE = "' + ns +'"')
.replace(/(\.define)|\bdefine\(/g, function(_, a) {
return a || ns + ".define(";
});
Expand Down Expand Up @@ -551,20 +546,10 @@ function addSnippetFile(modeName) {
}

function compress(text) {
return asciify(require("dryice").copy.filter.uglifyjs(text));
// copy.filter.uglifyjs.options.ascii_only = true; doesn't work with some uglify.js versions
function asciify(text) {
return text.replace(/[\x00-\x08\x0b\x0c\x0e\x19\x80-\uffff]/g, function(c) {
c = c.charCodeAt(0).toString(16);
if (c.length == 1)
return "\\x0" + c;
if (c.length == 2)
return "\\x" + c;
if (c.length == 3)
return "\\u0" + c;
return "\\u" + c;
});
}
var ujs = require("dryice").copy.filter.uglifyjs;
ujs.options.mangle_toplevel = {except: ["ACE_NAMESPACE", "requirejs"]};
ujs.options.beautify = {ascii_only: true, inline_script: true}
return ujs(text);
}

function extend(base, extra) {
Expand Down
2 changes: 1 addition & 1 deletion kitchen-sink.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
<script src="src/ace.js" data-ace-base="src" type="text/javascript" charset="utf-8"></script>
<script src="src/keybinding-vim.js"></script>
<script src="src/keybinding-emacs.js"></script>
<script src="kitchen-sink/demo.js"></script>
<script src="demo/kitchen-sink/demo.js"></script>
<script type="text/javascript" charset="utf-8">
require("kitchen-sink/demo");
</script>
Expand Down

0 comments on commit 6714359

Please sign in to comment.