Skip to content

Commit e4b057f

Browse files
authored
chore: update node and some deps (postlight#209)
* chore: update .nvmrc * added prettier and pre-commit hooks * update docker image to new node * add karma-cli to get web tests working * explictly install karma... seems to fix problem * remove pre-built phantomjs * swap install order
1 parent 78adb2c commit e4b057f

File tree

304 files changed

+6045
-4744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

304 files changed

+6045
-4744
lines changed

.circleci/config.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@ version: 2
22
jobs:
33
test-node:
44
docker:
5-
- image: circleci/node:6.14-stretch
5+
- image: circleci/node:8.10
66
steps:
77
- checkout
88
- run: "yarn install"
99
- run: "yarn lint:ci"
1010
- run: "yarn build"
1111
- run: "./scripts/pr-parser-preview.sh"
12-
- run: "yarn test:node -- --maxWorkers=4"
12+
- run: "yarn test:node --maxWorkers=4"
1313

1414
- store_artifacts:
1515
path: tmp/artifacts
1616

1717
test-web:
1818
docker:
19-
- image: circleci/node:6.14-stretch
19+
- image: circleci/node:8.10-browsers
2020
steps:
2121
- checkout
2222
- run: "yarn install"
2323
# For some reason phantomjs-prebuild is failing w/yarn, but npm installing works
2424
- run: "npm install phantomjs-prebuilt"
25-
# Switch to 7 and lint
26-
- run: "yarn test:web -- --maxWorkers=4"
27-
- run: "yarn build:web -- --maxWorkers=4"
25+
- run: "yarn add karma-cli --dev"
26+
- run: "yarn test:web --maxWorkers=4"
27+
- run: "yarn build:web --maxWorkers=4"
2828

2929
update-fixtures:
3030
docker:
31-
- image: circleci/node:6.14-stretch
31+
- image: circleci/node:8.10
3232
steps:
3333
- checkout
3434
- run: "yarn install"

.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Copy this file, and add rule overrides as needed.
33
{
44
"parser": "babel-eslint",
5-
"extends": "airbnb",
5+
"extends": ["airbnb", "prettier"],
66
"plugins": [
77
"babel"
88
],

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.10
1+
8.10

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "es5",
3+
"semi": true,
4+
"singleQuote": true
5+
}

package.json

+21
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,34 @@
4949
"changelog-maker": "^2.3.0",
5050
"eslint": "^3.8.1",
5151
"eslint-config-airbnb": "^12.0.0",
52+
"eslint-config-prettier": "^3.5.0",
5253
"eslint-import-resolver-babel-module": "^2.0.1",
5354
"eslint-plugin-babel": "^3.3.0",
5455
"eslint-plugin-import": "^1.16.0",
5556
"eslint-plugin-jsx-a11y": "^2.2.3",
5657
"eslint-plugin-react": "^6.4.1",
5758
"express": "^4.14.0",
59+
"husky": "^1.3.1",
5860
"inquirer": "^1.1.3",
5961
"jasmine-core": "^2.5.2",
6062
"jest": "^16.0.2",
6163
"jest-cli": "^16.0.2",
6264
"karma": "^1.3.0",
6365
"karma-browserify": "^5.1.0",
6466
"karma-chrome-launcher": "^2.0.0",
67+
"karma-cli": "^2.0.0",
6568
"karma-jasmine": "^1.0.2",
6669
"karma-mocha": "^1.3.0",
6770
"karma-phantomjs-launcher": "^1.0.2",
6871
"karma-requirejs": "^1.1.0",
72+
"lint-staged": "^8.1.0",
6973
"mocha": "^3.1.2",
7074
"nock": "^9.0.2",
7175
"ora": "^0.3.0",
7276
"phantomjs-polyfill-find": "ptim/phantomjs-polyfill-find",
7377
"phantomjs-polyfill-string-includes": "^1.0.0",
7478
"phantomjs-prebuilt": "^2.1.14",
79+
"prettier": "^1.15.3",
7580
"requirejs": "^2.3.2",
7681
"rollup": "^0.36.3",
7782
"rollup-plugin-babel": "^2.6.1",
@@ -104,5 +109,21 @@
104109
"request": "browser-request",
105110
"iconv-lite": "./src/shims/iconv-lite",
106111
"moment-timezone": "./node_modules/moment-timezone/builds/moment-timezone-with-data-2010-2020.min.js"
112+
},
113+
"husky": {
114+
"hooks": {
115+
"pre-commit": "lint-staged"
116+
}
117+
},
118+
"lint-staged": {
119+
"*.{js}": [
120+
"eslint --fix",
121+
"prettier --write",
122+
"git add"
123+
],
124+
"*.{json,css,md}": [
125+
"prettier --write",
126+
"git add"
127+
]
107128
}
108129
}

