forked from django-cms/django-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
240 lines (219 loc) · 7.03 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// #####################################################################################################################
// #IMPORTS#
var gulp = require('gulp');
var gutil = require('gulp-util');
var plumber = require('gulp-plumber');
var fs = require('fs');
var autoprefixer = require('autoprefixer');
var postcss = require('gulp-postcss');
var gulpif = require('gulp-if');
var iconfont = require('gulp-iconfont');
var iconfontCss = require('gulp-iconfont-css');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var minifyCss = require('gulp-clean-css');
var eslint = require('gulp-eslint');
var webpack = require('webpack');
var KarmaServer = require('karma').Server;
var integrationTests = require('djangocms-casper-helpers/gulp');
var argv = require('minimist')(process.argv.slice(2)); // eslint-disable-line
// #####################################################################################################################
// #SETTINGS#
var options = {
debug: argv.debug
};
var PROJECT_ROOT = __dirname + '/cms/static/cms';
var PROJECT_PATH = {
js: PROJECT_ROOT + '/js',
sass: PROJECT_ROOT + '/sass',
css: PROJECT_ROOT + '/css',
icons: PROJECT_ROOT + '/fonts',
tests: __dirname + '/cms/tests/frontend'
};
var PROJECT_PATTERNS = {
js: [
PROJECT_PATH.js + '/modules/*.js',
PROJECT_PATH.js + '/widgets/*.js',
PROJECT_PATH.js + '/*.js',
PROJECT_PATH.js + '/gulpfile.js',
PROJECT_PATH.tests + '/**/*.js',
'!' + PROJECT_PATH.tests + '/unit/helpers/**/*.js',
'!' + PROJECT_PATH.tests + '/coverage/**/*.js',
'!' + PROJECT_PATH.js + '/modules/jquery.*.js',
'!' + PROJECT_PATH.js + '/dist/*.js'
],
sass: [PROJECT_PATH.sass + '/**/*.{scss,sass}'],
icons: [PROJECT_PATH.icons + '/src/*.svg']
};
var INTEGRATION_TESTS = [
[
'loginAdmin',
'toolbar',
'addFirstPage',
'wizard',
'editMode',
'sideframe',
'createContent',
'users',
'addNewUser',
'newPage',
'pageControl',
'modal',
'permissions',
'logout',
'clipboard',
'link-plugin-content-mode',
'add-multiple-plugins',
'plugin-dynamic-script-loading'
],
[
'pageTypes',
'switchLanguage',
'editContent',
'editContentTools',
'publish',
'loginToolbar',
'changeSettings',
'toolbar-login-apphooks',
'permissions-enabled',
{
serverArgs: '--CMS_PERMISSION=False --CMS_TOOLBAR_URL__EDIT_ON=test-edit',
file: 'copy-from-language'
},
{
serverArgs: '--CMS_PERMISSION=False --CMS_TOOLBAR_URL__EDIT_ON=test-edit',
file: 'pagetree-no-permission'
},
{
serverArgs: '--CMS_PERMISSION=False --CMS_TOOLBAR_URL__EDIT_ON=test-edit',
file: 'permissions-disabled'
}
],
[
'pagetree',
'pagetree-drag-n-drop-copy',
'disableToolbar',
'dragndrop',
'copy-apphook-page',
// 'revertLive', // disabled
'narrowScreen',
'nonadmin'
]
];
var CMS_VERSION = fs.readFileSync('cms/__init__.py', { encoding: 'utf-8' }).match(/__version__ = '(.*?)'/)[1];
// #####################################################################################################################
// #TASKS#
gulp.task('sass', function() {
gulp
.src(PROJECT_PATTERNS.sass)
.pipe(gulpif(options.debug, sourcemaps.init()))
.pipe(sass())
.on('error', function(error) {
gutil.log(gutil.colors.red('Error (' + error.plugin + '): ' + error.messageFormatted));
})
.pipe(
postcss([
autoprefixer({
cascade: false
})
])
)
.pipe(
minifyCss({
rebase: false
})
)
.pipe(gulpif(options.debug, sourcemaps.write()))
.pipe(gulp.dest(PROJECT_PATH.css + '/' + CMS_VERSION + '/'));
});
gulp.task('icons', function() {
gulp
.src(PROJECT_PATTERNS.icons)
.pipe(
iconfontCss({
fontName: 'django-cms-iconfont',
path: PROJECT_PATH.sass + '/libs/_iconfont.scss',
targetPath: '../../sass/components/_iconography.scss',
fontPath: '../../fonts/' + CMS_VERSION + '/'
})
)
.pipe(
iconfont({
fontName: 'django-cms-iconfont',
normalize: true,
formats: ['svg', 'ttf', 'eot', 'woff', 'woff2']
})
)
.on('glyphs', function(glyphs, opts) {
gutil.log.bind(glyphs, opts);
})
.pipe(gulp.dest(PROJECT_PATH.icons + '/' + CMS_VERSION + '/'));
});
gulp.task('lint', ['lint:javascript']);
gulp.task('lint:javascript', function() {
// DOCS: http://eslint.org
return gulp
.src(PROJECT_PATTERNS.js)
.pipe(gulpif(!process.env.CI, plumber()))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.pipe(gulpif(!process.env.CI, plumber.stop()));
});
gulp.task('tests', ['tests:unit', 'tests:integration']);
// gulp tests:unit --tests=cms.base,cms.modal
gulp.task('tests:unit', function(done) {
var server = new KarmaServer(
{
configFile: PROJECT_PATH.tests + '/karma.conf.js',
singleRun: true
},
done
);
server.start();
});
gulp.task('tests:unit:watch', function() {
var server = new KarmaServer({
configFile: PROJECT_PATH.tests + '/karma.conf.js'
});
server.start();
});
// gulp tests:integration [--clean] [--screenshots] [--tests=loginAdmin,toolbar]
gulp.task(
'tests:integration',
integrationTests({
tests: INTEGRATION_TESTS,
pathToTests: PROJECT_PATH.tests,
argv: argv,
dbPath: 'testdb.sqlite',
serverCommand: 'testserver.py',
logger: gutil.log.bind(gutil),
waitForMigrations: 5 // seconds
})
);
var webpackBundle = function(opts) {
var webpackOptions = opts || {};
webpackOptions.PROJECT_PATH = PROJECT_PATH;
webpackOptions.debug = options.debug;
webpackOptions.CMS_VERSION = CMS_VERSION;
return function(done) {
var config = require('./webpack.config')(webpackOptions);
webpack(config, function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log('[webpack]', stats.toString({ maxModules: Infinity, colors: true, optimizationBailout: true }));
if (typeof done !== 'undefined' && (!opts || !opts.watch)) {
done();
}
});
};
};
gulp.task('bundle:watch', webpackBundle({ watch: true }));
gulp.task('bundle', webpackBundle());
gulp.task('watch', function() {
gulp.start('bundle:watch');
gulp.watch(PROJECT_PATTERNS.sass, ['sass']);
gulp.watch(PROJECT_PATTERNS.js, ['lint']);
});
gulp.task('default', ['sass', 'lint', 'watch']);