This repository has been archived by the owner on Jun 5, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
64 lines (48 loc) · 1.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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];
}
};