Commit 728b8b43 authored by Aral Balkan's avatar Aral Balkan
Browse files

Make .gitignore backup safer

parent dce50715
......@@ -38,7 +38,6 @@ const distOldGitBackupDirectoryName = `${distGitBackupDirectoryName}.old`
const distOldGitBackupDirectoryPath = path.resolve('..', distOldGitBackupDirectoryName)
const gitIgnoreFilePath = path.join(distDirectoryPath, '.gitignore')
const gitIgnoreFile = fs.readFileSync(gitIgnoreFilePath, 'utf-8')
// Exec with promises and piped stdout.
async function exec(command) {
......@@ -50,7 +49,17 @@ async function exec(command) {
console.log('Building…')
let gitIgnoreFile = null
if (fs.existsSync(distDirectoryPath)) {
// Backup the .gitignore file, if one exists
if (fs.existsSync(gitIgnoreFilePath)) {
console.log(' - Backing up .gitignore file from distribution directory.')
gitIgnoreFile = fs.readFileSync(gitIgnoreFilePath, 'utf-8')
} else {
console.log(' - No .gitignore file found in distribution directory.')
}
// Backup the git folder if the distribution directory is under source control.
if (fs.existsSync(distDirectoryGitPath)) {
// First, move the old backup, if one exists.
......@@ -89,9 +98,11 @@ if (fs.existsSync(distGitBackupDirectoryPath)) {
console.log('Restoring .git folder into distribution directory.')
await exec(`cp -R ${distGitBackupDirectoryPath} ${distDirectoryGitPath}`, { env: process.env })
// And save the previously-backed up .gitignore file also.
console.log('Restoring .gitignore file.')
fs.writeFileSync(gitIgnoreFilePath, gitIgnoreFile, 'utf-8')
// And restore the previously-backed up .gitignore file, if one exists.
if (gitIgnoreFile !== null) {
console.log('Restoring .gitignore file.')
fs.writeFileSync(gitIgnoreFilePath, gitIgnoreFile, 'utf-8')
}
} else {
console.log(' - Distribution directory not under version control; no .git directory to restore.')
}
......
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