-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
electron-builder.js
150 lines (140 loc) · 4.36 KB
/
electron-builder.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const path = require('path')
const normalizePackageData = require('normalize-package-data');
const fs = require("fs/promises");
const generateMetadata = require('./generate-metadata-for-builder')
// Monkey-patch to not remove things I explicitly didn't say so
// See: https://github.com/electron-userland/electron-builder/issues/6957
let transformer = require('app-builder-lib/out/fileTransformer')
const builder_util_1 = require("builder-util");
transformer.createTransformer = function(srcDir, configuration, extraMetadata, extraTransformer) {
const mainPackageJson = path.join(srcDir, "package.json");
const isRemovePackageScripts = configuration.removePackageScripts !== false;
const isRemovePackageKeywords = configuration.removePackageKeywords !== false;
const packageJson = path.sep + "package.json";
return file => {
if (file === mainPackageJson) {
return modifyMainPackageJson(file, extraMetadata, isRemovePackageScripts, isRemovePackageKeywords);
}
if (extraTransformer != null) {
return extraTransformer(file);
}
else {
return null;
}
};
}
async function modifyMainPackageJson(file, extraMetadata, isRemovePackageScripts, isRemovePackageKeywords) {
const mainPackageData = JSON.parse(await fs.readFile(file, "utf-8"));
if (extraMetadata != null) {
builder_util_1.deepAssign(mainPackageData, extraMetadata);
return JSON.stringify(mainPackageData, null, 2);
}
return null;
}
/// END Monkey-Patch
const builder = require("electron-builder")
const Platform = builder.Platform
const pngIcon = 'resources/app-icons/beta.png'
const icoIcon = 'resources/app-icons/beta.ico'
let options = {
"appId": "com.pulsar-edit.pulsar",
"npmRebuild": false,
"publish": null,
files: [
"package.json",
"docs/**/*",
"dot-atom/**/*",
"exports/**/*",
"keymaps/**/*",
"menus/**/*",
"node_modules/**/*",
"resources/**/*",
"script/**/*",
"src/**/*",
"static/**/*",
"vendor/**/*",
"!**/node_modules/*/{test,__tests__,tests,powered-test,example,examples}",
"!**/node_modules/*.d.ts",
"!**/node_modules/.bin",
"!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}",
"!.editorconfig",
"!**/._*",
"!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,.gitignore,.gitattributes}",
"!**/{__pycache__,thumbs.db,.flowconfig,.idea,.vs,.nyc_output}",
"!**/{appveyor.yml,.travis.yml,circle.yml}",
"!**/{npm-debug.log,yarn.lock,.yarn-integrity,.yarn-metadata.json}"
],
"extraResources": [
{
"from": "pulsar.sh",
"to": "pulsar.sh"
}, {
"from": "ppm",
"to": "app/ppm"
}, {
"from": pngIcon,
"to": "pulsar.png"
},
],
compression: "normal",
deb: { afterInstall: "script/post-install.sh" },
rpm: {
afterInstall: "script/post-install.sh",
compression: 'xz'
},
"linux": {
"icon": pngIcon,
"category": "Development",
"synopsis": "A Community-led Hyper-Hackable Text Editor",
"target": [
{ target: "appimage" },
{ target: "deb" },
{ target: "rpm" }
],
},
"mac": {
"icon": pngIcon,
"category": "Development"
},
"win": {
"icon": icoIcon,
"target": [
{ "target": "nsis" },
{ "target": "portable" }
]
},
"extraMetadata": {
},
"asarUnpack": ["node_modules/github/bin/*"]
}
function whatToBuild() {
const argvStartingWith = process.argv.findIndex(e => e.match('electron-builder.js'))
const what = process.argv[argvStartingWith + 1]
if(what) {
const filter = e => e.target === what
options.linux.target = options.linux.target.filter(filter)
options.win.target = options.win.target.filter(filter)
// options.mac.target = options.mac.target.filter(filter)
return options
} else {
return options
}
}
async function main() {
const package = await fs.readFile('package.json', "utf-8")
let options = whatToBuild()
options.extraMetadata = generateMetadata(JSON.parse(package))
builder.build({
//targets: Platform.LINUX.createTarget(),
config: options
}).then((result) => {
console.log("Built binaries")
fs.mkdir('binaries').catch(() => "")
Promise.all(result.map(r => fs.copyFile(r, path.join('binaries', path.basename(r)))))
}).catch((error) => {
console.error("Error building binaries")
console.error(error)
process.exit(1)
})
}
main()