From 0162d887e780ddf5985664700cf8d00bbc708b86 Mon Sep 17 00:00:00 2001
From: Alf Eaton <eaton.alf@gmail.com>
Date: Tue, 22 Aug 2017 22:16:13 +0100
Subject: [PATCH] Add styleguide to component-manuscript

---
 .../webpack.config.js                         |  4 +--
 packages/component-manuscript/package.json    | 19 ++++++++++--
 .../src/components/Manuscript.md              | 29 +++++++++++++++++++
 .../component-manuscript/styleguide.config.js | 22 ++++++++++++++
 .../component-manuscript/webpack.config.js    | 15 +++++++---
 packages/xpub-ui/webpack.config.js            |  4 +--
 6 files changed, 80 insertions(+), 13 deletions(-)
 create mode 100644 packages/component-manuscript/src/components/Manuscript.md
 create mode 100644 packages/component-manuscript/styleguide.config.js

diff --git a/packages/component-authentication/webpack.config.js b/packages/component-authentication/webpack.config.js
index 62d213e0b..22200b0a2 100644
--- a/packages/component-authentication/webpack.config.js
+++ b/packages/component-authentication/webpack.config.js
@@ -8,9 +8,7 @@ module.exports = {
   entry: './src/index.js',
   output: {
     filename: 'index.js',
-    path: path.join(__dirname, 'dist'),
-    library: 'xpub-authentication',
-    libraryTarget: 'commonjs2'
+    path: path.join(__dirname, 'dist')
   },
   devtool: 'cheap-module-source-map',
   externals: [nodeExternals({
diff --git a/packages/component-manuscript/package.json b/packages/component-manuscript/package.json
index e396dd668..c0bdf5ca3 100644
--- a/packages/component-manuscript/package.json
+++ b/packages/component-manuscript/package.json
@@ -16,7 +16,8 @@
     "react": "^15.6.1",
     "react-dom": "^15.6.1",
     "react-redux": "^5.0.2",
-    "react-router": "^3.0.5"
+    "react-router": "^3.0.5",
+    "recompose": "^0.25.0"
   },
   "devDependencies": {
     "babel-loader": "^7.1.1",
@@ -27,18 +28,30 @@
     "css-loader": "^0.28.4",
     "eslint": "^4.4.1",
     "extract-text-webpack-plugin": "^2.1.2",
+    "faker": "^4.1.0",
     "file-loader": "^0.11.2",
     "node-sass": "^4.5.3",
+    "recompose": "^0.25.0",
     "rimraf": "^2.6.1",
+    "xpub-styleguide": "^0.0.2",
+    "react-styleguidist": "^6.0.8",
     "sass-loader": "^6.0.6",
     "style-loader": "^0.18.2",
     "webpack": "^3.5.5",
-    "webpack-node-externals": "^1.6.0"
+    "webpack-node-externals": "^1.6.0",
+    "prop-types": "^15.5.10",
+    "pubsweet-client": "^1.0.0-alpha.1",
+    "react": "^15.6.1",
+    "react-dom": "^15.6.1",
+    "react-redux": "^5.0.2",
+    "react-router": "^3.0.5"
   },
   "scripts": {
+    "styleguide": "styleguidist server",
+    "styleguide:build": "styleguidist build",
     "prebuild": "npm run clean && npm run lint",
     "lint": "eslint src",
     "clean": "rimraf dist",
-    "build": "NODE_ENV=production webpack --progress --profile"
+    "build": "NODE_ENV=production webpack --progress --profile --optimize-minimize"
   }
 }
diff --git a/packages/component-manuscript/src/components/Manuscript.md b/packages/component-manuscript/src/components/Manuscript.md
new file mode 100644
index 000000000..d53d74c8a
--- /dev/null
+++ b/packages/component-manuscript/src/components/Manuscript.md
@@ -0,0 +1,29 @@
+An editor for a manuscript.
+
+```js
+const project = {
+  
+};
+
+const version = {
+  progress: {},
+  source: '<div><h1>This is an example</h1></div>'
+};
+
+const currentUser = {
+  teams: [
+    {
+      teamType: {
+        name: 'Production Editor'
+      }
+    }
+  ]
+};
+
+<Manuscript 
+  project={project}
+  version={version}
+  currentUser={currentUser}
+  fileUpload={data => console.log(data)}
+  updateVersion={(project, version) => console.log(project, version)}/>
+```
diff --git a/packages/component-manuscript/styleguide.config.js b/packages/component-manuscript/styleguide.config.js
new file mode 100644
index 000000000..eed44210a
--- /dev/null
+++ b/packages/component-manuscript/styleguide.config.js
@@ -0,0 +1,22 @@
+module.exports = {
+  title: 'xpub dashboard style guide',
+  styleguideComponents: {
+    StyleGuideRenderer: require.resolve('xpub-styleguide/src/components/StyleGuideRenderer'),
+    Wrapper: require.resolve('xpub-styleguide/src/components/Wrapper')
+  },
+  context: {
+    faker: 'faker'
+  },
+  components: './src/components/*.js',
+  skipComponentsWithoutExample: true,
+  webpackConfig: require('./webpack.config.js'),
+  serverPort: 6063,
+  theme: {
+    fontFamily: {
+      base: '"Fira Sans", sans-serif'
+    },
+    color: {
+      link: 'cornflowerblue'
+    }
+  }
+}
diff --git a/packages/component-manuscript/webpack.config.js b/packages/component-manuscript/webpack.config.js
index 6efd1e71a..9e83b0e41 100644
--- a/packages/component-manuscript/webpack.config.js
+++ b/packages/component-manuscript/webpack.config.js
@@ -14,10 +14,11 @@ module.exports = {
     libraryTarget: 'commonjs2'
   },
   devtool: 'cheap-module-source-map',
-  externals: [nodeExternals({
-    whitelist: [/\.(?!js$).{1,5}$/i]
-  })],
+  // externals: [nodeExternals({
+  //   whitelist: [/\.(?!js$).{1,5}$/i]
+  // })],
   resolve: {
+    symlinks: false, // needed to prevent babel looking in other folders
     extensions: ['.js', '.jsx'], // needed because pubsweet-component-wax uses jsx
   },
   module: {
@@ -29,11 +30,12 @@ module.exports = {
             include: [
               path.join(__dirname, 'src'),
               /pubsweet-[^/]+\/src/,
+              /xpub-[^/]+\/src/,
             ],
             loader: 'babel-loader',
             options: {
               presets: [
-                'minify',
+                // 'minify',
                 ['env', { modules: false }],
                 'react',
                 'stage-2'
@@ -44,6 +46,11 @@ module.exports = {
           // CSS modules
           {
             test: /\.local\.css$/,
+            include: [
+              path.join(__dirname, 'src'),
+              /pubsweet-[^/]+\/src/,
+              /xpub-[^/]+\/src/,
+            ],
             use: [
               'style-loader',
               {
diff --git a/packages/xpub-ui/webpack.config.js b/packages/xpub-ui/webpack.config.js
index 842d4ee1c..cac709214 100644
--- a/packages/xpub-ui/webpack.config.js
+++ b/packages/xpub-ui/webpack.config.js
@@ -8,9 +8,7 @@ module.exports = {
   entry: './src/index.js',
   output: {
     filename: 'index.js',
-    path: path.join(__dirname, 'dist'),
-    library: 'xpub-ui',
-    libraryTarget: 'commonjs2'
+    path: path.join(__dirname, 'dist')
   },
   devtool: 'cheap-module-source-map',
   externals: [nodeExternals({
-- 
GitLab