forked from django-cms/djangocms-text-ckeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
179 lines (153 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
'use strict';
const gulp = require('gulp');
const gulpif = require('gulp-if');
const sourcemaps = require('gulp-sourcemaps');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const eslint = require('gulp-eslint');
const plumber = require('gulp-plumber');
const replace = require('gulp-replace');
const revReplace = require('gulp-rev-replace');
const rev = require('gulp-rev');
const runSequence = require('run-sequence');
const filter = require('gulp-filter');
const del = require('del');
const integrationTests = require('djangocms-casper-helpers/gulp');
const path = require('path');
const child_process = require('child_process');
const execSync = child_process.execSync;
const browserSync = require('browser-sync').create();
const argv = require('minimist')(process.argv.slice(2));
const options = {
debug: argv.debug
};
const PROJECT_ROOT = __dirname + '/djangocms_text_ckeditor/static/djangocms_text_ckeditor';
const PROJECT_PATH = {
js: PROJECT_ROOT + '/js',
tests: __dirname + '/djangocms_text_ckeditor/tests/frontend'
};
const PROJECT_PATTERNS = {
js: [
PROJECT_PATH.js + '/**/*.js',
PROJECT_PATH.js + '/../ckeditor_plugins/**/*.js',
'!' + PROJECT_PATH.js + '/pre.js',
'!' + PROJECT_PATH.js + '/post.js',
'!' + PROJECT_PATH.js + '/../ckeditor_plugins/cmsresize/*.js',
'!' + PROJECT_PATH.js + '/../ckeditor_plugins/cmsdialog/*.js',
'!' + PROJECT_PATH.js + '/../ckeditor/**/*.js',
'!' + PROJECT_PATH.js + '/dist/*.js'
]
};
/*
* Object keys are filenames of bundles that will be compiled
* from array of paths that are the value.
*/
const JS_BUNDLE = [
PROJECT_PATH.js + '/pre.js',
PROJECT_PATH.js + '/cms.ckeditor.js',
PROJECT_PATH.js + '/../ckeditor/ckeditor.js',
PROJECT_PATH.js + '/../ckeditor_plugins/cmswidget/plugin.js',
PROJECT_PATH.js + '/../ckeditor_plugins/cmsdialog/plugin.js',
PROJECT_PATH.js + '/../ckeditor_plugins/cmsresize/plugin.js',
PROJECT_PATH.js + '/../ckeditor_plugins/cmsplugins/plugin.js',
PROJECT_PATH.js + '/post.js'
];
const lint = () => {
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()))
);
};
const INTEGRATION_TESTS = [
['smoke']
];
// gulp tests:integration [--clean] [--screenshots] [--tests=loginAdmin,toolbar]
const pathToBin = child_process.execSync('npm bin').toString().trim();
const pathToCasper = path.join(pathToBin, 'casperjs');
gulp.task('tests:integration', integrationTests({
tests: INTEGRATION_TESTS,
pathToTests: PROJECT_PATH.tests,
argv: argv,
dbPath: 'testdb.sqlite',
serverCommand: 'tests/settings.py',
logger: console.log.bind(console), // eslint-disable-line no-console
waitForMigrations: 10,
pathToCasper: pathToCasper
}));
gulp.task('bundle', function (done) {
runSequence('bundle:cleanup:before', 'bundle:js', 'bundle:template', 'bundle:cleanup', done);
});
// gulp.task('bundle:cleanup:before', function () {
const bundleCleanUpBefore = () => {
return (
del([PROJECT_PATH.js + '/dist/'])
);
};
const bundleJS = () => {
const f = filter([
'**',
'!**/ckeditor/ckeditor.js',
'!**/pre.js',
'!**/post.js'
], { restore: true });
return (
gulp
.src(JS_BUNDLE)
.pipe(gulpif(options.debug, sourcemaps.init()))
.pipe(f)
.pipe(gulpif(!options.debug, uglify({
preserveComments: 'some'
})))
.pipe(f.restore)
.pipe(concat('bundle.cms.ckeditor.min.js', {
newLine: '\n'
}))
.pipe(rev())
.pipe(gulpif(options.debug, sourcemaps.write()))
.pipe(gulp.dest(PROJECT_PATH.js + '/dist/'))
.pipe(rev.manifest())
.pipe(gulp.dest(PROJECT_PATH.js + '/dist/'))
);
};
const bundleTemplate = () => {
const manifest = gulp.src(PROJECT_PATH.js + '/dist/rev-manifest.json');
return (
gulp
.src([PROJECT_ROOT + '/../../widgets.py'])
.pipe(replace(
/bundle\-*.cms.ckeditor.min.js/,
'bundle.cms.ckeditor.min.js'
))
.pipe(gulp.dest(PROJECT_ROOT + '/../../'))
.pipe(revReplace({
manifest: manifest,
replaceInExtensions: ['.py']
}))
.pipe(gulp.dest(PROJECT_ROOT + '/../../'))
);
};
const patchForDarkmode = async function(){
console.log( execSync('cd private && python3 ./patch_moono_lisa.py').toString());
};
const bundleCleanup = () => {
return (
del([PROJECT_PATH.js + '/dist/rev-manifest.json'])
);
};
const watchFiles = () => {
browserSync.init();
gulp.watch(PROJECT_PATTERNS.js, lint);
gulp.watch(JS_BUNDLE, gulp.series(bundleCleanUpBefore, bundleJS, bundleTemplate, bundleCleanup));
};
gulp.task('ci', lint);
// gulp.task('default', ['lint', 'bundle', 'watch']);
gulp.task("lint", lint);
gulp.task("watch", watchFiles);
gulp.task("darkmode", patchForDarkmode);
gulp.task("bundle", gulp.series(bundleCleanUpBefore, bundleJS, bundleTemplate, bundleCleanup));
gulp.task("build", gulp.series(bundleCleanUpBefore, bundleJS, bundleTemplate, patchForDarkmode, bundleCleanup));