From 77526749bcbf3d43df1a5c7e15da03d38a4c8e24 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 17 Jul 2013 22:54:07 +0400 Subject: [PATCH] add emmet updater --- demo/kitchen-sink/demo.js | 4 +- tool/update_deps.js | 246 +++++++++++++++++++++----------------- 2 files changed, 136 insertions(+), 114 deletions(-) diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index 193da9bb..7e88967e 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -520,10 +520,10 @@ new StatusBar(env.editor, cmdLine.container); var Emmet = require("ace/ext/emmet"); -net.loadScript("https://rawgithub.com/nightwing/emmet-core/master/emmet.js", function() { +net.loadScript("http://nightwing.github.io/emmet-core/emmet.js", function() { Emmet.setCore(window.emmet); env.editor.setOption("enableEmmet", true); -}) +}); // require("ace/placeholder").PlaceHolder; diff --git a/tool/update_deps.js b/tool/update_deps.js index bdb73a9e..b7726abc 100644 --- a/tool/update_deps.js +++ b/tool/update_deps.js @@ -3,154 +3,176 @@ var https = require("https") , url = require("url") , fs = require("fs"); +var async = require("asyncjs"); var rootDir = __dirname + "/../lib/ace/"; var deps = [{ - path: "mode/css/csslint.js", - url: "https://raw.github.com/stubbornella/csslint/master/release/csslint-node.js", - needsFixup: true + path: "mode/css/csslint.js", + url: "https://raw.github.com/stubbornella/csslint/master/release/csslint-node.js", + needsFixup: true }, { - path: "../../demo/kitchen-sink/require.js", - url: "https://raw.github.com/jrburke/requirejs/master/require.js", - needsFixup: false + path: "../../demo/kitchen-sink/require.js", + url: "https://raw.github.com/jrburke/requirejs/master/require.js", + needsFixup: false }, { - path: "mode/lua/luaparse.js", - url: "https://raw.github.com/oxyc/luaparse/master/luaparse.js", - needsFixup: true, - postProcess: function(src) { - return src.replace( - /\(function\s*\(root,\s*name,\s*factory\)\s*{[\s\S]*?}\(this,\s*'luaparse',/, - "(function (root, name, factory) {\n factory(exports)\n}(this, 'luaparse'," - ) - } + path: "mode/lua/luaparse.js", + url: "https://raw.github.com/oxyc/luaparse/master/luaparse.js", + needsFixup: true, + postProcess: function(src) { + return src.replace( + /\(function\s*\(root,\s*name,\s*factory\)\s*{[\s\S]*?}\(this,\s*'luaparse',/, + "(function (root, name, factory) {\n factory(exports)\n}(this, 'luaparse'," + ) + } }, { - path: "mode/javascript/jshint.js", - url: "http://jshint.com/get/jshint-2.1.4.js", - needsFixup: true, - postProcess: function(src) { - src = src.replace(/(\],|\{)((?:\d+|"\w+"):\[)/g, "$1\n$2") + path: "mode/javascript/jshint.js", + url: "http://jshint.com/get/jshint-2.1.4.js", + needsFixup: true, + postProcess: function(src) { + src = src.replace(/(\],|\{)((?:\d+|"\w+"):\[)/g, "$1\n$2") .replace(/^(\},)(\{[^{}\[\]]*?\}\])/gm, "$1\n$2") - + src = src.replace( /"Expected a conditional expression and instead saw an assignment."/g, '"Assignment in conditional expression"' ); - + src = src.replace(/\brequire\(["']|\(require,|\(require\)/g, function(r){ return r.replace("require", "req"); }) - + src = src.replace(/var defaultMaxListeners = 10;/, function(a) {return a.replace("10", "200")}); - + src = src.replace(/var JSHINT;\s*\(function[\s()]+\{\s*/, "") .replace(/JSHINT = .*\n\s*\}\(\)\);\s*/, ""); src += '\n' + 'function req() {return require.apply(this, arguments)}\n' + 'module.exports = req("jshint");\n'; return src; - } + } +}, { + path: "ext/emmet-core.js", + url: [ + "https://raw.github.com/sergeche/emmet-sublime/master/emmet/emmet-app.js", + "https://raw.github.com/sergeche/emmet-sublime/master/emmet/snippets.json" + ], + postProcess: function(data) { + return data[0] + .replace("define(emmet)", "define('emmet', [], emmet)") + .replace(/(emmet.define\('bootstrap'.*)[\s\S]*$/, function(_, x) { + return x + "\n" + + "var snippets = " + data[1] + ";\n" + + "var res = require('resources');\n" + + "var userData = res.getVocabulary('user') || {};\n" + + "res.setVocabulary(require('utils').deepMerge(userData, snippets), 'user');\n" + + "});"; + }); + } }]; var download = function(href, callback) { - var options = url.parse(href); - var protocol = options.protocol === "https:" ? https : http; - console.log("connecting to " + options.host + " " + options.path); - protocol.get(options, function(res) { - var data = ""; - res.setEncoding("utf-8"); + if (Array.isArray(href)) + return async.map(href, download, callback); - res.on("data", function(chunk){ - data += chunk; - }); + var options = url.parse(href); + var protocol = options.protocol === "https:" ? https : http; + console.log("connecting to " + options.host + " " + options.path); + protocol.get(options, function(res) { + var data = ""; + res.setEncoding("utf-8"); - res.on("end", function(){ - callback(data); - }); - }); + res.on("data", function(chunk){ + data += chunk; + }); + + res.on("end", function(){ + callback(null, data); + }); + }); }; var getDep = function(dep) { - download(dep.url, function(data) { - if (dep.postProcess) - data = dep.postProcess(data); - if (dep.needsFixup) - data = "define(function(require, exports, module) {\n" - + data - + "\n});"; - - fs.writeFile(rootDir + dep.path, data, "utf-8", function(err){ - if (err) throw err; - console.log("File " + dep.path + " saved."); - }); - }); + download(dep.url, function(err, data) { + if (dep.postProcess) + data = dep.postProcess(data); + if (dep.needsFixup) + data = "define(function(require, exports, module) {\n" + + data + + "\n});"; + + fs.writeFile(rootDir + dep.path, data, "utf-8", function(err){ + if (err) throw err; + console.log("File " + dep.path + " saved."); + }); + }); }; -deps.forEach(getDep); +deps.slice(-1).forEach(getDep); // coffee-script void function(){ - var rootHref = "https://raw.github.com/jashkenas/coffee-script/master/"; - var path = "mode/coffee/"; - - var subDir = "lib/coffee-script/"; - var deps = [ - "helpers.js", - "lexer.js", - "nodes.js", - "parser.js", - "rewriter.js", - "scope.js" - ].map(function(x) { - return { - name: x, - href: rootHref + subDir + x, - path: rootDir + path + x - }; - }); - deps.push({name:"LICENSE", href: rootHref + "LICENSE"}); - - var downloads = {}, counter = 0; - - deps.forEach(function(x) { - download(x.href, function(data) { - counter++; - downloads[x.name] = data; - if (counter == deps.length) - allDone(); - }); - }); - function allDone() { - deps.pop(); - var license = downloads.LICENSE.split('\n'); - license = "/**\n * " + license.join("\n * ") + "\n */"; - - deps.forEach(function(x) { - var data = downloads[x.name]; - console.log(x.name); - console.log(!data); - if (!data) - return; - if (x.name == "parser.js") { - data = data.replace("var parser = (function(){", "") - .replace(/\nreturn (new Parser)[\s\S]*$/, "\n\nmodule.exports = $1;\n\n"); - } else { - data = data.replace("(function() {", "") - .replace(/\}\).call\(this\);\s*$/, ""); - } - data = license - + "\n\n" - + "define(function(require, exports, module) {\n" - + data - + "\n});"; - - fs.writeFile(x.path, data, "utf-8", function(err){ - if (err) throw err; - console.log("File " + x.name + " saved."); + var rootHref = "https://raw.github.com/jashkenas/coffee-script/master/"; + var path = "mode/coffee/"; + + var subDir = "lib/coffee-script/"; + var deps = [ + "helpers.js", + "lexer.js", + "nodes.js", + "parser.js", + "rewriter.js", + "scope.js" + ].map(function(x) { + return { + name: x, + href: rootHref + subDir + x, + path: rootDir + path + x + }; + }); + deps.push({name:"LICENSE", href: rootHref + "LICENSE"}); + + var downloads = {}, counter = 0; + + deps.forEach(function(x) { + download(x.href, function(err, data) { + counter++; + downloads[x.name] = data; + if (counter == deps.length) + allDone(); + }); + }); + function allDone() { + deps.pop(); + var license = downloads.LICENSE.split('\n'); + license = "/**\n * " + license.join("\n * ") + "\n */"; + + deps.forEach(function(x) { + var data = downloads[x.name]; + console.log(x.name); + console.log(!data); + if (!data) + return; + if (x.name == "parser.js") { + data = data.replace("var parser = (function(){", "") + .replace(/\nreturn (new Parser)[\s\S]*$/, "\n\nmodule.exports = $1;\n\n"); + } else { + data = data.replace("(function() {", "") + .replace(/\}\).call\(this\);\s*$/, ""); + } + data = license + + "\n\n" + + "define(function(require, exports, module) {\n" + + data + + "\n});"; + + fs.writeFile(x.path, data, "utf-8", function(err){ + if (err) throw err; + console.log("File " + x.name + " saved."); console.warn("mode/coffee/coffee-script file needs to updated manually"); console.warn("mode/coffee/parser.js: parseError function needs to be modified"); - }); - }); - } + }); + }); + } }//();