about summary refs log tree commit diff
path: root/config/webpack
diff options
context:
space:
mode:
authorkibigo! <marrus-sh@users.noreply.github.com>2017-11-30 19:29:47 -0800
committerkibigo! <marrus-sh@users.noreply.github.com>2017-11-30 19:29:47 -0800
commit541fe9b110fce15c42ba15df27926552c234afd0 (patch)
treef4c0a74cb87d4d40ca44e99f1825fa9cd47edf96 /config/webpack
parent8812bab6875024f76c59ab43d1dd3717e5e6da68 (diff)
Skins support
Diffstat (limited to 'config/webpack')
-rw-r--r--config/webpack/configuration.js28
-rw-r--r--config/webpack/shared.js20
2 files changed, 44 insertions, 4 deletions
diff --git a/config/webpack/configuration.js b/config/webpack/configuration.js
index f8741c5d8..cb31c6ab8 100644
--- a/config/webpack/configuration.js
+++ b/config/webpack/configuration.js
@@ -1,15 +1,16 @@
 // Common configuration for webpacker loaded from config/webpacker.yml
 
-const { basename, dirname, join, resolve } = require('path');
+const { basename, dirname, extname, join, resolve } = require('path');
 const { env } = require('process');
 const { safeLoad } = require('js-yaml');
-const { readFileSync } = require('fs');
+const { lstatSync, readFileSync } = require('fs');
 const glob = require('glob');
 
 const configPath = resolve('config', 'webpacker.yml');
 const loadersDir = join(__dirname, 'loaders');
 const settings = safeLoad(readFileSync(configPath), 'utf8')[env.NODE_ENV];
 const themeFiles = glob.sync('app/javascript/themes/*/theme.yml');
+const skinFiles = glob.sync('app/javascript/skins/*/*');
 const themes = {};
 
 const core = function () {
@@ -25,14 +26,35 @@ for (let i = 0; i < themeFiles.length; i++) {
   const themeFile = themeFiles[i];
   const data = safeLoad(readFileSync(themeFile), 'utf8');
   data.name = basename(dirname(themeFile));
+  data.skin = {};
   if (!data.pack_directory) {
     data.pack_directory = dirname(themeFile);
   }
-  if (data.pack && typeof data.pack == 'object') {
+  if (data.pack && typeof data.pack === 'object') {
     themes[data.name] = data;
   }
 }
 
+for (let i = 0; i < skinFiles.length; i++) {
+  const skinFile = skinFiles[i];
+  let skin = basename(skinFile);
+  const name = basename(dirname(skinFile));
+  if (!themes[name]) {
+    continue;
+  }
+  const data = themes[name].skin;
+  if (lstatSync(skinFile).isDirectory()) {
+    data[skin] = {};
+    const skinPacks = glob.sync(skinFile, '*.{css,scss}');
+    for (let j = 0; j < skinPacks.length; j++) {
+      const pack = skinPacks[i];
+      data[skin][basename(pack, extname(pack))] = pack;
+    }
+  } else if ((skin = skin.match(/^(.*)\.s?css$/i))) {
+    data[skin[1]] = { common: skinFile };
+  }
+}
+
 function removeOuterSlashes(string) {
   return string.replace(/^\/*/, '').replace(/\/*$/, '');
 }
diff --git a/config/webpack/shared.js b/config/webpack/shared.js
index 5b90f27fb..a2550bc81 100644
--- a/config/webpack/shared.js
+++ b/config/webpack/shared.js
@@ -1,7 +1,7 @@
 // Note: You must restart bin/webpack-dev-server for changes to take effect
 
 const webpack = require('webpack');
-const { basename, dirname, join, relative, resolve } = require('path');
+const { basename, join, resolve } = require('path');
 const { sync } = require('glob');
 const ExtractTextPlugin = require('extract-text-webpack-plugin');
 const ManifestPlugin = require('webpack-manifest-plugin');
@@ -24,6 +24,24 @@ function reducePacks (data, into = {}) {
     }
     return map;
   }, into);
+  if (data.name) {
+    Object.keys(data.skin).reduce((map, entry) => {
+      const skin = data.skin[entry];
+      const skinName = entry;
+      if (!skin) {
+        return map;
+      }
+      Object.keys(skin).reduce((map, entry) => {
+        const packFile = skin[entry];
+        if (!packFile) {
+          return map;
+        }
+        map[`skins/${data.name}/${skinName}/${entry}`] = resolve(packFile);
+        return map;
+      }, into);
+      return map;
+    }, into);
+  }
   return into;
 }