Created
June 8, 2016 14:25
-
-
Save Igloczek/33f91fedc455321bbbf87480fc557245 to your computer and use it in GitHub Desktop.
Frontools theme inheritance temporary workaround
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
module.exports = function() { | |
// global vars | |
var gulp = this.gulp, | |
plugins = this.opts.plugins, | |
config = this.opts.configs; | |
// local plugins | |
const fs = require('fs'); | |
const path = require('path'); | |
const mkdirp = require('mkdirp'); | |
// local vars | |
var themeName = plugins.util.env.theme || false, | |
themes = themeName ? [themeName] : Object.keys(config.themes); | |
// Cycles through themes defined in themes.json | |
themes.forEach(name => { | |
var theme = config.themes[name]; | |
// Triggers if the current theme has a 'parent' argument | |
if (theme.parent) { | |
var parentSrc = config.themes[theme.parent].src; | |
// Creates an array of paths for every .scss file in the parent theme | |
var partials = plugins.globby.sync( | |
[ | |
config.projectPath + parentSrc + '/**/*.scss' | |
] | |
); | |
// Iterates through the array | |
partials.forEach(function(partial) { | |
// Grabs the relative file path after the parent theme dir name | |
var relPath = path.parse(partial).dir.split(parentSrc).pop(), | |
// Stores only the partial's file name in a variable | |
fileName = path.parse(partial).base; | |
// Creates empty directory structures based on paths from the globby array | |
// This will ONLY create necessary folder structures (no templates or layout folders are included) | |
mkdirp(config.projectPath + theme.src + relPath, () => { | |
// when the callback fires, symlinks to each of the scss partials are established based on the parent theme | |
fs.symlink( | |
partial, config.projectPath + theme.src + relPath + '/' + fileName, | |
() => { | |
plugins.util.log( | |
plugins.util.colors.green( | |
'Symlinked: ' + relPath + '/' + fileName + ' to ' + name | |
) | |
); | |
} | |
); | |
}); | |
}) | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment