Commit c0a62c16 authored by Eric Eastwood's avatar Eric Eastwood
Browse files
parent 52e8c5bd
Pipeline #10694157 passed with stage
in 13 minutes and 7 seconds
......@@ -22,7 +22,6 @@ Gitter requires MongoDB, Redis, ElasticSearch and Neo4J. These are all included
1. Clone this repo
1. Run `npm install`
* Go and make a cup of tea, because this will take a rather long time.
1. Do an initial compile of the CSS with `npm run task-css` this will be part of the gulp task [in the future](https://gitlab.com/gitlab-org/gitter/webapp/issues/1741).
## Starting Gitter
......
......@@ -93,6 +93,9 @@ gulp.task('css:compile:desktop', function() {
});
gulp.task('css:watch', function() {
cssWebStyleBuilder.build();
cssMobileStyleBuilder.build();
cssMobileStyleBuilder.startWatching();
cssWebStyleBuilder.startWatching();
});
......@@ -3,6 +3,8 @@
var Promise = require('bluebird');
var _ = require('underscore');
var path = require('path');
var fs = require('fs');
var stat = Promise.promisify(fs.stat);
var EventEmitter = require('events').EventEmitter;
var chokidar = require('chokidar');
......@@ -18,8 +20,23 @@ var transformPathsToAbsolute = function(paths, /*option*/basePath) {
});
};
var transformEntryPointToDestFile = function(entryPoint, dest) {
var fileName = path.basename(entryPoint, '.less') + '.css';
return transformPathsToAbsolute(path.join(dest, fileName))[0];
};
var getLastModifiedTime = function(targetFile) {
return stat(targetFile)
.catch(function() {
return {
mtime: -1
};
})
.then(function(targetStats) {
return targetStats.mtime;
});
};
var defaults = {
......@@ -36,33 +53,76 @@ var LessWatcher = function(entryPoints, options) {
this.watchHandle = null;
};
LessWatcher.prototype.getDepMap = function() {
var depMap = this.depMap;
if(!depMap) {
var absoluteEntryPoints = transformPathsToAbsolute(this.entryPoints);
var lessOptions = this.opts.lessOptions;
depMap = {};
var depMapGeneratedPromise = Promise.all(absoluteEntryPoints.map(function(entryPoint) {
var depMapPromise = lessDependencyMapUtils.generateLessDependencyMap(entryPoint, lessOptions);
LessWatcher.prototype.generateDepMap = function() {
var depMap = {};
var absoluteEntryPoints = transformPathsToAbsolute(this.entryPoints);
var lessOptions = this.opts.lessOptions;
return depMapPromise
.then(function(partialDepMap) {
depMap = lessDependencyMapUtils.extendDepMaps(depMap, partialDepMap);
});
}.bind(this)));
return depMapGeneratedPromise
.then(function() {
return depMap;
var depMapGeneratedPromise = Promise.all(absoluteEntryPoints.map(function(entryPoint) {
return lessDependencyMapUtils.generateLessDependencyMap(entryPoint, lessOptions)
.then(function(partialDepMap) {
depMap = lessDependencyMapUtils.extendDepMaps(depMap, partialDepMap);
});
}
}));
return depMapGeneratedPromise
.then(function() {
return depMap;
});
};
this.depMap = depMap;
return Promise.resolve(this.depMap);
LessWatcher.prototype.getDepMap = function() {
return this.depMap ?
Promise.resolve(this.depMap) :
this.generateDepMap()
.tap(function(depMap) {
this.depMap = depMap;
}.bind(this));
};
LessWatcher.prototype.getDirtyEntryPoints = function() {
var opts = this.opts;
var entryPoints = this.entryPoints;
var absoluteEntryPoints = transformPathsToAbsolute(entryPoints);
var dirtyEntryMap = {};
return this.getDepMap()
.then(function(depMap) {
var filesToCheck = Object.keys(depMap).concat(absoluteEntryPoints);
return Promise.map(filesToCheck, function(needleFile) {
return getLastModifiedTime(needleFile)
.then(function(needleMTime) {
var affectedEntryPoints = lessDependencyMapUtils.getEntryPointsAffectedByFile(
depMap,
absoluteEntryPoints,
needleFile
);
return Promise.each(affectedEntryPoints, function(entryPoint) {
var destFile = transformEntryPointToDestFile(entryPoint, opts.dest);
// Compare the entry(root) compiled file time to the needle(child) file time
return getLastModifiedTime(destFile)
.then(function(destMTime) {
var destTime = new Date(destMTime).getTime();
var needleTime = new Date(needleMTime).getTime();
if (destTime < needleTime) {
dirtyEntryMap[entryPoint] = true;
}
});
});
});
});
})
.then(function() {
return Object.keys(dirtyEntryMap);
});
}
LessWatcher.prototype.startWatching = function(/*optional*/newWatchGlob) {
console.log('Starting to watch Less');
......
......@@ -28,15 +28,15 @@ module.exports = function(entryPoints, options) {
.pipe(sourcemaps.init())
.pipe(less(opts.lessOptions));
opts.streamTransform(stream)
.pipe(sourcemaps.write(opts.sourceMapOptions.dest, opts.sourceMapOptions.options))
.pipe(gulp.dest(opts.dest))
.on('end', function() {
resolve();
})
.on('error', function(err) {
reject(err);
});
opts.streamTransform(stream)
.pipe(sourcemaps.write(opts.sourceMapOptions.dest, opts.sourceMapOptions.options))
.pipe(gulp.dest(opts.dest))
.on('end', function() {
resolve();
})
.on('error', function(err) {
reject(err);
});
});
};
......@@ -49,8 +49,16 @@ module.exports = function(entryPoints, options) {
});
return {
build: function() {
return buildStyles(entryPoints)
build: function(force) {
var getTargetEntryPointsPromise = Promise.resolve(entryPoints);
if (!force) {
getTargetEntryPointsPromise = myLessWatcher.getDirtyEntryPoints();
}
return getTargetEntryPointsPromise
.then(function(targetEntryPoints) {
return buildStyles(targetEntryPoints);
})
.then(function() {
console.log('building done');
});
......
......@@ -11,4 +11,3 @@
.login-view__agree {
text-align: center;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment