From daa7cb9a2cafb5973ae163b8190d4fd683f8cfc7 Mon Sep 17 00:00:00 2001 From: "hongqi.gan" Date: Mon, 11 Apr 2016 21:52:54 +0800 Subject: [PATCH 1/7] feature add babel support default buildin is react and es2015 --- lib/compiler/plugins/jsx.js | 28 ++++++++ package.json | 119 ++++++++++++++++---------------- src/compiler/plugins/jsx.coffee | 16 +++++ 3 files changed, 105 insertions(+), 58 deletions(-) create mode 100644 lib/compiler/plugins/jsx.js create mode 100644 src/compiler/plugins/jsx.coffee diff --git a/lib/compiler/plugins/jsx.js b/lib/compiler/plugins/jsx.js new file mode 100644 index 0000000..7fcbe41 --- /dev/null +++ b/lib/compiler/plugins/jsx.js @@ -0,0 +1,28 @@ +// Generated by CoffeeScript 1.4.0 +(function() { + var babel, es2015, react, syspath; + + syspath = require('path'); + + babel = require('babel-core'); + + es2015 = require('babel-preset-es2015'); + + react = require('babel-preset-react'); + + exports.contentType = "javascript"; + + exports.process = function(txt, path, module, cb) { + var name; + try { + name = syspath.basename(path, '.jsx'); + txt = (babel.transform(txt, { + presets: [es2015, react] + })).code; + return cb(null, txt); + } catch (err) { + return cb(err); + } + }; + +}).call(this); diff --git a/package.json b/package.json index a353a1a..3e172d3 100644 --- a/package.json +++ b/package.json @@ -1,59 +1,62 @@ { - "author": "hao.lin ", - "name": "fekit", - "description": "FE Toolkit", - "version": "0.2.139", - "bin": "./bin/fekit", - "repository": { - "type": "git", - "url": "git://github.com/rinh/fekit.git" - }, - "dependencies": { - "async": "0.2.x", - "autoprefixer": "^6.0.3", - "cjson": "0.2.x", - "coffee-script": "1.4.x", - "compute-cluster": "*", - "connect": "2.7.x", - "find": "0.1.7", - "fs-extra": "0.12.0", - "fstream": "*", - "graceful-fs": "1.1.x", - "handlebars": "2.0.0-alpha.1", - "http-proxy": "1.11.x", - "ignore": "^2.2.15", - "js-yaml": "3.0.2", - "mkdirp": "0.3.x", - "mocha": "1.7.x", - "ncp": "0.4.x", - "node-sass-china": "^3.4.1", - "optimist": "0.3.x", - "postcss": "^5.0.9", - "prompt": "0.2.x", - "qless": "1.5.x", - "request": "2.16.x", - "rimraf": "2.1.4", - "semver": "1.1.x", - "sty": "0.6.x", - "tar": "^2.2.0", - "temp": "0.5.0", - "uglify-js": "1.3.x", - "uglifycss": "0.0.5", - "underscore": "1.4.x", - "underscore.string": "2.3.3", - "urlrouter": "0.2.x", - "velocity.java": "^1.3.0", - "velocityjs": "0.4.x" - }, - "devDependencies": { - "chai": "1.3.x" - }, - "optionalDependencies": {}, - "engines": { - "node": "*" - }, - "license": "MIT", - "scripts": { - "prepublish": "cake build" - } -} \ No newline at end of file + "author": "hao.lin ", + "name": "fekit", + "description": "FE Toolkit", + "version": "0.2.139", + "bin": "./bin/fekit", + "repository": { + "type": "git", + "url": "git://github.com/rinh/fekit.git" + }, + "dependencies": { + "async": "0.2.x", + "autoprefixer": "^6.0.3", + "cjson": "0.2.x", + "coffee-script": "1.4.x", + "compute-cluster": "*", + "connect": "2.7.x", + "find": "0.1.7", + "fs-extra": "0.12.0", + "fstream": "*", + "graceful-fs": "1.1.x", + "handlebars": "2.0.0-alpha.1", + "http-proxy": "1.11.x", + "ignore": "^2.2.15", + "js-yaml": "3.0.2", + "mkdirp": "0.3.x", + "mocha": "1.7.x", + "ncp": "0.4.x", + "node-sass-china": "^3.4.1", + "optimist": "0.3.x", + "postcss": "^5.0.9", + "prompt": "0.2.x", + "qless": "1.5.x", + "request": "2.16.x", + "rimraf": "2.1.4", + "semver": "1.1.x", + "sty": "0.6.x", + "tar": "^2.2.0", + "temp": "0.5.0", + "uglify-js": "1.3.x", + "uglifycss": "0.0.5", + "underscore": "1.4.x", + "underscore.string": "2.3.3", + "urlrouter": "0.2.x", + "velocity.java": "^1.3.0", + "velocityjs": "0.4.x" + }, + "devDependencies": { + "babel-cli": "^6.7.5", + "babel-preset-es2015": "^6.6.0", + "babel-preset-react": "^6.5.0", + "chai": "1.3.x" + }, + "optionalDependencies": {}, + "engines": { + "node": "*" + }, + "license": "MIT", + "scripts": { + "prepublish": "cake build" + } +} diff --git a/src/compiler/plugins/jsx.coffee b/src/compiler/plugins/jsx.coffee new file mode 100644 index 0000000..be775e9 --- /dev/null +++ b/src/compiler/plugins/jsx.coffee @@ -0,0 +1,16 @@ +syspath = require 'path' +babel = require 'babel-core' +es2015 = require('babel-preset-es2015') +react = require('babel-preset-react') + +exports.contentType = "javascript" + +exports.process = (txt, path, module, cb) -> + try + name = syspath.basename path, '.jsx' + + txt = (babel.transform txt, {presets: [es2015, react]}).code + + cb null, txt + catch err + cb err From b1d035f07e5f916df19cd85d225a542ebd92274e Mon Sep 17 00:00:00 2001 From: "hongqi.gan" Date: Tue, 12 Apr 2016 11:05:15 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0babel=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=B8=94=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=E6=89=A9?= =?UTF-8?q?=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/compiler/module/module.js | 2 ++ lib/compiler/plugins/es.js | 56 +++++++++++++++++++++++++++++++ lib/compiler/plugins/jsx.js | 24 +------------ src/compiler/module/module.coffee | 3 ++ src/compiler/plugins/es.coffee | 38 +++++++++++++++++++++ src/compiler/plugins/jsx.coffee | 17 +--------- 6 files changed, 101 insertions(+), 39 deletions(-) create mode 100644 lib/compiler/plugins/es.js create mode 100644 src/compiler/plugins/es.coffee diff --git a/lib/compiler/module/module.js b/lib/compiler/module/module.js index 923a531..b47c8bd 100644 --- a/lib/compiler/module/module.js +++ b/lib/compiler/module/module.js @@ -179,6 +179,8 @@ case MODULE_CONTENT_TYPE.CSS: m = new CSSModule(uri); } + console.log('module jump---- ' + uri); + console.log(m); if (rootModule) { m.root_module = rootModule; } diff --git a/lib/compiler/plugins/es.js b/lib/compiler/plugins/es.js new file mode 100644 index 0000000..12066b2 --- /dev/null +++ b/lib/compiler/plugins/es.js @@ -0,0 +1,56 @@ +// Generated by CoffeeScript 1.4.0 +(function() { + var Package, babel, es2015, getBabelConfig, react, syspath, utils; + + utils = require('../../util'); + + Package = require('../../package'); + + syspath = require('path'); + + babel = require('babel-core'); + + es2015 = require('babel-preset-es2015'); + + react = require('babel-preset-react'); + + getBabelConfig = function(configPath) { + var config; + if (!utils.path.exists(configPath)) { + return null; + } + config = utils.file.io.readJSON(configPath); + return config; + }; + + exports.contentType = "javascript"; + + exports.process = function(txt, path, module, cb) { + var babelConfig, babel_config_path, basepath, cwd, name; + try { + console.log('here ....'); + name = syspath.basename(path, '.es'); + cwd = process.cwd(); + basepath = utils.path.closest(cwd, Package.FEKIT_MODULE_DIR, true); + if (!basepath) { + basepath = utils.path.closest(cwd, 'fekit.config'); + } + if (!basepath) { + basepath = cwd; + } + babel_config_path = utils.path.join(basepath, '.babelrc'); + babelConfig = getBabelConfig(babel_config_path); + if (!babelConfig) { + babelConfig = { + presets: [es2015, react] + }; + } + console.log(babelConfig); + txt = (babel.transform(txt, babelConfig)).code; + return cb(null, txt); + } catch (err) { + return cb(err); + } + }; + +}).call(this); diff --git a/lib/compiler/plugins/jsx.js b/lib/compiler/plugins/jsx.js index 7fcbe41..e3b9e2e 100644 --- a/lib/compiler/plugins/jsx.js +++ b/lib/compiler/plugins/jsx.js @@ -1,28 +1,6 @@ // Generated by CoffeeScript 1.4.0 (function() { - var babel, es2015, react, syspath; - syspath = require('path'); - - babel = require('babel-core'); - - es2015 = require('babel-preset-es2015'); - - react = require('babel-preset-react'); - - exports.contentType = "javascript"; - - exports.process = function(txt, path, module, cb) { - var name; - try { - name = syspath.basename(path, '.jsx'); - txt = (babel.transform(txt, { - presets: [es2015, react] - })).code; - return cb(null, txt); - } catch (err) { - return cb(err); - } - }; + module.exports = require('./es'); }).call(this); diff --git a/src/compiler/module/module.coffee b/src/compiler/module/module.coffee index bcae5c6..5e5c2b1 100644 --- a/src/compiler/module/module.coffee +++ b/src/compiler/module/module.coffee @@ -148,6 +148,9 @@ Module.parse = ( path , options , parentModule , rootModule ) -> when MODULE_CONTENT_TYPE.CSS m = new CSSModule( uri ) + console.log('module jump---- ' + uri) + console.log(m) + m.root_module = rootModule if rootModule m.parent = parentModule m.options = options diff --git a/src/compiler/plugins/es.coffee b/src/compiler/plugins/es.coffee new file mode 100644 index 0000000..c3df39b --- /dev/null +++ b/src/compiler/plugins/es.coffee @@ -0,0 +1,38 @@ +utils = require '../../util' +Package = require '../../package' +syspath = require 'path' +babel = require 'babel-core' +es2015 = require('babel-preset-es2015') +react = require('babel-preset-react') + +getBabelConfig = ( configPath ) -> + return null unless utils.path.exists configPath + config = utils.file.io.readJSON configPath + return config + +exports.contentType = "javascript" + +exports.process = (txt, path, module, cb) -> + try + console.log('here ....'); + name = syspath.basename path, '.es' + + cwd = process.cwd() + # 先寻找最近的fekit_modules目录 + basepath = utils.path.closest cwd , Package.FEKIT_MODULE_DIR , true + # 如果没有,再寻找最近的fekit.config + basepath = utils.path.closest cwd , 'fekit.config' unless basepath + # 再没有,则使用当前目录 + basepath = cwd unless basepath + + babel_config_path = utils.path.join( basepath , '.babelrc' ) + + babelConfig = getBabelConfig babel_config_path + + babelConfig = {presets: [es2015, react]} unless babelConfig + console.log(babelConfig); + txt = (babel.transform txt, babelConfig).code + + cb null, txt + catch err + cb err \ No newline at end of file diff --git a/src/compiler/plugins/jsx.coffee b/src/compiler/plugins/jsx.coffee index be775e9..55e6ed5 100644 --- a/src/compiler/plugins/jsx.coffee +++ b/src/compiler/plugins/jsx.coffee @@ -1,16 +1 @@ -syspath = require 'path' -babel = require 'babel-core' -es2015 = require('babel-preset-es2015') -react = require('babel-preset-react') - -exports.contentType = "javascript" - -exports.process = (txt, path, module, cb) -> - try - name = syspath.basename path, '.jsx' - - txt = (babel.transform txt, {presets: [es2015, react]}).code - - cb null, txt - catch err - cb err +module.exports = require './es' \ No newline at end of file From 6ada6eef78eb942f4e81132c33a447343b525260 Mon Sep 17 00:00:00 2001 From: "hongqi.gan" Date: Tue, 12 Apr 2016 11:06:43 +0800 Subject: [PATCH 3/7] =?UTF-8?q?delete=20=E5=88=A0=E9=99=A4console.log?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/compiler/plugins/es.js | 2 -- src/compiler/plugins/es.coffee | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/compiler/plugins/es.js b/lib/compiler/plugins/es.js index 12066b2..a009d7b 100644 --- a/lib/compiler/plugins/es.js +++ b/lib/compiler/plugins/es.js @@ -28,7 +28,6 @@ exports.process = function(txt, path, module, cb) { var babelConfig, babel_config_path, basepath, cwd, name; try { - console.log('here ....'); name = syspath.basename(path, '.es'); cwd = process.cwd(); basepath = utils.path.closest(cwd, Package.FEKIT_MODULE_DIR, true); @@ -45,7 +44,6 @@ presets: [es2015, react] }; } - console.log(babelConfig); txt = (babel.transform(txt, babelConfig)).code; return cb(null, txt); } catch (err) { diff --git a/src/compiler/plugins/es.coffee b/src/compiler/plugins/es.coffee index c3df39b..c679844 100644 --- a/src/compiler/plugins/es.coffee +++ b/src/compiler/plugins/es.coffee @@ -14,7 +14,6 @@ exports.contentType = "javascript" exports.process = (txt, path, module, cb) -> try - console.log('here ....'); name = syspath.basename path, '.es' cwd = process.cwd() @@ -30,7 +29,7 @@ exports.process = (txt, path, module, cb) -> babelConfig = getBabelConfig babel_config_path babelConfig = {presets: [es2015, react]} unless babelConfig - console.log(babelConfig); + txt = (babel.transform txt, babelConfig).code cb null, txt From 6b2f19989cc2384fc1324c2a74b108d496047a51 Mon Sep 17 00:00:00 2001 From: "hongqi.gan" Date: Tue, 12 Apr 2016 11:25:22 +0800 Subject: [PATCH 4/7] =?UTF-8?q?remove=20=E5=88=A0=E9=99=A4=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/compiler/module/module.js | 2 -- src/compiler/module/module.coffee | 3 --- 2 files changed, 5 deletions(-) diff --git a/lib/compiler/module/module.js b/lib/compiler/module/module.js index b47c8bd..923a531 100644 --- a/lib/compiler/module/module.js +++ b/lib/compiler/module/module.js @@ -179,8 +179,6 @@ case MODULE_CONTENT_TYPE.CSS: m = new CSSModule(uri); } - console.log('module jump---- ' + uri); - console.log(m); if (rootModule) { m.root_module = rootModule; } diff --git a/src/compiler/module/module.coffee b/src/compiler/module/module.coffee index 5e5c2b1..bcae5c6 100644 --- a/src/compiler/module/module.coffee +++ b/src/compiler/module/module.coffee @@ -148,9 +148,6 @@ Module.parse = ( path , options , parentModule , rootModule ) -> when MODULE_CONTENT_TYPE.CSS m = new CSSModule( uri ) - console.log('module jump---- ' + uri) - console.log(m) - m.root_module = rootModule if rootModule m.parent = parentModule m.options = options From d90b69387250f8af59201d86b9ca186470783bfc Mon Sep 17 00:00:00 2001 From: "hongqi.gan" Date: Wed, 13 Apr 2016 11:00:39 +0800 Subject: [PATCH 5/7] =?UTF-8?q?mod=20=E6=9B=B4=E6=94=B9babel=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3e172d3..e379a39 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,9 @@ "dependencies": { "async": "0.2.x", "autoprefixer": "^6.0.3", + "babel-cli": "^6.7.5", + "babel-preset-es2015": "^6.6.0", + "babel-preset-react": "^6.5.0", "cjson": "0.2.x", "coffee-script": "1.4.x", "compute-cluster": "*", @@ -46,9 +49,6 @@ "velocityjs": "0.4.x" }, "devDependencies": { - "babel-cli": "^6.7.5", - "babel-preset-es2015": "^6.6.0", - "babel-preset-react": "^6.5.0", "chai": "1.3.x" }, "optionalDependencies": {}, From 2ad0d34db25258205f2798bc043c5d980671459b Mon Sep 17 00:00:00 2001 From: honchy <805548138@qq.com> Date: Fri, 15 Apr 2016 11:45:00 +0800 Subject: [PATCH 6/7] reformat and move babel dep position to dev --- package.json | 120 +++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/package.json b/package.json index e379a39..60ce19d 100644 --- a/package.json +++ b/package.json @@ -1,62 +1,62 @@ { - "author": "hao.lin ", - "name": "fekit", - "description": "FE Toolkit", - "version": "0.2.139", - "bin": "./bin/fekit", - "repository": { - "type": "git", - "url": "git://github.com/rinh/fekit.git" - }, - "dependencies": { - "async": "0.2.x", - "autoprefixer": "^6.0.3", - "babel-cli": "^6.7.5", - "babel-preset-es2015": "^6.6.0", - "babel-preset-react": "^6.5.0", - "cjson": "0.2.x", - "coffee-script": "1.4.x", - "compute-cluster": "*", - "connect": "2.7.x", - "find": "0.1.7", - "fs-extra": "0.12.0", - "fstream": "*", - "graceful-fs": "1.1.x", - "handlebars": "2.0.0-alpha.1", - "http-proxy": "1.11.x", - "ignore": "^2.2.15", - "js-yaml": "3.0.2", - "mkdirp": "0.3.x", - "mocha": "1.7.x", - "ncp": "0.4.x", - "node-sass-china": "^3.4.1", - "optimist": "0.3.x", - "postcss": "^5.0.9", - "prompt": "0.2.x", - "qless": "1.5.x", - "request": "2.16.x", - "rimraf": "2.1.4", - "semver": "1.1.x", - "sty": "0.6.x", - "tar": "^2.2.0", - "temp": "0.5.0", - "uglify-js": "1.3.x", - "uglifycss": "0.0.5", - "underscore": "1.4.x", - "underscore.string": "2.3.3", - "urlrouter": "0.2.x", - "velocity.java": "^1.3.0", - "velocityjs": "0.4.x" - }, - "devDependencies": { - "chai": "1.3.x" - }, - "optionalDependencies": {}, - "engines": { - "node": "*" - }, - "license": "MIT", - "scripts": { - "prepublish": "cake build" - } + "author": "hao.lin ", + "name": "fekit", + "description": "FE Toolkit", + "version": "0.2.139", + "bin": "./bin/fekit", + "repository": { + "type": "git", + "url": "git://github.com/rinh/fekit.git" + }, + "dependencies": { + "async": "0.2.x", + "autoprefixer": "^6.0.3", + "cjson": "0.2.x", + "coffee-script": "1.4.x", + "compute-cluster": "*", + "connect": "2.7.x", + "find": "0.1.7", + "fs-extra": "0.12.0", + "fstream": "*", + "graceful-fs": "1.1.x", + "handlebars": "2.0.0-alpha.1", + "http-proxy": "1.11.x", + "ignore": "^2.2.15", + "js-yaml": "3.0.2", + "mkdirp": "0.3.x", + "mocha": "1.7.x", + "ncp": "0.4.x", + "node-sass-china": "^3.4.1", + "optimist": "0.3.x", + "postcss": "^5.0.9", + "prompt": "0.2.x", + "qless": "1.5.x", + "request": "2.16.x", + "rimraf": "2.1.4", + "semver": "1.1.x", + "sty": "0.6.x", + "tar": "^2.2.0", + "temp": "0.5.0", + "uglify-js": "1.3.x", + "uglifycss": "0.0.5", + "underscore": "1.4.x", + "underscore.string": "2.3.3", + "urlrouter": "0.2.x", + "velocity.java": "^1.3.0", + "velocityjs": "0.4.x" + }, + "devDependencies": { + "chai": "1.3.x", + "babel-cli": "^6.7.5", + "babel-preset-es2015": "^6.6.0", + "babel-preset-react": "^6.5.0", + }, + "optionalDependencies": {}, + "engines": { + "node": "*" + }, + "license": "MIT", + "scripts": { + "prepublish": "cake build" + } } From 0e4a7ea939f33bd08a5ed43d6c60d3132c7df3e2 Mon Sep 17 00:00:00 2001 From: honchy <805548138@qq.com> Date: Fri, 15 Apr 2016 11:46:15 +0800 Subject: [PATCH 7/7] remove tail comma --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 60ce19d..e48d955 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "chai": "1.3.x", "babel-cli": "^6.7.5", "babel-preset-es2015": "^6.6.0", - "babel-preset-react": "^6.5.0", + "babel-preset-react": "^6.5.0" }, "optionalDependencies": {}, "engines": {