-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
96 lines (77 loc) · 3.02 KB
/
index.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
global.rootPath = __dirname;
const {
gulpTaskInit
} = require('@sxa/celt');
const fileActionResolver = require('@sxa/celt/util/fileActionResolver').fileActionResolver;
const uploadScriban = require('@sxa/celt/util/requestChangeScriban');
// Ensure process ends after all Gulp tasks are finished
const gulp = require('gulp');
const watch = require('gulp-watch');
const bulkSass = require('gulp-sass-bulk-import');
const gulpReplace = require('gulp-replace');
const fs = require('fs');
const path = require('path');
const through = require('through2');
const config = require(global.rootPath + '/gulp/config');
const uploadFilesGlob = ['scripts/**/*', 'styles/**/*', 'fonts/**/*', 'images/**/*', '!images/flags/**/*'];
gulpTaskInit();
// Fix the wildcard imports of the sass copied from the Sitecore default theme provided in @sxa/Theme.
// The provided sass is not valid sass - top-level wildcard imports initially handled by gulp-sass-bulk-import
// but does not work over multiple levels.
// Fix location of "base/.." folder - must be relative due to new build approach using webpack
gulp.task('fix-defaulttheme-sass-for-webpack', function() {
gulp
.src('defaulttheme/sass/*.scss')
.pipe(bulkSass())
// make @import path relative to sass folder
.pipe(gulpReplace(path.join(__dirname, 'defaulttheme/sass/').replace(/\\/g,'/'), './'))
.pipe( gulp.dest('defaulttheme/sass/') );
gulp
.src('defaulttheme/sass/*/*.scss')
.pipe(gulpReplace('"base/', '"../base/'))
.pipe( gulp.dest('defaulttheme/sass/') );
gulp
.src('defaulttheme/sass/*/*/*.scss')
.pipe(gulpReplace('"base/', '"../../base/'))
.pipe( gulp.dest('defaulttheme/sass/') );
});
// Deploy/watch all created artifacts to Sitecore:
// - -/scriban/**/*.scriban
// - scripts/**/* (e.g. pre-optimized-min.js, ...)
// - styles/**/* (e.g. pre-optimized-min.css, ...)
// - fonts/**/*
// - images/**/* - excluding the images/flags folder
// Watch images and Scriban files and the generated scripts/pre-optimized-min.js (+ other bundles) and styles/pre-optimized-min.css (+ other modules)
// Note that sources/index.ts + included files (also sass) is watched by webpack resulting in one or more files in scripts and styles folders
gulp.task('custom-all-watch', ['login'],
function () {
global.isWatching = true;
// Upload Scriban files
gulp.run('watch-scriban');
// Watch other files
gulp.watch(uploadFilesGlob, { verbose: 0, delay: 500 }, function (file) {
processFile(file);
});
}
);
gulp.task('deploy-to-sitecore', ['login'], function () {
uploadScriban({
path: `${__dirname}/-/scriban/metadata.json`
});
gulp.src(uploadFilesGlob, { strict: true, silent: false })
.pipe(processFileInPipeline())
});
const processFileInPipeline = () => {
return through.obj({ highWaterMark: 256 }, (file, enc, cb, ) => {
processFile(file);
return cb(null, file);
});
}
const processFile = (file) => {
if (fs.lstatSync(file.path).isFile()) {
fileActionResolver({
path: file.path,
event: 'change'
});
}
}