-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
202 lines (171 loc) · 5.44 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
var plugin = 'socket',
source_SCSS = { admin: './scss/**/*.scss', public: './scss/**/*.scss'},
dest_CSS = { admin:'./css/', public: './css/'},
gulp = require('gulp'),
sass = require('gulp-sass'),
prefix = require('gulp-autoprefixer'),
exec = require('gulp-exec'),
replace = require('gulp-replace'),
minify = require('gulp-minify-css'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
beautify = require('gulp-beautify'),
csscomb = require('gulp-csscomb'),
cmq = require('gulp-combine-media-queries'),
chmod = require('gulp-chmod'),
fs = require('fs'),
rtlcss = require('rtlcss'),
postcss = require('gulp-postcss'),
del = require('del'),
rename = require('gulp-rename');
require('es6-promise').polyfill();
var options = {
silent: true,
continueOnError: true // default: false
};
// styles related
gulp.task('styles-admin', function () {
return gulp.src(source_SCSS.admin)
.pipe(sass({'sourcemap': false, style: 'compact'}))
.on('error', function (e) {
console.log(e.message);
})
.pipe(prefix("last 1 version", "> 1%", "ie 8", "ie 7"))
.pipe(gulp.dest(dest_CSS.admin));
});
gulp.task('styles-public', function () {
return gulp.src(source_SCSS.public)
.pipe(sass({'sourcemap': false, style: 'compact'}))
.on('error', function (e) {
console.log(e.message);
})
.pipe(prefix("last 1 version", "> 1%", "ie 8", "ie 7"))
.pipe(gulp.dest(dest_CSS.public));
});
gulp.task('styles', ['styles-admin', 'styles-public'], function () {
// ok
});
gulp.task('watch-styles', function () {
return gulp.watch(source_SCSS.admin, ['styles-admin']);
});
gulp.task('watch-public', function () {
return gulp.watch(source_SCSS.public, ['styles-public']);
});
/**
* Create a zip archive out of the cleaned folder and delete the folder
*/
gulp.task( 'zip', ['build'], function() {
return gulp.src( './' )
.pipe( exec( 'cd ./../; rm -rf socket.zip; cd ./build/; zip -r -X ./../socket.zip ./socket; cd ./../; rm -rf build' ) );
} );
/**
* Copy theme folder outside in a build folder, recreate styles before that
*/
gulp.task( 'copy-folder', function() {
return gulp.src( './' )
.pipe( exec( 'rm -Rf ./../build; mkdir -p ./../build/socket; cp -Rf ./* ./../build/socket/' ) );
} );
/**
* Clean the folder of unneeded files and folders
*/
gulp.task( 'build', ['copy-folder'], function() {
// files that should not be present in build zip
files_to_remove = [
'**/codekit-config.json',
'node_modules',
'tests',
'.travis.yml',
'circle.yml',
'phpunit.xml.dist',
'.sass-cache',
'config.rb',
'gulpfile.js',
'package.json',
'pxg.json',
'build',
'.idea',
'**/*.css.map',
'**/.git*',
'*.sublime-project',
'.DS_Store',
'**/.DS_Store',
'__MACOSX',
'**/__MACOSX',
'+development.rb',
'+production.rb',
'README.md'
];
files_to_remove.forEach( function( e, k ) {
files_to_remove[k] = '../build/socket/' + e;
} );
del.sync(files_to_remove, {force: true});
} );
// usually there is a default task for lazy people who just wanna type gulp
gulp.task('default', ['styles'], function () {
// silence
});
gulp.task('susy', function() {
return gulp.src('scss/*.scss')
.pipe(sass({
// outputStyle: 'compressed',
includePaths: ['node_modules/susy/sass']
}).on('error', sass.logError))
.pipe(gulp.dest('css'));
});
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var react = require('react');
var reactdom = require('react-dom');
var babel = require('babelify');
function compile_admin(watch) {
var bundler = watchify(browserify('./src/socket.js', { debug: true }).transform(babel, { presets: ["es2015", "stage-0", "react"]}));
function rebundle_admin() {
bundler.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); })
.pipe(source('socket.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./js'));
}
if (watch) {
bundler.on('update', function() {
console.log('-> bundling admin dashboard...' + new Date().getTime() / 1000);
rebundle_admin();
});
}
rebundle_admin();
}
function watch_admin() {
return compile_admin(true);
};
gulp.task('react', function() { return compile(); });
gulp.task('compile', function() { return compile_admin(false); });
gulp.task('watch', ['watch-styles'], function() { return watch_admin(true); });
gulp.task('default', ['watch-all']);
/**
* Short commands help
*/
gulp.task('help', function () {
var $help = '\nCommands available : \n \n' +
'=== General Commands === \n' +
'start (default)Compiles all styles and scripts and makes the theme ready to start \n' +
'zip Generate the zip archive \n' +
'build Generate the build directory with the cleaned theme \n' +
'help Print all commands \n' +
'=== Style === \n' +
'styles Compiles styles in production mode\n' +
'styles-dev Compiles styles in development mode \n' +
'styles-admin Compiles admin styles \n' +
'=== Scripts === \n' +
'scripts Concatenate all js scripts \n' +
'scripts-dev Concatenate all js scripts \n' +
'=== Watchers === \n' +
'watch Watches all js and scss files \n' +
'styles-watch Watch only styles\n' +
'scripts-watch Watch scripts only \n';
console.log($help);
});