-
-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mozaik.inspector): add theme support
- Loading branch information
Raphael Benitte
committed
Apr 5, 2016
1 parent
15df1ba
commit d5dc3ed
Showing
9 changed files
with
94 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,51 @@ | ||
var gulp = require('gulp'); | ||
var path = require('path'); | ||
var stylus = require('gulp-stylus'); | ||
var fs = require('fs'); | ||
var gutil = require('gulp-util'); | ||
var chalk = require('chalk'); | ||
var config = require('../config'); | ||
var gulp = require('gulp'); | ||
var path = require('path'); | ||
var stylus = require('gulp-stylus'); | ||
var fs = require('fs'); | ||
var gutil = require('gulp-util'); | ||
var chalk = require('chalk'); | ||
var config = require('../config'); | ||
var Promise = require('bluebird'); | ||
|
||
|
||
gulp.task('styles', ['styles:dev']); | ||
|
||
|
||
gulp.task('styles:dev', ['collect:styles'], function (done) { | ||
var appConfig = require(path.join(config.root, 'config.js')); | ||
var theme = appConfig.theme; | ||
|
||
var mozaikThemePath = config.mozaikSrc + path.join('themes', theme); | ||
var customThemePath = config.root + path.join('themes', theme); | ||
|
||
if (fs.existsSync(customThemePath)) { | ||
theme = customThemePath; | ||
} else if (fs.existsSync(mozaikThemePath)) { | ||
theme = mozaikThemePath; | ||
} | ||
|
||
if (fs.existsSync(path.join(theme, '_vars.styl')) === false || fs.existsSync(path.join(theme, 'index.styl')) == false) { | ||
return done(new Error(chalk.red('Please make sure your theme contains both \'_vars.styl\' and \'index.styl\' files (path: ' + theme + ')'))); | ||
} | ||
|
||
gutil.log(chalk.green('Compiling stylus code using theme \'' + theme + '\'')); | ||
|
||
return gulp | ||
.src(config.mozaikSrc + 'styl/mozaik.styl') | ||
.pipe(stylus({ | ||
'include css': true, | ||
use: function (style) { | ||
style.define('$theme', theme); | ||
} | ||
})) | ||
.pipe(gulp.dest(config.dest + 'css')) | ||
; | ||
gulp.task('styles:dev', ['collect:styles'], function () { | ||
return new Promise(function (resolve, reject) { | ||
// invalidate config require cache to force reload | ||
var mod = require.resolve(path.join(config.root, 'config.js')); | ||
if (mod && ((mod = require.cache[mod]) !== undefined)) { | ||
delete require.cache[mod.id]; | ||
} | ||
|
||
var appConfig = require(path.join(config.root, 'config.js')); | ||
var theme = appConfig.theme; | ||
|
||
var mozaikThemePath = config.mozaikSrc + path.join('themes', theme); | ||
var customThemePath = config.root + path.join('themes', theme); | ||
|
||
if (fs.existsSync(customThemePath)) { | ||
theme = customThemePath; | ||
} else if (fs.existsSync(mozaikThemePath)) { | ||
theme = mozaikThemePath; | ||
} | ||
|
||
if (fs.existsSync(path.join(theme, '_vars.styl')) === false || fs.existsSync(path.join(theme, 'index.styl')) == false) { | ||
return done(new Error(chalk.red('Please make sure your theme contains both \'_vars.styl\' and \'index.styl\' files (path: ' + theme + ')'))); | ||
} | ||
|
||
gutil.log(chalk.green('Compiling stylus code using theme \'' + theme + '\'')); | ||
|
||
resolve(gulp | ||
.src(config.mozaikSrc + 'styl/mozaik.styl') | ||
.pipe(stylus({ | ||
'include css': true, | ||
use: function (style) { | ||
style.define('$theme', theme); | ||
} | ||
})) | ||
.pipe(gulp.dest(config.dest + 'css')) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters