forked from electron-userland/electron-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (73 loc) · 2.17 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* electron-builder
* https://github.com/loopline-systems/electron-builder
*
* Licensed under the MIT license.
*/
'use strict';
var platforms = require( './lib/platforms' );
var path = require( 'path' );
var fs = require( 'fs' );
var mkdirp = require( 'mkdirp' );
/**
* Prototype for electron-builder
* @type {Object}
*/
var Builder = {
/**
* Build the installer for given platform
*
* @param {Object} options option
* @param {Function} callback callback
*/
build : function( options, callback ) {
options = options || {};
options.log = options.log || console.log;
options.out = options.out ? path.resolve( process.cwd(), options.out ) : process.cwd();
options.log(
'- Running electron-builder ' + require( './package' ).version
);
// make sure the output
// directory ends with a slash
if ( options.out[ options.out.length - 1 ] !== path.sep ) {
options.out += path.sep;
}
// make sure the output
// directory exists
if ( !fs.existsSync( options.out ) ) {
options.log( '- Ouput directory ´' + options.out + '´ does not exist ' );
mkdirp.sync( options.out );
options.log( '- Created ´' + options.out + '´ ' );
}
// FAIL when not all required options are set
if ( !options.appPath || !options.platform || !options.config ) {
return callback( new Error( 'Required option not set' ) );
}
if ( typeof options.config === 'string' ) {
var configPath = path.resolve( process.cwd(), options.config );
options.basePath = path.dirname( configPath );
try {
options.config = require( configPath );
} catch( error ) {
return callback( new Error( 'Could not load config file' ) );
}
}
// FAIL when set platform is not available
if ( !platforms[ options.platform ] ) {
return callback(
new Error( 'Building for ´' + options.platform + '´ is not supported' )
);
}
platforms[ options.platform ].init().build( options, callback );
}
};
/**
* Expose factory function
*
* @type {Object}
*/
module.exports = {
init : function() {
return Object.create( Builder );
}
};