UNPKG

@davidwinter/electron-forge-maker-snap

Version:

[![test](https://github.com/davidwinter/electron-forge-maker-snap/workflows/test/badge.svg)](https://github.com/davidwinter/electron-forge-maker-snap/actions?query=workflow%3Atest) [![Codecov](https://img.shields.io/codecov/c/github/davidwinter/electron-f

65 lines (48 loc) 1.78 kB
const path = require('path'); const {spawn} = require('child_process'); const MakerBase = require('@electron-forge/maker-base').default; const fse = require('fs-extra'); const debug = require('debug'); const SnapPackager = require('./snap-packager.js'); const log = debug('electron-forge-maker-snap:maker-snap'); log.log = console.log.bind(console); module.exports = class MakerSnap extends MakerBase { constructor(configFetcher, providedPlatforms) { super(configFetcher, providedPlatforms); this.name = 'snap'; this.defaultPlatforms = ['linux']; } isSupportedOnCurrentPlatform() { return true; } async make(options) { log('snap maker has been initiated from electron-forge'); const pkg = new SnapPackager({ makeOptions: options, makerOptions: this.config, dependencies: { fse, process, spawn } }); log('Creating snapcraft related files'); pkg.createSnapcraftFiles(); log('Snapcraft related files created'); log('Creating snap file'); const snapFileLocation = await pkg.createSnapPackage(); log(`Snap file created at: ${snapFileLocation}`); const snapFilename = path.basename(snapFileLocation); const finalSnapLocation = path.join(options.makeDir, snapFilename); log(`Moving snap file from ${snapFileLocation} to ${finalSnapLocation}`); fse.renameSync(snapFileLocation, finalSnapLocation); log(`Snap file moved to: ${finalSnapLocation}`); const snapcraftDirectory = path.dirname(snapFileLocation); if (fse.existsSync(snapcraftDirectory)) { fse.rmdirSync(snapcraftDirectory, {recursive: true}); log(`Tidy up; snapcraft files deleted from: ${snapcraftDirectory}`); } log(`Finishing snap maker, passing back to electron-forge with: ${finalSnapLocation}`); return [finalSnapLocation]; } };