-
Notifications
You must be signed in to change notification settings - Fork 1
/
publisher.js
41 lines (36 loc) · 1.02 KB
/
publisher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const Path = require('path');
const hirestime = require('hirestime');
const { Nuxt, Builder, Generator } = require('nuxt');
module.exports = async function(request, reply) {
try {
const getElapsed = hirestime();
const { nuxtConfigFn } = require('./nuxt.config.js');
const { payload } = request;
const { name } = payload;
const uploadFolderPath = Path.join(__dirname, `./dist/${name}`);
console.log(`About to generate page: ${name}`);
const nuxtConfig = nuxtConfigFn({
dev: false,
generate: {
dir: uploadFolderPath,
routes: [
{
route: '/',
payload,
},
],
},
});
const nuxt = new Nuxt(nuxtConfig);
const builder = new Builder(nuxt);
const generator = new Generator(nuxt, builder);
const generateResult = await generator.generate({
build: false,
});
const result = `Published in ${getElapsed(hirestime.S)}s`;
return result;
} catch (e) {
console.error(e);
throw new Error(e);
}
};