Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Put JS through build pipeline #285

Merged
merged 7 commits into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"es2015",
"stage-0"
]
}
2 changes: 2 additions & 0 deletions client/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env:
browser: true
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
"exhibit": "^0.10.1",
"exhibit-directory": "^0.10.1",
"exhibit-plugin-autoprefixer": "^0.10.1",
"exhibit-plugin-babel": "^0.10.1",
"exhibit-plugin-browserify": "^0.10.1",
"exhibit-plugin-sass": "^0.10.1",
"express": "^4.14.0",
"express-babelify-middleware": "^0.2.1",
"g-ui": "git+https://github.com/Financial-Times/g-ui.git#adds-templates",
"html-minifier": "^3.0.3",
"isomorphic-fetch": "^2.2.1",
Expand All @@ -55,9 +56,9 @@
"sequelize": "^3.24.3",
"sequelize-cli": "^2.4.0",
"svg-intersections": "^0.2.5",
"trip": "^1.0.3",
"winston": "^2.2.0",
"xmldom": "^0.1.22",
"trip": "^1.0.3"
"xmldom": "^0.1.22"
},
"devDependencies": {
"babel-eslint": "^6.1.2",
Expand All @@ -76,10 +77,10 @@
},
"private": true,
"scripts": {
"start": "sequelize db:migrate && node --require ./setup.js server",
"scraper": "node --require ./setup.js scraper/run",
"postinstall": "bower install && trip build",
"dev": "trip watch & nodemon --ext js,html,svg,css --ignore dist --ignore public",
"postinstall": "bower install && trip build",
"scraper": "node --require ./setup.js scraper/run",
"start": "sequelize db:migrate && node --require ./setup.js server",
"test": "mocha --compilers js:babel-core/register layouts/*.spec.js"
}
}
12 changes: 6 additions & 6 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import express from 'express';
import lru from 'lru-cache';
import babelify from 'express-babelify-middleware';
import slashes from 'connect-slashes';
import flags from '../config/flags';
import * as nunjucks from './nunjucks';
Expand Down Expand Up @@ -52,7 +51,6 @@ if (process.env.SCRAPE_ON_STARTUP === '1' || process.env.SCRAPE_ON_STARTUP === '
});
}

app.use('/main.js', babelify('public/main.js'));
app.use(express.static('dist'));
app.use(express.static('public'));
app.use(slashes(false));
Expand Down Expand Up @@ -100,7 +98,7 @@ app.get('/__access_metadata', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.setHeader('Cache-Control', `public, max-age=86400`);
res.send(`
{"access_metadata":[{"path_regex":"\/us-elections*","classification":"unconditional"},
{"access_metadata":[{"path_regex":"/us-elections*","classification":"unconditional"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The slash is needed. Do not merge this!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah the linter complained about it as unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that backslash is supposed to be in the output, it should be \\.

  • \\/ translates to \/
  • \/ translates to /
  • / translates to /

which do we want

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I need to check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 ok, just needed to also check the access service docs

{"path_regex":".*","classification":"unconditional"}]}`);
});

Expand Down Expand Up @@ -202,7 +200,9 @@ if (app.locals.flags.results) {
app.get('/:code', stateCodeRedirectController);

const server = app.listen(process.env.PORT || 5000, () => {
const host = server.address().address;
const port = server.address().port;
console.log(`running ${host} ${port}`);
const { port } = server.address();

console.log(
app.locals.flags.prod ? `Running on port ${port}` : `Running at http://localhost:${port}/`
);
});
2 changes: 2 additions & 0 deletions tripfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const dist = new Directory('dist', { log: true });
const transform = compose(
plugin('sass', { root: 'client', loadPaths: ['bower_components'] }),
plugin('autoprefixer', 'last 2 versions'),
plugin('babel', { root: 'client' }),
plugin('browserify', { root: 'client' }),
);

export const build = async () => {
Expand Down
2 changes: 1 addition & 1 deletion views/polls-layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
]
%}
{% set scripts = [
'main.js',
'main.entry.js',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

@callumlocke callumlocke Oct 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The browserify default is for *.entry.js to be treated as an entry. I could rename the file back to main.js and just configure browserify to treat main.js as an entry instead, if you prefer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine.

'g-ui/index.js',
'https://origami-build.ft.com/v2/bundles/js?export=bundle&modules=o-expander@^4.0.2,o-buttons@^4.0.2,o-date@^2.6.0,o-cookie-message@^2.2.0'
]
Expand Down