This commit is contained in:
Evan Scott
2018-09-30 16:56:22 -05:00
parent 48144f3eb2
commit bef754dc27
12 changed files with 69 additions and 95 deletions

View File

@@ -1,2 +1,4 @@
*.json *.json
*.yml *.yml
dist
flow-typed

View File

@@ -1,6 +1,9 @@
{ {
"arrowParens": "avoid",
"printWidth": 100,
"jsxBracketSameLine": false,
"semi": true, "semi": true,
"singleQuote": true, "singleQuote": true,
"trailingComma": "es5", "tabWidth": 2,
"printWidth": 100 "trailingComma": "es5"
} }

View File

@@ -1,27 +0,0 @@
version: "{build}"
branches:
only:
- master
skip_tags: true
build: off
clone_depth: 1
shallow_clone: true
matrix:
fast_finish: true
environment:
matrix:
- nodejs_version: 8
init:
- git config --global core.autocrlf input
install:
- ps: 'Install-Product node $env:nodejs_version x64'
- set CI=true
- yarn
cache:
- '%LOCALAPPDATA%/Yarn'
test_script:
- node --version
- yarn --version
- yarn build
- yarn flow
- yarn test

View File

@@ -6,7 +6,7 @@ const tracing = process.argv.some(arg => arg.indexOf('tracing') > -1);
if (tracing) { if (tracing) {
console.log( console.log(
'\nTracing enabled. (note that this might impact benchmark results, we recommend leaving this turned off unless you need a trace)' '\nTracing enabled. (note that this might impact benchmark results, we recommend leaving this turned off unless you need a trace)',
); );
} }
@@ -18,7 +18,7 @@ if (tracing) {
await page.goto(`file://${path.join(__dirname, './dist/index.html')}`); await page.goto(`file://${path.join(__dirname, './dist/index.html')}`);
console.log( console.log(
'Running benchmarks... (this may take a minute or two; do not use your machine while these are running!)' 'Running benchmarks... (this may take a minute or two; do not use your machine while these are running!)',
); );
for (var i = 0; i < tests.length; i++) { for (var i = 0; i < tests.length; i++) {
const test = tests[i]; const test = tests[i];

View File

@@ -8,13 +8,13 @@ type ComponentsType = {
Box: Component, Box: Component,
Dot: Component, Dot: Component,
Provider: Component, Provider: Component,
View: Component View: Component,
}; };
type ImplementationType = { type ImplementationType = {
components: ComponentsType, components: ComponentsType,
name: string, name: string,
version: string version: string,
}; };
const toImplementations = (context: Object): Array<ImplementationType> => const toImplementations = (context: Object): Array<ImplementationType> =>

View File

@@ -21,7 +21,7 @@ const createTestBlock = fn => {
Provider, Provider,
benchmarkType, benchmarkType,
version, version,
name name,
}; };
return testSetups; return testSetups;
}, {}); }, {});
@@ -33,14 +33,14 @@ const tests = {
Component: Tree, Component: Tree,
getComponentProps: () => ({ breadth: 2, components, depth: 7, id: 0, wrap: 1 }), getComponentProps: () => ({ breadth: 2, components, depth: 7, id: 0, wrap: 1 }),
Provider: components.Provider, Provider: components.Provider,
sampleCount: 500 sampleCount: 500,
})), })),
'Mount wide tree': createTestBlock(components => ({ 'Mount wide tree': createTestBlock(components => ({
benchmarkType: 'mount', benchmarkType: 'mount',
Component: Tree, Component: Tree,
getComponentProps: () => ({ breadth: 6, components, depth: 3, id: 0, wrap: 2 }), getComponentProps: () => ({ breadth: 6, components, depth: 3, id: 0, wrap: 2 }),
Provider: components.Provider, Provider: components.Provider,
sampleCount: 500 sampleCount: 500,
})), })),
'Update dynamic styles': createTestBlock(components => ({ 'Update dynamic styles': createTestBlock(components => ({
benchmarkType: 'update', benchmarkType: 'update',
@@ -49,8 +49,8 @@ const tests = {
return { components, s: 200, renderCount: cycle, x: 0, y: 0 }; return { components, s: 200, renderCount: cycle, x: 0, y: 0 };
}, },
Provider: components.Provider, Provider: components.Provider,
sampleCount: 1000 sampleCount: 1000,
})) })),
}; };
ReactDOM.render(<App tests={tests} />, document.querySelector('.root')); ReactDOM.render(<App tests={tests} />, document.querySelector('.root'));

View File

@@ -1,9 +1,9 @@
// @flow // @flow
const webpack = require('webpack') const webpack = require('webpack');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer') const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const path = require('path') const path = require('path');
const appDirectory = path.resolve(__dirname) const appDirectory = path.resolve(__dirname);
module.exports = { module.exports = {
mode: 'production', mode: 'production',
@@ -51,4 +51,4 @@ module.exports = {
'styled-components': path.resolve('../src'), 'styled-components': path.resolve('../src'),
}, },
}, },
} };

View File

