ADD export script
This commit is contained in:
parent
cdb7753a23
commit
44e7a2e14e
82
node/app.js
82
node/app.js
@ -1,26 +1,55 @@
|
||||
/* eslint-disable */
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const exec = require('child_process').exec;
|
||||
const Rx = require('rxjs/Rx');
|
||||
const http = require('http');
|
||||
|
||||
/**
|
||||
* converts resumes to pdf
|
||||
* @return {Promise}
|
||||
*/
|
||||
const convert = () => {
|
||||
const fetchResponse = () => {
|
||||
return new Promise((res, rej) => {
|
||||
try {
|
||||
const req = http.request('http://localhost:8080/#/', response => res(response.statusCode));
|
||||
req.on('error', (err) => rej(err));
|
||||
req.end();
|
||||
} catch (err) {
|
||||
rej(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const waitForServerReachable = () => {
|
||||
return Rx.Observable
|
||||
.interval(1000)
|
||||
.mergeMap(async() => {
|
||||
try {
|
||||
const statusCode = await fetchResponse();
|
||||
if (statusCode === 200) return true;
|
||||
} catch (err) {}
|
||||
return false;
|
||||
})
|
||||
.filter(ok => !!ok);
|
||||
};
|
||||
|
||||
const timedOut = timeout => {
|
||||
return new Promise(res => {
|
||||
setTimeout(res, timeout);
|
||||
});
|
||||
};
|
||||
|
||||
const convert = async() => {
|
||||
await waitForServerReachable().first().toPromise();
|
||||
console.log('Connected to server ...');
|
||||
console.log('Exporting ...');
|
||||
try {
|
||||
const directories = getResumesFromDirectories();
|
||||
const scripts = directories.map(resume => electroshotScript(resume.path));
|
||||
execBash(scripts.join(' && '));
|
||||
await execBash(scripts.join(' && '));
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
console.log('Finished exports.');
|
||||
};
|
||||
|
||||
/**
|
||||
* generates electroshot command for screenshoting resume
|
||||
* @param {string} resume resume name in URL
|
||||
* @return {string} electroshot command
|
||||
*/
|
||||
const electroshotScript = resume => {
|
||||
const dir = path.join(__dirname, '../pdf');
|
||||
return 'electroshot localhost:8080/#/resume/' + resume +
|
||||
@ -28,39 +57,26 @@ const electroshotScript = resume => {
|
||||
' --filename "' + resume + '.pdf" --pdf-background';
|
||||
};
|
||||
|
||||
/**
|
||||
* gets resumes names and paths from directories
|
||||
* @return {Object[]} array with resumes object {path: '', name: ''}
|
||||
*/
|
||||
const getResumesFromDirectories = () => {
|
||||
const directories = getDirectories();
|
||||
return directories
|
||||
.filter(dir => dir.includes('resume-') && dir !== 'resume-XX')
|
||||
.map(dir => {
|
||||
let name = dir.replace('resume-', '');
|
||||
let fileName = dir.replace('.vue', '');
|
||||
return {
|
||||
path: fileName.replace('resume-', ''),
|
||||
name: name.replace('-', ' ')
|
||||
};
|
||||
});
|
||||
.filter(dir => dir.includes('resume-') && dir !== 'resume-XX')
|
||||
.map(dir => {
|
||||
let name = dir.replace('resume-', '');
|
||||
let fileName = dir.replace('.vue', '');
|
||||
return {
|
||||
path: fileName.replace('resume-', ''),
|
||||
name: name.replace('-', ' ')
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* gets directories starting with 'resume-'
|
||||
* @return {[]}
|
||||
*/
|
||||
const getDirectories = () => {
|
||||
const srcpath = path.join(__dirname, '../src/components');
|
||||
return fs.readdirSync(srcpath)
|
||||
.filter(file => file.includes('resume-'));
|
||||
};
|
||||
|
||||
/**
|
||||
* executes command
|
||||
* @param {string} script e.g. 'echo "Hello World"'
|
||||
* @return {Promise}
|
||||
*/
|
||||
const execBash = script => {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(script,
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
"dev": "node build/dev-server.js",
|
||||
"start": "node build/dev-server.js",
|
||||
"pdf": "node node/app.js",
|
||||
"export": "concurrently \"npm run dev\" \"npm run pdf\" --success first --kill-others --raw",
|
||||
"test": "cross-env BABEL_ENV=test karma start test/karma.conf.js --single-run",
|
||||
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
|
||||
},
|
||||
@ -58,6 +59,7 @@
|
||||
"file-loader": "^0.11.1",
|
||||
"friendly-errors-webpack-plugin": "^1.1.3",
|
||||
"html-webpack-plugin": "^2.28.0",
|
||||
"http": "0.0.0",
|
||||
"http-proxy-middleware": "^0.17.3",
|
||||
"inject-loader": "^3.0.0",
|
||||
"karma": "^1.4.1",
|
||||
@ -80,13 +82,17 @@
|
||||
"phantomjs-prebuilt": "^2.1.14",
|
||||
"postcss": "^6.0.1",
|
||||
"postcss-cssnext": "^2.11.0",
|
||||
"request": "^2.81.0",
|
||||
"request-promise": "^4.2.1",
|
||||
"rimraf": "^2.6.0",
|
||||
"rx": "^4.1.0",
|
||||
"rxjs": "^5.4.0",
|
||||
"selenium-server": "^3.0.1",
|
||||
"semver": "^5.3.0",
|
||||
"shelljs": "^0.7.6",
|
||||
"sinon": "^2.1.0",
|
||||
"sinon-chai": "^2.8.0",
|
||||
"url-exists": "^1.0.3",
|
||||
"url-loader": "^0.5.8",
|
||||
"vue-loader": "^11.3.4",
|
||||
"vue-style-loader": "^2.0.5",
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
pdf/oblique.pdf
BIN
pdf/oblique.pdf
Binary file not shown.
BIN
pdf/side-bar.pdf
BIN
pdf/side-bar.pdf
Binary file not shown.
BIN
pdf/template.pdf
BIN
pdf/template.pdf
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user