Skip to content

Commit fb98712

Browse files
author
Ives van Hoorne
committed
Homepage
1 parent 796037b commit fb98712

File tree

14 files changed

+1114
-81
lines changed

14 files changed

+1114
-81
lines changed

Gulpfile.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const gulp = require('gulp');
2+
const postcss = require('gulp-postcss');
3+
const autoprefixer = require('autoprefixer');
4+
const cssnano = require('cssnano');
5+
6+
const config = require('./config/paths');
7+
8+
gulp.task('css', function() {
9+
return gulp
10+
.src('src/homepage/**/*.css')
11+
.pipe(postcss([autoprefixer, cssnano]))
12+
.pipe(gulp.dest(`${config.appBuild}/`));
13+
});
14+
15+
gulp.task('javascript', function() {
16+
return gulp
17+
.src('src/homepage/**/*.js')
18+
.pipe(gulp.dest(`${config.appBuild}/`));
19+
});
20+
21+
gulp.task('html', function() {
22+
return gulp
23+
.src('src/homepage/**/*.html')
24+
.pipe(gulp.dest(`${config.appBuild}/`));
25+
});
26+
27+
gulp.task('static', function() {
28+
return gulp
29+
.src(`${config.staticPath}/**/*`)
30+
.pipe(gulp.dest(`${config.appBuild}/`));
31+
});
32+
33+
gulp.task('default', ['css', 'html', 'javascript', 'static']);

