OSDN Git Service

create directory
[eos/zephyr.git] / gulpfile.js
1 var gulp            = require('gulp'),
2     exec            = require('child_process').exec,
3     uglify          = require('gulp-uglify'),
4     inject          = require('gulp-inject'),
5     jshint          = require('gulp-jshint'),
6     angularFilesort = require('gulp-angular-filesort'),
7     bs              = require('browser-sync').create(),
8     gls             = require('gulp-live-server'),
9     concat          = require('gulp-concat'),
10     _               = require('lodash'),
11     templateCache   = require('gulp-angular-templatecache'),
12     tap             = require('gulp-tap'),
13     runSequence     = require('run-sequence')
14
15 var paths = {
16     index      : ['./client/index.html'],
17     angular    : ['./client/assets/vendor/angular/*.js'],
18     underscore : ['./client/assets/vendor/underscore-min.js'],
19     vendor     : ['./client/assets/vendor/*.js', './client/assets/vendor/*.css'],
20     app        : ['./client/app/*.js'],
21     shared     : ['./client/app/shared/**/*.js'],
22     components : ['./client/app/components/**/*.js', './client/app/components/**/*.css'],
23     templates   : ['./client/app/**/*.html']
24 };
25
26 gulp.task('inject', function() {
27     return gulp.src(paths.index)
28     .pipe(inject(gulp.src(paths.angular).pipe(angularFilesort()), {name: 'angular'}))
29     .pipe(inject(gulp.src(paths.underscore, {read: false}), {name: 'underscore'}))
30     .pipe(inject(gulp.src(paths.vendor, {read: false}), {name: 'vendor'}))
31     .pipe(inject(gulp.src(paths.app, {read:false}), {name: 'app'}))
32     .pipe(inject(gulp.src(paths.shared, {read: false}), {name: 'shared'}))
33     .pipe(inject(gulp.src(paths.components, {read:false}), {name: 'components'}))
34     .pipe(gulp.dest('./client'));
35 });
36
37 gulp.task('browser-sync', ['serve'], function() {
38     bs.init(null, {
39         proxy: {
40             target: "http://127.0.0.1:3000",
41             ws: true
42         },
43         browser: "google chrome",
44         //port: "7000",
45         ghostMode: false,
46     })
47 })
48
49 gulp.task('parse-option', function(cb) {
50     return exec('ruby create-json-file.rb', {cwd: './util/'}, function(err) {
51         if(err) console.error(err);
52         else cb();
53     });
54 });
55
56 gulp.task('serve', function(cb) {
57     var server = gls.new('./server/app.js');
58     server.start();
59     cb();
60 });
61
62 gulp.task('watch', function() {
63     var pathsArray = new Array();
64     Object.keys(paths).forEach(function(key) {
65         pathsArray = pathsArray.concat(paths[key]);
66     });
67
68     gulp.watch(pathsArray, ['bs-reload']);
69 });
70
71 gulp.task('bs-reload', function() {
72     bs.reload();
73 });
74
75 gulp.task('angular-concat', function() {
76     return gulp.src(paths.angular)
77     .pipe(angularFilesort(), {name: 'angular'}) 
78     .pipe(concat('angular.js'))
79     .pipe(gulp.dest('./dist/'))
80 })
81
82 gulp.task('js-vendor-concat', function() {
83     return gulp.src('./client/assets/vendor/*.js')
84     .pipe(concat('vendor.js'))
85     .pipe(gulp.dest('./dist/'))
86 })
87
88 gulp.task('underscore', function() {
89     return gulp.src(paths.underscore)
90     .pipe(concat('underscore.js'))
91     .pipe(gulp.dest('./dist/'))
92 })
93
94 gulp.task('js-app', function() {
95     return gulp.src(paths.app)
96     .pipe(gulp.dest('./dist/'))
97 })
98
99 gulp.task('js-source-concat', function() {
100     return gulp.src(_.union(paths.shared, paths.components))
101     .pipe(tap(function(file) {
102         file.contents = Buffer.concat([
103             new Buffer("(function(){\n"),
104             file.contents,
105             new Buffer("}());")
106         ])
107     }))
108     .pipe(concat('source.js'))
109     .pipe(gulp.dest('./dist/'))
110 })
111
112 gulp.task('css-concat', function() {
113     return gulp.src(paths.vendor[1])
114     .pipe(concat('style.css'))
115     .pipe(gulp.dest('./dist/'))
116 })
117
118 gulp.task('cache', function() {
119     gulp.src(paths.templates)
120     .pipe(templateCache('templates.js', {module: 'zephyrApp', root: '/client/app/'}))
121     .pipe(gulp.dest('dist/'))
122 })
123
124 gulp.task('set-production', function() {
125     process.env.NODE_ENV = 'production'
126 })
127
128 gulp.task('dbdrop', function() {
129     process.env.DB_ZEPHYR = 'drop'
130 })
131
132 gulp.task('build', ['angular-concat', 'js-vendor-concat', 'underscore', 'js-app', 'js-source-concat', 'css-concat', 'cache'], function() {
133 })
134
135 gulp.task('default', function(callback) {
136     runSequence('inject', 'serve', 'browser-sync', 'watch', callback)
137     //['inject', 'browser-sync', 'watch']); 
138 })
139 gulp.task('deploy', function(callback) {
140     runSequence('build', 'set-production', 'serve', callback)
141 })
142
143 gulp.task('test', function(callback) {
144     runSequence('dbdrop', 'default', callback)
145 })
146