Skip to content

Commit 46a8b0e

Browse files
authoredJul 17, 2017
Run all examples on precommit (wojtekmaj#124)
Fixes wojtekmaj#110
1 parent 6cdb2a7 commit 46a8b0e

File tree

7 files changed

+1139
-9
lines changed

7 files changed

+1139
-9
lines changed
 

‎examples/fractals/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,4 @@ const doc = (
2626
</Document>
2727
);
2828

29-
ReactPDF.render(doc, `${__dirname}/output.pdf`, () => {
30-
console.log('Fractals rendered!');
31-
});
29+
ReactPDF.render(doc, `${__dirname}/output.pdf`);

‎examples/index.js

+32-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1+
import fs from 'fs';
2+
import path from 'path';
13
import MockDate from 'mockdate';
4+
import chalk from 'chalk';
25

36
// For git purposes.
47
// Prevent commiting PDF example everytime the script is excecuted.
58
MockDate.set(1434319925275);
69

7-
try {
8-
require(`./${process.argv[2]}/index`);
9-
} catch (e) {
10-
console.error(e);
10+
const getDirectories = (srcpath = __dirname) =>
11+
fs
12+
.readdirSync(srcpath)
13+
.filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory())
14+
.filter(folder => folder !== 'node_modules');
15+
16+
const fileExists = (file, srcpath = __dirname) =>
17+
fs.existsSync(path.join(__dirname, file));
18+
19+
const runExample = name => {
20+
try {
21+
require(`./${name}/index`);
22+
} catch (e) {
23+
console.error(e);
24+
}
25+
};
26+
27+
const testName = process.argv[2];
28+
29+
if (testName === 'all') {
30+
console.log(chalk.green('Running all the examples suite'));
31+
getDirectories().forEach(dir => {
32+
if (fileExists(`${dir}/index.js`)) {
33+
runExample(dir);
34+
}
35+
});
36+
} else {
37+
console.log(chalk.green(`Running the ${testName} example`));
38+
runExample(testName);
1139
}

‎examples/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dependencies": {
1010
"@react-pdf/core": "^0.4.1",
1111
"@react-pdf/node": "^0.4.1",
12+
"chalk": "^2.0.1",
1213
"lodash.times": "^4.3.2",
1314
"react": "16.0.0-alpha.4"
1415
}

‎examples/page-layout/output.pdf

0 Bytes
Binary file not shown.

‎examples/text/output.pdf

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.