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-20 22:13:37 -0800
committerkibigo! <marrus-sh@users.noreply.github.com>2017-11-20 22:13:37 -0800
commitbdbbd06dad298dc3e1a5f568f4a3ff3635b48f22 (patch)
tree1a475460389053b41f293d27f7c915f0d545d4ad /config/webpack
parent321fa41930f8a11356939a1684ff153f2f46443b (diff)
Finalized theme loading and stuff
Diffstat (limited to 'config/webpack')
-rw-r--r--config/webpack/configuration.js13
-rw-r--r--config/webpack/generateLocalePacks.js2
-rw-r--r--config/webpack/shared.js40
3 files changed, 35 insertions, 20 deletions
diff --git a/config/webpack/configuration.js b/config/webpack/configuration.js
index 74f75d89b..9514bc547 100644
--- a/config/webpack/configuration.js
+++ b/config/webpack/configuration.js
@@ -12,14 +12,24 @@ const settings = safeLoad(readFileSync(configPath), 'utf8')[env.NODE_ENV];
 const themeFiles = glob.sync('app/javascript/themes/*/theme.yml');
 const themes = {};
 
+const core = function () {
+  const coreFile = resolve('app', 'javascript', 'core', 'theme.yml');
+  const data = safeLoad(readFileSync(coreFile), 'utf8');
+  if (!data.pack_directory) {
+    data.pack_directory = dirname(coreFile);
+  }
+  return data.pack ? data : {};
+}();
+
 for (let i = 0; i < themeFiles.length; i++) {
   const themeFile = themeFiles[i];
   const data = safeLoad(readFileSync(themeFile), 'utf8');
+  data.name = basename(dirname(themeFile));
   if (!data.pack_directory) {
     data.pack_directory = dirname(themeFile);
   }
   if (data.pack) {
-    themes[basename(dirname(themeFile))] = data;
+    themes[data.name] = data;
   }
 }
 
@@ -43,6 +53,7 @@ const output = {
 
 module.exports = {
   settings,
+  core,
   themes,
   env,
   loadersDir,
diff --git a/config/webpack/generateLocalePacks.js b/config/webpack/generateLocalePacks.js
index cd3bed50c..a943589f7 100644
--- a/config/webpack/generateLocalePacks.js
+++ b/config/webpack/generateLocalePacks.js
@@ -57,7 +57,7 @@ Object.keys(glitchMessages).forEach(function (key) {
 //
 import messages from '../../app/javascript/mastodon/locales/${locale}.json';
 import localeData from ${JSON.stringify(localeDataPath)};
-import { setLocale } from '../../app/javascript/mastodon/locales';
+import { setLocale } from 'locales';
 ${glitchInject}
 setLocale({messages: mergedMessages, localeData: localeData});
 `;
diff --git a/config/webpack/shared.js b/config/webpack/shared.js
index 5d176db4e..5b90f27fb 100644
--- a/config/webpack/shared.js
+++ b/config/webpack/shared.js
@@ -6,33 +6,37 @@ 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, themes, 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 ? `themes/${data.name}/${entry}` : `core/${entry}`] = resolve(data.pack_directory, packFile);
+    }
+    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(themes).reduce((map, entry) => reducePacks(themes[entry], map), {})
   ),
 
   output: {
@@ -64,7 +68,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.
     }),
   ],