]> git.agnieray.net Git - galette.git/blob - gulpfile.js
Move all assets' sources out of webroot folder
[galette.git] / gulpfile.js
1 /*
2 * Set the URL of your local instance of Galette here.
3 * Then run "gulp serve".
4 * This is for local development purpose only.
5 * Don't commit this change in the repository.
6 */
7 const localServer = {
8 url: 'http://galette.localhost/'
9 }
10
11 var gulp = require('gulp'),
12 del = require('del'),
13 uglify = require('gulp-uglify'),
14 cleanCSS = require('gulp-clean-css'),
15 merge = require('merge-stream'),
16 concat = require('gulp-concat'),
17 replace = require('gulp-replace'),
18 browserSync = require('browser-sync').create(),
19 build = require('./semantic/tasks/build'),
20 buildJS = require('./semantic/tasks/build/javascript'),
21 buildCSS = require('./semantic/tasks/build/css'),
22 buildAssets = require('./semantic/tasks/build/assets')
23 ;
24
25 gulp.task('build ui', build);
26 gulp.task('build-css', buildCSS);
27 gulp.task('build-javascript', buildJS);
28 gulp.task('build-assets', buildAssets);
29
30 var paths = {
31 webroot: './galette/webroot/',
32 assets: {
33 public: './galette/webroot/assets/',
34 css: './galette/webroot/assets/css/',
35 js: './galette/webroot/assets/js/',
36 webfonts: './galette/webroot/assets/webfonts/',
37 theme: {
38 public: './galette/webroot/themes/default/',
39 css: './galette/webroot/themes/default/ui/semantic.min.css',
40 js: './galette/webroot/themes/default/ui/semantic.min.js',
41 images: './galette/webroot/themes/default/images/'
42 }
43 },
44 src: {
45 theme: './ui/semantic/galette/**/*',
46 config: './ui/semantic/theme*',
47 files: [
48 './ui/semantic/galette/*',
49 './ui/semantic/galette/**/*.*'
50 ],
51 css: './ui/css/**/*.css',
52 js: './ui/js/*.js',
53 favicon:'./ui/images/favicon.ico',
54 faviconpng:'./ui/images/favicon.png',
55 logo: './ui/images/galette.png',
56 photo:'./ui/images/default.png'
57 },
58 semantic: {
59 src: './semantic/src/',
60 theme: './semantic/src/themes/galette/'
61 },
62 styles: {
63 main: [
64 './ui/css/galette.css',
65 './node_modules/summernote/dist/summernote-lite.min.css'
66 ]
67 },
68 scripts: {
69 main: [
70 './node_modules/jquery/dist/jquery.js',
71 './node_modules/js-cookie/dist/js.cookie.min.js',
72 './node_modules/summernote/dist/summernote-lite.min.js',
73 './ui/js/common.js'
74 ],
75 chartjs: [
76 './node_modules/chart.js/dist/chart.min.js',
77 './node_modules/chartjs-plugin-autocolors/dist/chartjs-plugin-autocolors.min.js',
78 './node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.min.js'
79 ],
80 sortablejs: [
81 './node_modules/sortablejs/Sortable.min.js'
82 ]
83 },
84 extras: [
85 {
86 src: './ui/css/galette_print.css',
87 dest: 'css/'
88 }, {
89 src: './ui/css/install.css',
90 dest: 'css/'
91 }, {
92 src: './ui/js/mass_changes.js',
93 dest: 'js/'
94 }, {
95 src: './node_modules/summernote/dist/font/*',
96 dest: 'webfonts/'
97 }, {
98 src: './node_modules/summernote/dist/lang/*.min.js',
99 dest: 'js/lang/'
100 }
101 ]
102 };
103
104 function galette() {
105 favicon = gulp.src(paths.src.favicon)
106 .pipe(gulp.dest(paths.webroot))
107 .pipe(browserSync.stream());
108
109 faviconpng = gulp.src(paths.src.faviconpng)
110 .pipe(gulp.dest(paths.assets.theme.images))
111 .pipe(browserSync.stream());
112
113 logo = gulp.src(paths.src.logo)
114 .pipe(gulp.dest(paths.assets.theme.images))
115 .pipe(browserSync.stream());
116
117 photo = gulp.src(paths.src.photo)
118 .pipe(gulp.dest(paths.assets.theme.images))
119 .pipe(browserSync.stream());
120
121 return merge(favicon, logo, photo);
122 }
123
124 function theme() {
125 config = gulp.src(paths.src.config)
126 .pipe(gulp.dest(paths.semantic.src))
127 .pipe(browserSync.stream());
128
129 theme = gulp.src(paths.src.files)
130 .pipe(gulp.dest(paths.semantic.theme))
131 .pipe(browserSync.stream());
132
133 return merge(config, theme);
134 }
135
136 function clean() {
137 return del([
138 paths.assets.public,
139 paths.assets.theme.public,
140 ]);
141 }
142
143 function styles() {
144 main = gulp.src(paths.styles.main)
145 .pipe(replace('url(font/', 'url(../webfonts/'))
146 .pipe(cleanCSS())
147 .pipe(concat('galette-main.bundle.min.css'))
148 .pipe(gulp.dest(paths.assets.css))
149 .pipe(browserSync.stream());
150
151 return merge(main);
152 }
153
154 function scripts() {
155 main = gulp.src(paths.scripts.main)
156 .pipe(concat('galette-main.bundle.min.js'))
157 .pipe(uglify())
158 .pipe(gulp.dest(paths.assets.js))
159 .pipe(browserSync.stream());
160
161 chartjs = gulp.src(paths.scripts.chartjs)
162 .pipe(concat('galette-chartjs.bundle.min.js'))
163 .pipe(gulp.dest(paths.assets.js))
164 .pipe(browserSync.stream());
165
166 sortablejs = gulp.src(paths.scripts.sortablejs)
167 .pipe(concat('galette-sortablejs.bundle.min.js'))
168 .pipe(gulp.dest(paths.assets.js))
169 .pipe(browserSync.stream());
170
171 return merge(main, chartjs, sortablejs);
172 }
173
174 function extras() {
175 main = paths.extras.map(function (extra) {
176 return gulp.src(extra.src)
177 .pipe(gulp.dest(paths.assets.public + extra.dest))
178 .pipe(browserSync.stream());
179 }
180 );
181
182 return merge(main);
183 }
184
185 function watch() {
186 browserSync.init({
187 proxy: localServer.url
188 })
189
190 gulp.watch([paths.src.favicon, paths.src.faviconpng, paths.src.logo, paths.src.photo], gulp.series(galette)).on('change', browserSync.reload)
191 gulp.watch([paths.src.theme, paths.src.config], gulp.series(theme, 'build-css')).on('change', browserSync.reload)
192 gulp.watch([paths.src.css], gulp.series(styles)).on('change', browserSync.reload)
193 gulp.watch([paths.src.js], gulp.series(scripts)).on('change', browserSync.reload)
194 gulp.watch([paths.assets.theme.css, paths.assets.theme.js, paths.assets.theme.images]).on('change', browserSync.reload)
195 }
196
197 exports.galette = galette;
198 exports.theme = theme;
199 exports.clean = clean;
200 exports.styles = styles;
201 exports.scripts = scripts;
202 exports.extras = extras;
203 exports.watch = watch;
204
205 var build = gulp.series(theme, clean, styles, scripts, extras, 'build ui', galette);
206 exports.default = build;