Skip to content

Commit

Permalink
selectively generate
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbyul-here committed Dec 21, 2020
1 parent cfa12fb commit cdaa8ce
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
39 changes: 29 additions & 10 deletions move-cache-back.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs-extra')
const path = require('path')
const { exec } = require("child_process")

const isProduction = process.env.NODE_ENV === 'PRODUCTION'

Expand All @@ -10,20 +11,38 @@ const CACHE_PATH = isProduction
const BUILD_PATH = path.resolve(__dirname, '.nuxt')

async function putNuxtClientBack() {
fs.pathExists(CACHE_PATH, (err, exists) => {
console.log('check cachepath')
console.log(err) // => null
console.log(exists) // => false
})

try {
const exists = await fs.pathExists(CACHE_PATH)
if (exists) {
console.log("cache found")
await fs.copy(CACHE_PATH + '/.nuxt', BUILD_PATH)
} catch (e) {
console.log(e)
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()

})()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Hanbyul Jo <[email protected]>",
"scripts": {
"initial-build": "INITIAL_BUILD=true nuxt generate",
"incremental-build": "node move-cache-back; nuxt generate --no-build;",
"incremental-build": "node move-cache-back",
"dev": "DEPLOY_ENV=DEV nuxt",
"build": "nuxt build",
"start": "nuxt start",
Expand Down

0 comments on commit cdaa8ce

Please sign in to comment.