├── .gitignore ├── .npmignore ├── README.md ├── package.json ├── index.js └── LICENSE.md /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | node_modules/ 3 | 4 | .DS_Store 5 | *.db 6 | *.bak 7 | *.tmp 8 | *.cmd 9 | ~* 10 | 11 | upload.py -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /.settings 3 | /.project 4 | /.gitignore 5 | /node_modules 6 | /test 7 | /.tmp 8 | 9 | .DS_Store 10 | 11 | *.db 12 | *.bak 13 | *.tmp 14 | *.cmd 15 | ~* 16 | 17 | upload.py -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fis-postprocessor-jswrapper 2 | 3 | A postprocessor plugin for fis to wrap javascript with closure or amd define. 4 | 5 | 6 | 7 | ## settings 8 | 9 | $ vi path/to/project/fis-conf.js 10 | 11 | ```javascript 12 | fis.config.merge({ 13 | settings : { 14 | postprocessor : { 15 | jswrapper : { 16 | //wrap type. if omitted, it will wrap js file with '(function(){...})();'. 17 | type : 'amd', 18 | //wrap all js file, default is false, wrap modular js file only. 19 | wrapAll : true 20 | } 21 | } 22 | } 23 | }); 24 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "fis-postprocessor-jswrapper", 3 | "description" : "A postprocessor plugin for fis to wrap javascript with closure or amd define.", 4 | "version" : "0.0.5", 5 | "author" : "FIS Team ", 6 | "homepage" : "http://fis.baidu.com/", 7 | "keywords": [ "fis" ], 8 | "main" : "index.js", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/fis-dev/fis-postprocessor-jswrapper.git" 12 | }, 13 | "engines" : { 14 | "node" : ">= 0.8.0" 15 | }, 16 | "scripts" : { 17 | "test" : "mocha test/ut --recursive" 18 | } 19 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * fis 3 | * http://fis.baidu.com/ 4 | */ 5 | 6 | 'use strict'; 7 | module.exports = function(content, file, conf){ 8 | if(file.isMod || conf.wrapAll){ 9 | //wrap 10 | if(conf.type === 'amd'){ 11 | if(!/^\s*define\s*\(/.test(content)){ 12 | content = 'define(\'' + file.getId() + '\', function(require, exports, module){\n\n' + content + '\n\n});'; 13 | } 14 | } else { 15 | if(!/^\s*(?:[!(]\s*|void\s+)function\(/.test(content)){ 16 | content = '!function(){\n\n' + content + '\n\n}();'; 17 | } 18 | } 19 | } 20 | return content; 21 | }; -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013 baidu.com 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 14 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 15 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 18 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. --------------------------------------------------------------------------------