Commit 1febb7b1 authored by Aral Balkan's avatar Aral Balkan
Browse files

Improve build script

parent 7587da08
......@@ -17,9 +17,12 @@
import path from 'path'
import fs from 'fs'
import childProcess from 'child_process'
import process from 'process'
import childProcess from 'child_process'
import { promisify } from 'util'
const exec = promisify(childProcess.exec)
const currentPath = path.resolve('.')
const currentPathSegments = currentPath.split(path.sep)
const currentDirectoryName = currentPathSegments[currentPathSegments.length - 1]
......@@ -31,23 +34,36 @@ const distDirectoryGitPath = path.join(distDirectoryPath, '.git')
const distGitBackupDirectoryName = `${distDirectoryName}.git`
const distGitBackupDirectoryPath = path.resolve('..', distGitBackupDirectoryName)
async function execWithPromisesAndProgress(command) {
const commandPromise = exec(command)
const commandProcess = commandPromise.child
commandProcess.stdout.pipe(process.stdout)
await commandPromise
}
console.log('Building…')
if (fs.existsSync(distDirectoryPath)) {
// Backup the git folder if the distribution directory is under source control.
if (fs.existsSync(distDirectoryGitPath)) {
// Back up the git folder so it’s not nuked by the Snowpack build.
console.log('Backing up .git folder from distribution directory.')
childProcess.execSync(`cp -R ${distDirectoryGitPath} ${distGitBackupDirectoryPath}`, { env: process.env })
console.log(' - Backing up .git folder from distribution directory.')
await execWithPromisesAndProgress(`cp -R ${distDirectoryGitPath} ${distGitBackupDirectoryPath}`, { env: process.env })
} else {
console.log(' - Distribution directory not under version control; not backing up .git directory.')
}
} else {
console.log('Initial build.')
console.log(' - Initial build.')
}
childProcess.execSync('npx snowpack build', { env: process.env })
await execWithPromisesAndProgress('npx snowpack build', { env: process.env })
if (fs.existsSync(distGitBackupDirectoryPath)) {
// Back up the git folder so it’s not nuked by the Snowpack build.
console.log('Restoring .git folder into distribution directory.')
childProcess.execSync(`cp -R ${distGitBackupDirectoryPath} ${distDirectoryGitPath}`, { env: process.env })
await execWithPromisesAndProgress(`cp -R ${distGitBackupDirectoryPath} ${distDirectoryGitPath}`, { env: process.env })
} else {
console.log(' - Distribution directory not under version control; no .git directory to restore.')
}
console.log('Done.')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment