Commit a5914810 authored by Aral Balkan's avatar Aral Balkan
Browse files

Add new build script that optionally backs up .git folder in dist

parent e9f9fc96
#!/env/node
//////////////////////////////////////////////////////////////////////
//
// Generic Small Web Client build script.
//
// Build the client into a …/<client-name>-dist folder,
// optionally backing up and restoring a .git folder
// if the distribution folder happens to be under source control.
// (Note: you must manually create a git repository and configure
// it you build the client for the first time.)
//
// Copyright ⓒ 2021 Aral Balkan. Licensed under AGPLv3 or later.
// Shared with ♥ by the Small Technology Foundation.
//
//////////////////////////////////////////////////////////////////////
import path from 'path'
import fs from 'fs'
import childProcess from 'child_process'
import process from 'process'
const currentPath = path.resolve('.')
const currentPathSegments = currentPath.split(path.sep)
const currentDirectoryName = currentPathSegments[currentPathSegments.length - 1]
const distDirectoryName = `${currentDirectoryName}-dist`
const distDirectoryPath = path.resolve('..', distDirectoryName)
const distDirectoryGitPath = path.join(distDirectoryPath, '.git')
const distGitBackupDirectoryName = `${distDirectoryName}.git`
const distGitBackupDirectoryPath = path.resolve('..', distGitBackupDirectoryName)
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 })
}
} else {
console.log('Initial build.')
}
childProcess.execSync('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 })
}
console.log('Done.')
......@@ -3,7 +3,7 @@ module.exports = {
mount: {
/* ... */
},
exclude: ['**/node_modules/**/*', '.git/**', 'build'],
exclude: ['**/node_modules/**/*', '.git/**', 'build.js'],
plugins: [
['@snowpack/plugin-svelte'],
],
......
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