-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcache-me.js
51 lines (42 loc) · 1.16 KB
/
cache-me.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
49
50
51
const fs = require('fs-extra')
const path = require('path')
const Rsync = require('rsync')
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, 'dist')
const rsync = new Rsync()
.shell('ssh')
.flags('azq')
.source(BUILD_PATH + '/')
.destination(CACHE_PATH)
async function cacheFinalFiles() {
try {
await fs.copy(BUILD_PATH, CACHE_PATH)
await fs.move(path.resolve(__dirname, '.nuxt'), path.join(CACHE_PATH, '.nuxt'))
} catch (e) {
console.log(e)
}
}
async function cacheAndCopy() {
try {
await fs.ensureDir(CACHE_PATH)
rsync.execute(async function(error, code, cmd) {
if (!error) {
await fs.copy(CACHE_PATH, BUILD_PATH)
await cacheFinalFiles()
console.log('Please tell me you are well cached.')
} else console.error('error')
})
} catch (err) {
// handle error
console.log('cache and copy ')
console.log(err)
}
}
async function putCacheBack() {
}
module.exports = {
cacheAndCopy
}