From 47424c2687d749dbcde98411dc1ea75d4527514e Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Fri, 29 Jan 2016 17:48:36 -0800 Subject: [PATCH 1/8] Clean up config and allow dashboard to be run via script --- PIG.config.js | 8 ++----- base.config.js | 40 ++++++++++++++++++++++++++++++++ dashboard.config.js | 14 +++--------- production.config.js | 3 +-- webpack.config.js | 54 ++++++++------------------------------------ 5 files changed, 55 insertions(+), 64 deletions(-) create mode 100644 base.config.js diff --git a/PIG.config.js b/PIG.config.js index 5a40aed4df..4e1dfef31f 100644 --- a/PIG.config.js +++ b/PIG.config.js @@ -1,10 +1,6 @@ -// Import the main configuration file var configuration = require('./webpack.config.js'); -// Remove the dashboard configuration, we're only building the PIG -delete configuration.entry.dashboard; - -// Remove SVG plugin -configuration.plugins = []; +configuration.entry = './dashboard/index.js'; +configuration.output.path = './PIG/bundles'; module.exports = configuration; diff --git a/base.config.js b/base.config.js new file mode 100644 index 0000000000..4590e88156 --- /dev/null +++ b/base.config.js @@ -0,0 +1,40 @@ +//This file should be imported by another config file, like dashboard.config.js + +var path = require('path'); +var SvgPrepPlugin = require('./plugins/svg-prep'); + +module.exports = { + output: { + filename: '[name].bundle.js' + }, + resolve: { + root: [__dirname, path.join(__dirname, 'node_modules')] + }, + resolveLoader: { + root: path.join(__dirname, 'node_modules') + }, + module: { + loaders: [ + { + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel-loader', + query: { + optional: ['runtime', 'es7.decorators'] + } + }, { + test: /\.scss$/, + loader: "style-loader!css-loader?modules&localIdentName=[local]__[hash:base64:5]!sass-loader?includePaths[]=" + + encodeURIComponent(path.resolve(__dirname, "../../app/webpack")) + }, { + test: /\.css$/, + loader: 'style-loader!css-loader' + } + ] + }, + plugins: [ + new SvgPrepPlugin({ + source: path.join(__dirname, 'icons') + }) + ] +}; diff --git a/dashboard.config.js b/dashboard.config.js index 86b7150810..ba529507e2 100644 --- a/dashboard.config.js +++ b/dashboard.config.js @@ -1,14 +1,6 @@ -var path = require('path'); +var configuration = require('./base.config.js'); -// Import the main configuration file -var configuration = require('./webpack.config.js'); - -// Remove the dashboard configuration, we're only building the PIG -delete configuration.entry.PIG; - -configuration.output.path = path.join(__dirname, 'Parse-Dashboard', 'bundles'); - -// Remove SVG plugin -configuration.plugins = []; +configuration.entry = './dashboard/index.js'; +configuration.output.path = './Parse-Dashboard/bundles'; module.exports = configuration; diff --git a/production.config.js b/production.config.js index ef57e72887..f4c77be1ce 100644 --- a/production.config.js +++ b/production.config.js @@ -1,9 +1,8 @@ // Production build configuration for dashboard.parse.com - var webpack = require('webpack'); // Import the main configuration file -var configuration = require('./webpack.config.js'); +var configuration = require('./base.config.js'); // Remove the PIG configuration, we're only building the dashboard delete configuration.entry.PIG; diff --git a/webpack.config.js b/webpack.config.js index 242c592760..5f91e065c5 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,48 +1,12 @@ -var path = require('path'); -var SvgPrepPlugin = require('./plugins/svg-prep'); +var configuration = require('./base.config.js'); -var entries = { - dashboard: path.join(__dirname, 'dashboard', 'index.js'), - login: path.join(__dirname, 'login', 'index.js'), - signup: path.join(__dirname, 'signup', 'index.js'), - PIG: path.join(__dirname, 'parse-interface-guide', 'index.js'), - quickstart: path.join(__dirname, 'quickstart', 'index.js') +configuration.entry = { + dashboard: './dashboard/index.js'), + login: './login/index.js' + signup: './signup/index.js' + PIG: './parse-interface-guide/index.js' + quickstart: './quickstart/index.js }; +configuration.output.path = './bundles'; -module.exports = { - entry: entries, - output: { - path: path.join(__dirname, 'PIG', 'bundles'), - filename: '[name].bundle.js' - }, - resolve: { - root: [__dirname, path.join(__dirname, 'node_modules')] - }, - resolveLoader: { - root: path.join(__dirname, 'node_modules') - }, - module: { - loaders: [ - { - test: /\.js$/, - exclude: /node_modules/, - loader: 'babel-loader', - query: { - optional: ['runtime', 'es7.decorators'] - } - }, { - test: /\.scss$/, - loader: "style-loader!css-loader?modules&localIdentName=[local]__[hash:base64:5]!sass-loader?includePaths[]=" + - encodeURIComponent(path.resolve(__dirname, "../../app/webpack")) - }, { - test: /\.css$/, - loader: 'style-loader!css-loader' - } - ] - }, - plugins: [ - new SvgPrepPlugin({ - source: path.join(__dirname, 'icons') - }) - ] -}; +module.exports = configuration; From bc1ecfb88c59a6ac1d66e6e6b2f61d842b9780af Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Fri, 29 Jan 2016 18:19:08 -0800 Subject: [PATCH 2/8] Make sure all the configs build --- .gitignore | 2 +- PIG.config.js | 2 +- production.config.js | 16 ++++++++++------ webpack.config.js | 10 +++++----- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 865cf5f1d1..9053d58bf4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .DS_Store node_modules/ -public/ +bundles/ PIG/bundles/ Parse-Dashboard/bundles/ diff --git a/PIG.config.js b/PIG.config.js index 4e1dfef31f..63771d54bb 100644 --- a/PIG.config.js +++ b/PIG.config.js @@ -1,4 +1,4 @@ -var configuration = require('./webpack.config.js'); +var configuration = require('./base.config.js'); configuration.entry = './dashboard/index.js'; configuration.output.path = './PIG/bundles'; diff --git a/production.config.js b/production.config.js index f4c77be1ce..069dd1d0cc 100644 --- a/production.config.js +++ b/production.config.js @@ -1,11 +1,15 @@ -// Production build configuration for dashboard.parse.com -var webpack = require('webpack'); - -// Import the main configuration file var configuration = require('./base.config.js'); -// Remove the PIG configuration, we're only building the dashboard -delete configuration.entry.PIG; +configuration.entry = { + dashboard: './dashboard/index.js', + login: './login/index.js', + signup: './signup/index.js', + PIG: './parse-interface-guide/index.js', + quickstart: './quickstart/index.js', +}; +configuration.output.path = './production/bundles'; + +var webpack = require('webpack'); // Add propType removal to Babel var loaders = configuration.module.loaders; diff --git a/webpack.config.js b/webpack.config.js index 5f91e065c5..bfa433fe9c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,11 +1,11 @@ var configuration = require('./base.config.js'); configuration.entry = { - dashboard: './dashboard/index.js'), - login: './login/index.js' - signup: './signup/index.js' - PIG: './parse-interface-guide/index.js' - quickstart: './quickstart/index.js + dashboard: './dashboard/index.js', + login: './login/index.js', + signup: './signup/index.js', + PIG: './parse-interface-guide/index.js', + quickstart: './quickstart/index.js', }; configuration.output.path = './bundles'; From 3aa2ff915fac89f8c8a4c7f40cb18ac1527d2c1e Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Fri, 29 Jan 2016 23:44:09 -0800 Subject: [PATCH 3/8] Able to run tests in /lib --- package.json | 8 ++------ testing/preprocessor.js | 9 +++------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 2d90580f05..1ec8f8053e 100644 --- a/package.json +++ b/package.json @@ -38,16 +38,12 @@ "generate": "node scripts/generate.js" }, "jest": { - "rootDir": "../../app/webpack", "testPathDirs": [ "components", "lib" ], - "testPathIgnorePatterns": [ - "/node_modules/" - ], - "scriptPreprocessor": "/../../script/webpack/testing/preprocessor.js", - "testDirectoryName": "webpack", + "scriptPreprocessor": "/testing/preprocessor.js", + "testDirectoryName": "tests", "testFileExtensions": [ "test.js" ], diff --git a/testing/preprocessor.js b/testing/preprocessor.js index 2c915a7547..adf7d399c6 100644 --- a/testing/preprocessor.js +++ b/testing/preprocessor.js @@ -1,8 +1,5 @@ var babel = require('babel-core'); var extractClassnames = require('./extractClassnames'); -var path = require('path'); - -var rootDir = path.join(process.cwd(), '..', '..', 'app', 'webpack'); module.exports = { process: function (src, filename) { @@ -12,9 +9,9 @@ module.exports = { } // Let Jest handle our custom module resolution - src = src.replace(/from \'stylesheets/g, "from '" + path.join(rootDir, 'stylesheets')); - src = src.replace(/from \'lib/g, "from '" + path.join(rootDir, 'lib')); - src = src.replace(/from \'components/g, "from '" + path.join(rootDir, 'components')); + src = src.replace(/from \'stylesheets/g, "from './stylesheets"); + src = src.replace(/from \'lib/g, "from './lib"); + src = src.replace(/from \'components/g, "from './components"); // Ignore all files within node_modules // babel files can be .js, .es, .jsx or .es6 From 5c999a4932aed3c32a53c872efab7027208e807c Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Sat, 30 Jan 2016 12:58:41 -0800 Subject: [PATCH 4/8] Make npm run generate work --- PIG.config.js | 2 +- dashboard.config.js | 2 +- package.json | 1 - parse-interface-guide/ComponentsMap.js | 2 +- scripts/generate.js | 26 +++++++++++++------------- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/PIG.config.js b/PIG.config.js index 63771d54bb..a2f0e12764 100644 --- a/PIG.config.js +++ b/PIG.config.js @@ -1,6 +1,6 @@ var configuration = require('./base.config.js'); -configuration.entry = './dashboard/index.js'; +configuration.entry = {PIG: './parse-interface-guide/index.js'}; configuration.output.path = './PIG/bundles'; module.exports = configuration; diff --git a/dashboard.config.js b/dashboard.config.js index ba529507e2..5cdc3f99ed 100644 --- a/dashboard.config.js +++ b/dashboard.config.js @@ -1,6 +1,6 @@ var configuration = require('./base.config.js'); -configuration.entry = './dashboard/index.js'; +configuration.entry = {dashboard: './dashboard/index.js'}; configuration.output.path = './Parse-Dashboard/bundles'; module.exports = configuration; diff --git a/package.json b/package.json index 1ec8f8053e..892a7b4621 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ }, "jest": { "testPathDirs": [ - "components", "lib" ], "scriptPreprocessor": "/testing/preprocessor.js", diff --git a/parse-interface-guide/ComponentsMap.js b/parse-interface-guide/ComponentsMap.js index dfb0cff77d..1582077e47 100644 --- a/parse-interface-guide/ComponentsMap.js +++ b/parse-interface-guide/ComponentsMap.js @@ -61,4 +61,4 @@ export let SliderWrap = require('components/SliderWrap/SliderWrap export let StatusIndicator = require('components/StatusIndicator/StatusIndicator.example'); export let TextInput = require('components/TextInput/TextInput.example'); export let Toggle = require('components/Toggle/Toggle.example'); -export let Tooltip = require('components/Tooltip/Tooltip.example'); \ No newline at end of file +export let Tooltip = require('components/Tooltip/Tooltip.example'); diff --git a/scripts/generate.js b/scripts/generate.js index 35b03d8fbc..1a02a28c36 100755 --- a/scripts/generate.js +++ b/scripts/generate.js @@ -5,8 +5,8 @@ const fs = require('fs'); const path = require('path'); -const rootDir = path.join(__dirname, '..', '..', '..', 'app', 'webpack', 'components'); -const pigDir = path.join(__dirname, '..', '..', '..', 'app', 'webpack', 'PIG'); +const rootDir = path.join(__dirname, '..', 'components'); +const pigDir = path.join(__dirname, '..', 'parse-interface-guide'); function padding(length) { let space = []; @@ -18,17 +18,16 @@ function padding(length) { function generateReact(name) { return ( -`import React from 'react'; -import styles from 'components/${name}/${name}.scss'; - -export default class ${name} extends React.Component { - constructor() { - super(); - } +`import PropTypes from 'lib/PropTypes'; +import React from 'react'; +import styles from 'components/${name}/${name}.scss'; - render() { +let ${name} = ({prop1}) => { + return
; +} - } +${name}.propTypes = { + prop1: PropTypes.string.isRequired.describe('Replace me with the actual props'), } `); } @@ -36,7 +35,7 @@ export default class ${name} extends React.Component { function generateExample(name) { return ( `import React${padding(name.length - 5)} from 'react'; -import ${name}${padding(5 - name.length)} from 'components/${name}/${name}.react'; +import ${name}${padding(5 - name.length)} f`+ 'rom' +` 'components/${name}/${name}.react'; export const component = ${name}; @@ -74,6 +73,7 @@ describe('${name}', () => { `); } + function updateComponentMap(name) { let numSpace = 1; if (name.length < 26) { @@ -86,7 +86,7 @@ function updateComponentMap(name) { } return ( -`export let ${name}${spaces}= require('components/${name}/${name}.example');` +`export let ${name}${spaces}= require('components/${name}/${name}.example');\n` ); } From a43081b91022a7e2de0d9812e7f5a8be320924f0 Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Sat, 30 Jan 2016 14:47:31 -0800 Subject: [PATCH 5/8] Component tests and npm run generate now work --- components/PlatformCard/PlatformCard.test.js | 17 --------- .../Button => lib/tests}/Button.test.js | 36 +++++++++---------- .../Markdown => lib/tests}/Markdown.test.js | 8 ++--- lib/tests/PlatformCard.test.js | 17 +++++++++ .../Tooltip => lib/tests}/Tooltip.test.js | 4 +-- scripts/generate.js | 11 +++--- testing/preprocessor.js | 6 ++-- 7 files changed, 50 insertions(+), 49 deletions(-) delete mode 100644 components/PlatformCard/PlatformCard.test.js rename {components/Button => lib/tests}/Button.test.js (68%) rename {components/Markdown => lib/tests}/Markdown.test.js (52%) create mode 100644 lib/tests/PlatformCard.test.js rename {components/Tooltip => lib/tests}/Tooltip.test.js (58%) diff --git a/components/PlatformCard/PlatformCard.test.js b/components/PlatformCard/PlatformCard.test.js deleted file mode 100644 index 31eac826fb..0000000000 --- a/components/PlatformCard/PlatformCard.test.js +++ /dev/null @@ -1,17 +0,0 @@ -jest.dontMock('./PlatformCard.react'); - -import React from 'react'; -import ReactDOM from 'react-dom'; -import TestUtils from 'react-addons-test-utils'; - -const PlatformCard = require('./PlatformCard.react'); - -describe('PlatformCard', () => { - it('can render examples', () => { - jest.dontMock('./PlatformCard.example'); - const example = require('./PlatformCard.example'); - example.demos.forEach((example, i) => { - example.render(); - }); - }); -}); diff --git a/components/Button/Button.test.js b/lib/tests/Button.test.js similarity index 68% rename from components/Button/Button.test.js rename to lib/tests/Button.test.js index 41daca013d..876a426bd3 100644 --- a/components/Button/Button.test.js +++ b/lib/tests/Button.test.js @@ -1,16 +1,16 @@ -jest.dontMock('./Button.react'); +jest.dontMock('../../components/Button/Button.react'); import React from 'react'; import ReactDOM from 'react-dom'; import TestUtils from 'react-addons-test-utils'; -const Button = require('./Button.react'); +var Button = require('../../components/Button/Button.react'); describe('Button', () => { it('has a default state', () => { - const shallowRenderer = TestUtils.createRenderer(); + var shallowRenderer = TestUtils.createRenderer(); shallowRenderer.render(