-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmove-cache-back.js
48 lines (42 loc) · 1.22 KB
/
move-cache-back.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
42
43
44
45
46
47
48
const fs = require('fs-extra')
const path = require('path')
const { exec } = require("child_process")
const isProduction = process.env.NODE_ENV === 'PRODUCTION'
const CACHE_PATH = isProduction
? path.join('/', 'opt', 'build', 'cache', 'nuxt_build') // Netlify cache path
: path.resolve(__dirname, '.nuxt_build')
const BUILD_PATH = path.resolve(__dirname, '.nuxt')
async function putNuxtClientBack() {
const exists = await fs.pathExists(CACHE_PATH)
if (exists) {
console.log("cache found")
await fs.copy(CACHE_PATH, BUILD_PATH)
exec('nuxt generate --no-build', (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
} else {
console.log("no cache")
exec('npm run generate', (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
}
}
;(async () => {
await putNuxtClientBack()
})()