gulp-jspool
a easy way to pack javascript components. ,only build for archive/litte project,do not apply to build in specific big projects,and don't export extra code(cmd config code in webpack/browserify)
Installation
npm install gulp-jspool
Features
- use config.json to pack
- control flow with ? ?
- @include
- copy/paste
- filters
- use filesystem to pack multiple environment
- use scope name to divide data environment
- Loop and conditional expressions
why use gulp-jspool
- we want to store our jscode,just like Carousel,data handle,UI interactions and so on,all of these codes need different running environment and develop environment.
- some animation js maybe have long running cycle,we need split them and write/test each cycle
- some jscomponent is composed by some other jscomponent,we need to have a mechanism to compose them in project.
a example about the ./example folder which export example.js
gulpfile.js
var gulp = ;var rename=uglify=;var jspool = ;gulp;
index.js
'@include(js/utils.js)' '@paste(tool)'//By jspool writing directories var { }; var prototypeExp=' extend(prototypeExp,extendFilter); Exp.prototype=prototypeExp; $("?button?").on("click",function(){ //.. }); var canvas=0; var c2d=canvas; //some c2d handle code for shape in ?shapes?}} if ?shapetype? == circle}} c2d
config.js
"export": "example.js" "paste": "tool": "../tool" "data": "data.json" "filter": "filter.js" "name":"example"
data.json
"button":"#btn""elements":"width":200"height":100...
dir tool is same to dir example
instructions for use and api
filesystem
- index.js //root js of project
- config.json //config file of project,must have json format.can be empty like {}. normal content is {"export":"example.js","paste":{"tool":"../tool"},"data":"data.json","filter":"filter.js","root":"index.js","name":"example"}
//config.json If no data attr,default value is data.json.If no filter ,default value is filter.js.If no export attr,default value is _test_export.js(This file is generated by the jspool,not by gulp.dest..).paste attr use for copy other same jspool directory.If no root attr,default value is index.js.If no name attr,the name of gulp.dest export file will be the name of dir.If use name attr,the name of gulp.dest export file will be the this name
- data.json //store data match variable
- filter.js //use node require to module.exports filters ob
multiple environment test/development/online in project ../example
- config.json
"export": "example.js" "root": "index.js""name":"example"
- dev-config.json
"export": "dev-example.js" "root": "dev-index.js""name":"dev-example"
- test-config.json
"export": "test-example.js" "root": "test-index.js""name":"test-example"
can use npm install jdirectory via jdirectory to create dirs and files,use like ...project1>jdir jspool
@include
'@include(js/event.js)'//if want diff data environment for other jsscope canvas as ?size|handRecthandColor?}} '@include(js/canvas.js)'/scope
@paste
some base utils js don't write in current dir,it exists in other directory;
- dir./tool
copy array var {...}; var {...}; /copy copy string var {} var {} /copy
- dir ./example
config.json {"paste":{"tool":"../tool"}}
some js file can have
'@paste(tool.array)' ......'@paste(tool)'
variable
//if can't match width,use 200 instead,?width:200|toPx?//can use much variable and filter?width:200height:100left:20top:20|toPxtoScale? //use for express//also can use {{for da in [1,2,3]}}or {{for....{"a":123,..}}}//if ?data? is object type,,da will just like {attr:"a",value:123}for da in ?data?}}//object type?daattr??davalue?/forfor da in ?data?}}//array type?da?/for//use complex loopvar temp=null;for ele in ?elements?}} temp=obele?elename|upperA?=
filter
//in your filter.js file//built-in filter is upper (upperCase string),lower (lowerCase string),length (length of array)moduleexports={//variableValue is the value of ?..?,//if use multi variable ?wd,hg,lf?,varibleValue will be a array to include all,//if use for loop,item will be the no of loop item,length is the length of loop length;};//tips:if you use filter to handle variableValue of type object in ??,//after you change this object attr,value, the change will exists in other situation;//for example: ?ob1|filter1? the value of ob1 is {x:1,y:1},and filter1 is function(variableValue){variableValue.z=3;return variableValue;} //then you use ?ob1? after the previous operation,the value of ob1 will be {x:1,y:1,z:3}.//so in filter1 ,use function(variableValue){//var ob=copy(variableValue);//copy is your copy object function; //ob.z=3;return ob;} //is better which you don't want to change the original data;
api
gulp;
process
fix
- 11-9 fix filter read bug.
- 11-10 fix buffer to use uglify.
- 11-23 can export just like a/b/c/d/exp.js