scripts/check-build.test.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ let urls = [
88
title: 'Iraqi troops storm town south of Mosul',
99
},
1010
{
11-
url: 'https://www.cnn.com/2018/10/12/us/before-after-aerial-images-mexico-beach-devastation-trnd/index.html',
12-
title: 'Before and after images show there\'s nothing left in some parts of Mexico Beach',
11+
url:
12+
'https://www.cnn.com/2018/10/12/us/before-after-aerial-images-mexico-beach-devastation-trnd/index.html',
13+
title:
14+
"Before and after images show there's nothing left in some parts of Mexico Beach",
1315
},
1416
];
1517

@@ -24,7 +26,8 @@ if (process.env.CI) {
2426
if (cheerio.browser) {
2527
require('../dist/mercury.web');
2628
}
27-
const Merc = typeof Mercury === 'undefined' ? require('../dist/mercury') : Mercury;
29+
const Merc =
30+
typeof Mercury === 'undefined' ? require('../dist/mercury') : Mercury;
2831

2932
describe('Is Mercury build working', () => {
3033
beforeAll(() => {
@@ -38,15 +41,17 @@ if (process.env.CI) {
3841
});
3942

4043
urls.map(article =>
41-
it(`gets this title right ${article.title}`, (done) => {
42-
Merc.parse(article.url).then((result) => {
43-
assert.equal(article.title, result.title);
44-
done();
45-
}).catch((e) => {
46-
console.log(e.name, e.message); // eslint-disable-line no-console
47-
assert.equal(true, false);
48-
done();
49-
});
44+
it(`gets this title right ${article.title}`, done => {
45+
Merc.parse(article.url)
46+
.then(result => {
47+
assert.equal(article.title, result.title);
48+
done();
49+
})
50+
.catch(e => {
51+
console.log(e.name, e.message); // eslint-disable-line no-console
52+
assert.equal(true, false);
53+
done();
54+
});
5055
})
5156
);
5257
});

scripts/comment-on-pr.js

+42-30
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
22
const bot = require('@jesses/circle-github-bot').default.create();
33
const Mercury = require('../dist/mercury.js');
4-
const fs = require("fs");
4+
const fs = require('fs');
55

66
const run = () => {
77
const screenshotPath = process.argv[2];
@@ -11,33 +11,42 @@ const run = () => {
1111
const html = fs.readFileSync(`${fixture}`);
1212

1313
// first parse is just to get the url
14-
Mercury.parse('http://example.com', html, { fallback: false }).then(({ url, domain, excerpt, word_count, direction }) => {
15-
// with the url, second pass will test the correct parser
16-
Mercury.parse(url, html, { fallback: false }).then(json => {
17-
// removing excerpt b/c this comes from content, not necessary
18-
delete json.excerpt
19-
20-
// adding items that aren't pulled in custom parser w/out fallback
21-
Object.assign(json, { url, domain, word_count, direction });
22-
23-
// a quick preview of the parsed content in an html file
24-
const previewHtml = `<h1>${json.title}</h1><img src=${json.lead_image_url} /><p>${json.author}</p>${json.content}`
25-
26-
27-
const jsonPath = `${screenshotPath}-parsed.json`;
28-
const fixtureArtifactPath = `tmp/artifacts/${fixture}`;
29-
const previewPath = `tmp/artifacts/${fixture}.preview.html`;
30-
31-
fs.writeFileSync(previewPath, previewHtml);
32-
fs.writeFileSync(jsonPath, JSON.stringify(json));
33-
fs.writeFileSync(fixtureArtifactPath, html);
34-
35-
bot.comment(process.env.GH_AUTH_TOKEN, `### 🤖 Automated Parsing Preview 🤖
14+
Mercury.parse('http://example.com', html, { fallback: false }).then(
15+
({ url, domain, excerpt, word_count, direction }) => {
16+
// with the url, second pass will test the correct parser
17+
Mercury.parse(url, html, { fallback: false }).then(json => {
18+
// removing excerpt b/c this comes from content, not necessary
19+
delete json.excerpt;
20+
21+
// adding items that aren't pulled in custom parser w/out fallback
22+
Object.assign(json, { url, domain, word_count, direction });
23+
24+
// a quick preview of the parsed content in an html file
25+
const previewHtml = `<h1>${json.title}</h1><img src=${
26+
json.lead_image_url
27+
} /><p>${json.author}</p>${json.content}`;
28+
29+
const jsonPath = `${screenshotPath}-parsed.json`;
30+
const fixtureArtifactPath = `tmp/artifacts/${fixture}`;
31+
const previewPath = `tmp/artifacts/${fixture}.preview.html`;
32+
33+
fs.writeFileSync(previewPath, previewHtml);
34+
fs.writeFileSync(jsonPath, JSON.stringify(json));
35+
fs.writeFileSync(fixtureArtifactPath, html);
36+
37+
bot.comment(
38+
process.env.GH_AUTH_TOKEN,
39+
`### 🤖 Automated Parsing Preview 🤖
3640
**Commit:** \`${bot.env.commitMessage}\`
3741
38-
![Screenshot of fixture (this embed should work after repo is public)](${bot.artifactUrl(screenshotPath)})
42+
![Screenshot of fixture (this embed should work after repo is public)](${bot.artifactUrl(
43+
screenshotPath
44+
)})
3945
40-
[Original Article](${url}) | ${bot.artifactLink(fixtureArtifactPath, 'HTML Fixture')} | ${bot.artifactLink(previewPath, 'Parsed Content Preview')}
46+
[Original Article](${url}) | ${bot.artifactLink(
47+
fixtureArtifactPath,
48+
'HTML Fixture'
49+
)} | ${bot.artifactLink(previewPath, 'Parsed Content Preview')}
4150
4251
<details>
4352
<summary><b>Parsed JSON</b></summary>
@@ -52,12 +61,15 @@ ${JSON.stringify(json, null, 2)}
5261
5362
**\`null\` fields**
5463
55-
${Object.keys(json).map(key => json[key] !== null ? '' : ` * \`${key}\n\``).join('') || 'None'}
64+
${Object.keys(json)
65+
.map(key => (json[key] !== null ? '' : ` * \`${key}\n\``))
66+
.join('') || 'None'}
5667
5768
`
58-
);
59-
});
60-
});
61-
}
69+
);
70+
});
71+
}
72+
);
73+
};
6274

6375
run();

scripts/generate-custom-parser.js

+18-16
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import inquirer from 'inquirer';
77
import ora from 'ora';
88
import { exec } from 'child_process';
99

10-
import {
11-
stripJunkTags,
12-
makeLinksAbsolute,
13-
} from 'utils/dom';
10+
import { stripJunkTags, makeLinksAbsolute } from 'utils/dom';
1411
import Mercury from '../dist/mercury';
1512
import extractorTemplate from './templates/custom-extractor';
1613
import extractorTestTemplate from './templates/custom-extractor-test';
@@ -19,7 +16,8 @@ const questions = [
1916
{
2017
type: 'input',
2118
name: 'website',
22-
message: 'Paste a url to an article you\'d like to create or extend a parser for:',
19+
message:
20+
"Paste a url to an article you'd like to create or extend a parser for:",
2321
validate(value) {
2422
const { hostname } = URL.parse(value);
2523
if (hostname) return true;
@@ -74,25 +72,25 @@ const urlArg = process.argv[2];
7472
if (urlArg) {
7573
scaffoldCustomParser(urlArg);
7674
} else {
77-
inquirer.prompt(questions).then((answers) => {
75+
inquirer.prompt(questions).then(answers => {
7876
scaffoldCustomParser(answers.website);
7977
});
8078
}
8179

8280
function generateScaffold(url, file, result) {
8381
const { hostname } = URL.parse(url);
8482
const extractor = extractorTemplate(hostname, extractorName(hostname));
85-
const extractorTest =
86-
extractorTestTemplate(
87-
file, url, getDir(url), result, extractorName(hostname)
88-
);
83+
const extractorTest = extractorTestTemplate(
84+
file,
85+
url,
86+
getDir(url),
87+
result,
88+
extractorName(hostname)
89+
);
8990

9091
fs.writeFileSync(`${getDir(url)}/index.js`, extractor);
9192
fs.writeFileSync(`${getDir(url)}/index.test.js`, extractorTest);
92-
fs.appendFileSync(
93-
'./src/extractors/custom/index.js',
94-
exportString(url),
95-
);
93+
fs.appendFileSync('./src/extractors/custom/index.js', exportString(url));
9694
exec(`npm run lint-fix-quiet -- ${getDir(url)}/*.js`);
9795
}
9896

@@ -116,9 +114,13 @@ function savePage($, [url], newParser) {
116114

117115
fs.writeFileSync(file, html);
118116

119-
Mercury.parse(url, html).then((result) => {
117+
Mercury.parse(url, html).then(result => {
120118
if (newParser) {
121-
confirm(generateScaffold, [url, file, result], 'Generating parser and tests');
119+
confirm(
120+
generateScaffold,
121+
[url, file, result],
122+
'Generating parser and tests'
123+
);
122124
console.log(`Your custom site extractor has been set up. To get started building it, run
123125
yarn watch:test -- ${hostname}
124126
-- OR --

scripts/generate-fixture-preview.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ const page = require('webpage').create();
33
const system = require('system');
44
const args = system.args;
55

6-
const fixtures = args.slice(1)[0].slice(0, -1).split(',');
6+
const fixtures = args
7+
.slice(1)[0]
8+
.slice(0, -1)
9+
.split(',');
710
const totalRenders = fixtures.length;
811

912
var renderCount = 0;
@@ -17,12 +20,13 @@ function pageRenderComplete() {
1720
}
1821

1922
function capturePage() {
20-
const fixturePath = fixtures[renderCount]
23+
const fixturePath = fixtures[renderCount];
2124
page.viewportSize = { width: 1366, height: 768 };
2225

2326
page.open(fixturePath, function() {
2427
// set default background to white (otherwise can sometimes get transparent bg in png
25-
const script = "function() { \
28+
const script =
29+
"function() { \
2630
var style = document.createElement('style'); \
2731
var text = document.createTextNode('body { background: #fff }'); \
2832
style.setAttribute('type', 'text/css'); \

0 commit comments

Comments
 (0)