about summary refs log tree commit diff
path: root/config/webpack/shared.js
diff options
context:
space:
mode:
authorbeatrix <beatrix.bitrot@gmail.com>2017-12-06 17:44:07 -0500
committerGitHub <noreply@github.com>2017-12-06 17:44:07 -0500
commit81b01457598459c42a7b14d9aa14f91ba60dcae1 (patch)
tree7d3e6dadb75f3be95e5a5ed8b7ecfe90e7711831 /config/webpack/shared.js
parentf1cbea77a4a52929244198dcbde26d63d837489a (diff)
parent017fc81caf8f265e5c5543186877437485625795 (diff)
Merge pull request #229 from glitch-soc/glitch-theme
Advanced Next-Level Flavours And Skins For Mastodon™
Diffstat (limited to 'config/webpack/shared.js')
-rw-r--r--config/webpack/shared.js60
1 files changed, 41 insertions, 19 deletions
diff --git a/config/webpack/shared.js b/config/webpack/shared.js
index 5d176db4e..e4b057ffb 100644
--- a/config/webpack/shared.js
+++ b/config/webpack/shared.js
@@ -1,38 +1,60 @@
 // 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');
 const extname = require('path-complete-extname');
-const { env, settings, themes, output, loadersDir } = require('./configuration.js');
+const { env, settings, core, flavours, output, loadersDir } = require('./configuration.js');
 const localePackPaths = require('./generateLocalePacks');
 
-const extensionGlob = `**/*{${settings.extensions.join(',')}}*`;
-const entryPath = join(settings.source_path, settings.source_entry_path);
-const packPaths = sync(join(entryPath, extensionGlob));
+function reducePacks (data, into = {}) {
+  if (!data.pack) {
+    return into;
+  }
+  Object.keys(data.pack).reduce((map, entry) => {
+    const pack = data.pack[entry];
+    if (!pack) {
+      return map;
+    }
+    const packFile = typeof pack === 'string' ? pack : pack.filename;
+    if (packFile) {
+      map[data.name ? `flavours/${data.name}/${entry}` : `core/${entry}`] = resolve(data.pack_directory, packFile);
+    }
+    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;
+}
 
 module.exports = {
   entry: Object.assign(
-    packPaths.reduce((map, entry) => {
-      const localMap = map;
-      const namespace = relative(join(entryPath), dirname(entry));
-      localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry);
-      return localMap;
-    }, {}),
+    { locales: resolve('app', 'javascript', 'locales') },
     localePackPaths.reduce((map, entry) => {
       const localMap = map;
       localMap[basename(entry, extname(entry, extname(entry)))] = resolve(entry);
       return localMap;
     }, {}),
-    Object.keys(themes).reduce(
-      (themePaths, name) => {
-        const themeData = themes[name];
-        themePaths[`themes/${name}`] = resolve(themeData.pack_directory, themeData.pack);
-        return themePaths;
-      }, {}
-    )
+    reducePacks(core),
+    Object.keys(flavours).reduce((map, entry) => reducePacks(flavours[entry], map), {})
   ),
 
   output: {
@@ -64,7 +86,7 @@ module.exports = {
       writeToFileEmit: true,
     }),
     new webpack.optimize.CommonsChunkPlugin({
-      name: 'common',
+      name: 'locales',
       minChunks: Infinity, // It doesn't make sense to use common chunks with multiple frontend support.
     }),
   ],