@@ -1,56 +1,54 @@
const path = require('path') const path = require('path');
const exec = require('child_process').exec const exec = require('child_process').exec;
const Express = require('express') const Express = require('express');
const watch = require('node-watch') const watch = require('node-watch');
import fs from 'fs' import fs from 'fs';
import React from 'react' import React from 'react';
import { renderToString } from 'react-dom/server' import { renderToString } from 'react-dom/server';
import { ServerStyleSheet } from '..' import { ServerStyleSheet } from '..';
import getExample from './example' import getExample from './example';
const HTML = fs.readFileSync(__dirname + '/index.html').toString() const HTML = fs.readFileSync(__dirname + '/index.html').toString();
const srcPath = __dirname.split('/example')[0] + '/src' const srcPath = __dirname.split('/example')[0] + '/src';
const hotBuild = () => const hotBuild = () =>
exec('npm run build:dist', (err, stdout, stderr) => { exec('npm run build:dist', (err, stdout, stderr) => {
if (err) throw err if (err) throw err;
if (stdout) { if (stdout) {
console.log(`npm run build:dist --- ${stdout}`) console.log(`npm run build:dist --- ${stdout}`);
} }
if (stderr) { if (stderr) {
console.log(`npm run build:dist --- ${stderr}`) console.log(`npm run build:dist --- ${stderr}`);
} }
}) });
watch(srcPath, filename => { watch(srcPath, filename => {
console.log(`${filename} file has changed`) console.log(`${filename} file has changed`);
hotBuild() hotBuild();
}) });
const app = new Express() const app = new Express();
app.use(Express.static(__dirname)) app.use(Express.static(__dirname));
app.use(Express.static('dist')) app.use(Express.static('dist'));
app.get('/with-perf.html', (req, res) => { app.get('/with-perf.html', (req, res) => {
res.sendFile(path.join(__dirname, 'with-perf.html')) res.sendFile(path.join(__dirname, 'with-perf.html'));
}) });
app.get('/ssr.html', (req, res) => { app.get('/ssr.html', (req, res) => {
const Example = getExample() const Example = getExample();
const sheet = new ServerStyleSheet() const sheet = new ServerStyleSheet();
const html = renderToString(sheet.collectStyles(<Example />)) const html = renderToString(sheet.collectStyles(<Example />));
const css = sheet.getStyleTags() const css = sheet.getStyleTags();
res.send( res.send(HTML.replace(/<!-- SSR:HTML -->/, html).replace(/<!-- SSR:CSS -->/, css));
HTML.replace(/<!-- SSR:HTML -->/, html).replace(/<!-- SSR:CSS -->/, css) });
)
})
app.get('/', (req, res) => { app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html')) res.sendFile(path.join(__dirname, 'index.html'));
}) });
export default app export default app;

View File

@@ -1,12 +1,12 @@
import React from 'react' import React from 'react';
import styled, { createGlobalStyle, keyframes } from '..' import styled, { createGlobalStyle, keyframes } from '..';
export default () => { export default () => {
const GlobalStyle = createGlobalStyle` const GlobalStyle = createGlobalStyle`
body { body {
font-family: sans-serif; font-family: sans-serif;
} }
` `;
// Create a <Title> react component that renders an <h1> which is // Create a <Title> react component that renders an <h1> which is
// centered, palevioletred and sized at 1.5em // centered, palevioletred and sized at 1.5em
@@ -15,14 +15,14 @@ export default () => {
text-align: center; text-align: center;
color: palevioletred; color: palevioletred;
animation: ${keyframes`from { opacity: 0; }`} 1s both; animation: ${keyframes`from { opacity: 0; }`} 1s both;
` `;
// Create a <Wrapper> react component that renders a <section> with // Create a <Wrapper> react component that renders a <section> with
// some padding and a papayawhip background // some padding and a papayawhip background
const Wrapper = styled.section` const Wrapper = styled.section`
padding: 4em; padding: 4em;
background: papayawhip; background: papayawhip;
` `;
return class Example extends React.Component { return class Example extends React.Component {
render() { render() {
@@ -31,7 +31,7 @@ export default () => {
<GlobalStyle /> <GlobalStyle />
<Title>Hello World, this is my first styled component!</Title> <Title>Hello World, this is my first styled component!</Title>
</Wrapper> </Wrapper>
) );
}
}
} }
};
};

View File

@@ -1,17 +1,13 @@
import app from './devServer' import app from './devServer';
const port = 3000 const port = 3000;
app.listen(port, error => { app.listen(port, error => {
/* eslint-disable no-console */ /* eslint-disable no-console */
if (error) { if (error) {
console.error(error) console.error(error);
} else { } else {
console.info( console.info('🌎 Listening on port %s. Open up http://localhost:%s/ in your browser.', port, port);
'🌎 Listening on port %s. Open up http://localhost:%s/ in your browser.',
port,
port
)
} }
/* eslint-enable no-console */ /* eslint-enable no-console */
}) });

View File

@@ -27,6 +27,7 @@
"flow:watch": "flow-watch", "flow:watch": "flow-watch",
"format": "eslint ./**/*.js --fix", "format": "eslint ./**/*.js --fix",
"lint": "eslint src", "lint": "eslint src",
"prettier": "prettier */**/*.js --write",
"prepublishOnly": "run-s build", "prepublishOnly": "run-s build",
"lint-staged": "lint-staged", "lint-staged": "lint-staged",
"dev": "cross-env BABEL_ENV=cjs babel-node example/startServer.js", "dev": "cross-env BABEL_ENV=cjs babel-node example/startServer.js",

View File

@@ -2,6 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/* Adapted from nodemon's postinstall: https://github.com/remy/nodemon/blob/master/package.json */ /* Adapted from nodemon's postinstall: https://github.com/remy/nodemon/blob/master/package.json */
var msg = 'Use styled-components at work? Consider supporting our development efforts at opencollective.com/styled-components'; var msg =
'Use styled-components at work? Consider supporting our development efforts at opencollective.com/styled-components';
console.log(msg); console.log(msg);