Gulp-shark-automation is a tool for automation of front-end.It supplies two functions:
- make a mock server during development phase
- build the source code and static resource during the deploy phase
Gulp-shark-automation needs a config file:
moduleexports = comment: '' //not required version: '1.0.0' //not required product: 'shark-automation' //name of product. not required contextPath: '/' //rootpath of request.default '/' protocol: 'http' //the protocol of product. default 'http' port: 9100 //port of mock server. required hostname: 'demo.shark.automation' //hostname of mock server. required openurl: 'http://demo.shark.automation:9000/index.html' //url is opend automatically when the mock server is ready. not required rootPath: __dirname //rootpath of product.required webapp: 'src/main/webapp' //path of source code.required mock: 'src/test/mock' //path of mock files.required scssPath: 'style/scss' //path of scss files. required cssPath: 'style/css' //path of css files. required imgPath: 'style/img' //path of images. required videoPath: 'style/video' //path of video. not required jsPath: 'js' //path of js. required fontPath: 'fonts' //path of fonts. not required htmlPath: 'views' //path of html. required templatePath: 'WEB-INF/tmpl' //path of ftl. not required ajaxPrefix: '/xhr' //rootpath of ajax request. required. mimgPathPrefix: '/hxm' //rootpath of static file requrest. not required. ifwebpack: true //should use webpack to build js. not required //required mimgURLPrefix: develop: '' //the rootpath of static resource during develop phase online: '' //the rootpath of static resource at online phase test: '' //the rootpath of static resource at test phase //need to deploy then required deploy: path: '' //the folder path which contains the files need to be pushed to the repository static: '' ////the folder path which contains the static files need to be pushed to the repository giturl: '' //git repository url.not required git: test: 'test' //test repository online: 'deploy' //online repository ;
mock-server
Gulp-shark-automation use express to make a mock server and need some mock files.Express uses the mock file related to the request path as response.For instance:request path: /xhr/demo/list.do, the related mock file is {config.mock}/xhr/demo/list.do
below shows how to start the mock server.
var gulpSharkAutomation = express = openurl = ;var config = ; //config filegulp;
build-task
Gulp-shark-automation helps you to build source code and deal the static resource such as compress、md5.You can assemble the tasks gulp-shark-automation registed to do the build.Below is the list of tasks gulp-shark-automation registed and the npm tool it depend on:
- clean:Clean the build folder depned on gulp-clean
- sass-preprocess:Compass sass to css depend on gulp-sass.
- webpack-server:use webpack to build js. Depend on webpack、webpack-stream
- useref:merge static resource the html and ftl linked depend on gulp-useref
- imagemin: min the image depend on gulp-imagemin、imagemin-pngquant
- revision-image: reversion the image use md5 depend on gulp-rev
- revreplace-css、revreplace-js: replace the image link url after reversion-image depend on gulp-rev-replace
- revision-css、revision-js:reversion the css or js depend on gulp-rev
- revreplace-html、revreplace-ftl: repalce the static resource include js、css、image link url depend on gulp-rev-replace
- copy-build: copy the builded files to the dest of build
- zip: compress files to zip depend on gulp-zip、md5
- deploy: depoly the build files to the git repository depend on shark-deploy-git
Demo:
var argv = argv gulpSharkAutomation = ;var config = ; //config filegulpSharkAutomation;gulp;
The npm package which the tasks gulp-shark-automation registed depend on is config with default options.If you want to override the default option, you can do this way:
var config = ; //config filegulpSharkAutomation;