config/paths.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = {
3030
appHtml: path.join(appSrc, 'index.html'),
3131
sandboxHtml: path.join(sandboxSrc, 'index.html'),
3232
appPackageJson: resolveApp('package.json'),
33+
staticPath: resolveApp('public'),
3334
src,
3435
appSrc,
3536
sandboxSrc,

config/webpack.config.js

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,21 @@ const __PROD__ = NODE_ENV === 'production'; // eslint-disable-line no-underscore
1515

1616
const babelConfig = __DEV__ ? babelDev : babelProd;
1717

18-
const getOutput = () =>
19-
__DEV__
20-
? {
21-
path: paths.appBuild,
22-
pathinfo: true,
23-
filename: 'static/js/[name].js',
24-
publicPath: '/',
25-
}
26-
: {
27-
path: paths.appBuild,
28-
pathinfo: true,
29-
filename: 'static/js/[name].[hash:8].js',
30-
chunkFilename: 'static/js/[name].[hash:8].chunk.js',
31-
sourceMapFilename: '[file].map', // Default
32-
publicPath: 'https://codesandbox.io/',
33-
};
18+
const getOutput = () => __DEV__
19+
? {
20+
path: paths.appBuild,
21+
pathinfo: true,
22+
filename: 'static/js/[name].js',
23+
publicPath: '/',
24+
}
25+
: {
26+
path: paths.appBuild,
27+
pathinfo: true,
28+
filename: 'static/js/[name].[hash:8].js',
29+
chunkFilename: 'static/js/[name].[hash:8].chunk.js',
30+
sourceMapFilename: '[file].map', // Default
31+
publicPath: 'https://codesandbox.io/',
32+
};
3433

3534
const config = {
3635
devtool: __DEV__ ? 'eval' : 'source-map',
@@ -41,13 +40,7 @@ const config = {
4140
require.resolve('./polyfills'),
4241
path.join(paths.sandboxSrc, 'index.js'),
4342
],
44-
vendor: [
45-
'babel-standalone',
46-
'codemirror',
47-
'react',
48-
'styled-components',
49-
'glamor',
50-
],
43+
vendor: ['babel-standalone', 'codemirror', 'react', 'styled-components'],
5144
},
5245

5346
target: 'web',
@@ -157,7 +150,7 @@ const config = {
157150
new HtmlWebpackPlugin({
158151
inject: true,
159152
chunks: ['vendor', 'common', 'app'],
160-
filename: 'index.html',
153+
filename: 'app.html',
161154
template: paths.appHtml,
162155
minify: __PROD__ && {
163156
removeComments: true,

deploy.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ mkdir .deliver && \
77
mkdir .deliver/www && \
88
docker cp $id:/app/www/ ./.deliver/ && \
99
docker rm -v $id && \
10-
echo "Copy static files" && \
11-
cp -R static/ .deliver/www/ && \
1210
echo "Tarring build files" && \
1311
tar -C .deliver -zcvf .deliver/code_sandbox_client.tar.gz www && \
1412
echo "Cleaning remote tar" && \

favicon.ico

31.3 KB
Binary file not shown.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"devDependencies": {
6-
"autoprefixer": "^6.6.0",
6+
"autoprefixer": "^6.7.7",
77
"babel-core": "^6.21.0",
88
"babel-eslint": "^7.1.1",
99
"babel-jest": "^19.0.0",
@@ -67,8 +67,11 @@
6767
"babel-standalone": "^6.21.1-0",
6868
"codemirror": "^5.22.0",
6969
"color": "^0.11.4",
70+
"cssnano": "^3.10.0",
7071
"debug": "^2.5.1",
7172
"glamor": "^2.20.12",
73+
"gulp": "^3.9.1",
74+
"gulp-postcss": "^6.4.0",
7275
"humps": "CompuIves/humps",
7376
"lodash": "^4.17.2",
7477
"moment": "^2.17.1",
@@ -98,7 +101,7 @@
98101
},
99102
"scripts": {
100103
"start": "node scripts/start.js",
101-
"build": "node scripts/build.js",
104+
"build": "node scripts/build.js && gulp",
102105
"test": "jest --env=jsdom",
103106
"test:watch": "jest --watch --env=jsdom",
104107
"lint": "eslint src"

public/favicon.ico

31.3 KB
Binary file not shown.
File renamed without changes.

scripts/start.js

Lines changed: 70 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function setupCompiler(port, protocol) {
6767

6868
// "done" event fires when Webpack has finished recompiling the bundle.
6969
// Whether or not you have warnings or errors, you will get this event.
70-
compiler.plugin('done', (stats) => {
70+
compiler.plugin('done', stats => {
7171
clearConsole();
7272
const hasErrors = stats.hasErrors();
7373
const hasWarnings = stats.hasWarnings();
@@ -79,7 +79,9 @@ function setupCompiler(port, protocol) {
7979
console.log(' ' + chalk.cyan(protocol + '://localhost:' + port + '/'));
8080
console.log();
8181
console.log('Note that the development build is not optimized.');
82-
console.log('To create a production build, use ' + chalk.cyan('npm run build') + '.');
82+
console.log(
83+
'To create a production build, use ' + chalk.cyan('npm run build') + '.'
84+
);
8385
console.log();
8486
return;
8587
}
@@ -90,11 +92,11 @@ function setupCompiler(port, protocol) {
9092
// We use stats.toJson({}, true) to make output more compact and readable:
9193
// https://github.com/facebookincubator/create-react-app/issues/401#issuecomment-238291901
9294
var json = stats.toJson({}, true);
93-
var formattedErrors = json.errors.map(message =>
94-
'Error in ' + formatMessage(message)
95+
var formattedErrors = json.errors.map(
96+
message => 'Error in ' + formatMessage(message)
9597
);
96-
var formattedWarnings = json.warnings.map(message =>
97-
'Warning in ' + formatMessage(message)
98+
var formattedWarnings = json.warnings.map(
99+
message => 'Warning in ' + formatMessage(message)
98100
);
99101
if (hasErrors) {
100102
console.log(chalk.red('Failed to compile.'));
@@ -121,8 +123,16 @@ function setupCompiler(port, protocol) {
121123
});
122124
// Teach some ESLint tricks.
123125
console.log('You may use special comments to disable some warnings.');
124-
console.log('Use ' + chalk.yellow('// eslint-disable-next-line') + ' to ignore the next line.');
125-
console.log('Use ' + chalk.yellow('/* eslint-disable */') + ' to ignore all warnings in a file.');
126+
console.log(
127+
'Use ' +
128+
chalk.yellow('// eslint-disable-next-line') +
129+
' to ignore the next line.'
130+
);
131+
console.log(
132+
'Use ' +
133+
chalk.yellow('/* eslint-disable */') +
134+
' to ignore all warnings in a file.'
135+
);
126136
}
127137
});
128138
}
@@ -134,8 +144,12 @@ function openBrowser(port, protocol) {
134144
// on OS X Google Chrome with AppleScript
135145
execSync('ps cax | grep "Google Chrome"');
136146
execSync(
137-
'osascript chrome.applescript ' + protocol + '://localhost:' + port + '/',
138-
{cwd: path.join(__dirname, 'utils'), stdio: 'ignore'}
147+
'osascript chrome.applescript ' +
148+
protocol +
149+
'://localhost:' +
150+
port +
151+
'/',
152+
{ cwd: path.join(__dirname, 'utils'), stdio: 'ignore' }
139153
);
140154
return;
141155
} catch (err) {
@@ -150,43 +164,59 @@ function openBrowser(port, protocol) {
150164
// We need to provide a custom onError function for httpProxyMiddleware.
151165
// It allows us to log custom error messages on the console.
152166
function onProxyError(proxy) {
153-
return function(err, req, res){
167+
return function(err, req, res) {
154168
var host = req.headers && req.headers.host;
155169
console.log(
156-
chalk.red('Proxy error:') + ' Could not proxy request ' + chalk.cyan(req.url) +
157-
' from ' + chalk.cyan(host) + ' to ' + chalk.cyan(proxy) + '.'
170+
chalk.red('Proxy error:') +
171+
' Could not proxy request ' +
172+
chalk.cyan(req.url) +
173+
' from ' +
174+
chalk.cyan(host) +
175+
' to ' +
176+
chalk.cyan(proxy) +
177+
'.'
158178
);
159179
console.log(
160180
'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
161-
chalk.cyan(err.code) + ').'
181+
chalk.cyan(err.code) +
182+
').'
162183
);
163184
console.log();
164-
}
185+
};
165186
}
166187

167188
function addMiddleware(devServer) {
168189
// `proxy` lets you to specify a fallback server during development.
169190
// Every unrecognized request will be forwarded to it.
170191
var proxy = require(paths.appPackageJson).proxy;
171-
devServer.use(historyApiFallback({
172-
// Allow paths with dots in them to be loaded, reference issue #387
173-
disableDotRule: true,
174-
// For single page apps, we generally want to fallback to /index.html.
175-
// However we also want to respect `proxy` for API calls.
176-
// So if `proxy` is specified, we need to decide which fallback to use.
177-
// We use a heuristic: if request `accept`s text/html, we pick /index.html.
178-
// Modern browsers include text/html into `accept` header when navigating.
179-
// However API calls like `fetch()` won’t generally won’t accept text/html.
180-
// If this heuristic doesn’t work well for you, don’t use `proxy`.
181-
htmlAcceptHeaders: proxy ?
182-
['text/html'] :
183-
['text/html', '*/*']
184-
}));
192+
devServer.use(
193+
historyApiFallback({
194+
// Allow paths with dots in them to be loaded, reference issue #387
195+
disableDotRule: true,
196+
// For single page apps, we generally want to fallback to /index.html.
197+
// However we also want to respect `proxy` for API calls.
198+
// So if `proxy` is specified, we need to decide which fallback to use.
199+
// We use a heuristic: if request `accept`s text/html, we pick /index.html.
200+
// Modern browsers include text/html into `accept` header when navigating.
201+
// However API calls like `fetch()` won’t generally won’t accept text/html.
202+
// If this heuristic doesn’t work well for you, don’t use `proxy`.
203+
htmlAcceptHeaders: proxy ? ['text/html'] : ['text/html', '*/*'],
204+
index: '/app.html',
205+
})
206+
);
185207
if (proxy) {
186208
if (typeof proxy !== 'string') {
187-
console.log(chalk.red('When specified, "proxy" in package.json must be a string.'));
188-
console.log(chalk.red('Instead, the type of "proxy" was "' + typeof proxy + '".'));
189-
console.log(chalk.red('Either remove "proxy" from package.json, or make it a string.'));
209+
console.log(
210+
chalk.red('When specified, "proxy" in package.json must be a string.')
211+
);
212+
console.log(
213+
chalk.red('Instead, the type of "proxy" was "' + typeof proxy + '".')
214+
);
215+
console.log(
216+
chalk.red(
217+
'Either remove "proxy" from package.json, or make it a string.'
218+
)
219+
);
190220
process.exit(1);
191221
}
192222

@@ -197,15 +227,16 @@ function addMiddleware(devServer) {
197227
// - /sockjs-node/* (WebpackDevServer uses this for hot reloading)
198228
// Tip: use https://www.debuggex.com/ to visualize the regex
199229
var mayProxy = /^(?!\/(index\.html$|.*\.hot-update\.json$|sockjs-node\/)).*$/;
200-
devServer.use(mayProxy,
230+
devServer.use(
231+
mayProxy,
201232
// Pass the scope regex both to Express and to the middleware for proxying
202233
// of both HTTP and WebSockets to work without false positives.
203234
httpProxyMiddleware(pathname => mayProxy.test(pathname), {
204235
target: proxy,
205236
logLevel: 'silent',
206237
onError: onProxyError(proxy),
207238
secure: false,
208-
changeOrigin: true
239+
changeOrigin: true,
209240
})
210241
);
211242
}
@@ -235,6 +266,7 @@ function runDevServer(port, protocol) {
235266
},
236267
// Enable HTTPS if the HTTPS environment variable is set to 'true'
237268
https: protocol === 'https',
269+
// contentBase: paths.staticPath,
238270
});
239271

240272
// Our custom middleware proxies requests to /index.html or a remote API.
@@ -254,7 +286,7 @@ function runDevServer(port, protocol) {
254286
}
255287

256288
function run(port) {
257-
var protocol = process.env.HTTPS === 'true' ? "https" : "http";
289+
var protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
258290
setupCompiler(port, protocol);
259291
runDevServer(port, protocol);
260292
}
@@ -268,9 +300,9 @@ detect(DEFAULT_PORT).then(port => {
268300
}
269301

270302
clearConsole();
271-
var question =
272-
chalk.yellow('Something is already running on port ' + DEFAULT_PORT + '.') +
273-
'\n\nWould you like to run the app on another port instead?';
303+
var question = chalk.yellow(
304+
'Something is already running on port ' + DEFAULT_PORT + '.'
305+
) + '\n\nWould you like to run the app on another port instead?';
274306

275307
prompt(question, true).then(shouldChangePort => {
276308
if (shouldChangePort) {

src/app/favicon.ico

7.03 KB
Binary file not shown.

0 commit comments

Comments
 (0)