electron-installer-snap
Version:
Build snapcraft packages for Electron applications
42 lines (32 loc) • 1.29 kB
JavaScript
/*
Copyright 2018, 2019 Mark Lee and contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const fs = require('fs-extra')
const path = require('path')
async function copyHook (snapMetaDir, hookName, hookPath) {
const snapHookPath = path.join(snapMetaDir, hookName)
if (!(await fs.pathExists(hookPath))) {
throw new Error(`Hook ${hookName} at ${hookPath} does not exist!`)
}
await fs.copy(hookPath, snapHookPath)
await fs.chmod(snapHookPath, 0o755)
}
module.exports = async function copyHooks (snapMetaDir, config) {
if (typeof config.hookScripts !== 'object') {
return
}
const hooks = config.hookScripts
delete config.hookScripts
await fs.mkdirs(snapMetaDir)
await Promise.all(Object.keys(hooks).map(key => copyHook(snapMetaDir, key, hooks[key])))
}