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
/
snap-values.js
153 lines (117 loc) · 3.49 KB
/
snap-values.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
151
152
153
const path = require('path');
const LinuxApp = require('electron-packager/src/linux.js');
class SnapValues {
constructor(options) {
this.makeOptions = options.makeOptions;
this.makerOptions = options.makerOptions;
this.values = {};
}
get applicationName() {
this.values.applicationName = this.makerOptions.applicationName || this.makeOptions.appName;
if (this.values.applicationName.length > 40) {
throw new Error(`applicationName must be 40 characters or less: ${this.values.applicationName}`);
}
return this.values.applicationName;
}
get executableName() {
return this._sanatizeExecutableName(this.makerOptions.executableName || this.makeOptions.appName);
}
get packagedExecutableName() {
const linuxApp = new LinuxApp.App({
name: this.makeOptions.appName
});
return linuxApp.newElectronName;
}
get version() {
return this.makeOptions.packageJSON.version;
}
get summary() {
this.values.summary = this.makerOptions.summary || this.makeOptions.packageJSON.description;
if (this.values.summary.length > 78) {
throw new Error('summary must be 78 characters or less');
}
return this.values.summary;
}
get description() {
return this.makerOptions.description || this.makeOptions.packageJSON.description;
}
get license() {
return this.makerOptions.license || this.makeOptions.packageJSON.license;
}
get icon() {
this.values.icon = this.makerOptions.icon || this.makeOptions.forgeConfig.packagerConfig.icon;
if (/\.png$/.test(this.values.icon) === false) {
this.values.icon += '.png';
}
if (path.isAbsolute(this.values.icon) === false) {
this.values.icon = path.join(process.cwd(), this.values.icon);
}
return this.values.icon;
}
get confinement() {
this.values.confinement = this.makerOptions.confinement || 'strict';
if (['strict', 'devmode', 'classic'].includes(this.values.confinement) === false) {
throw new Error('confinement must be either `strict`, `devmode` or `classic`');
}
return this.values.confinement;
}
get grade() {
this.values.grade = this.makerOptions.grade || 'stable';
if (['stable', 'devel'].includes(this.values.grade) === false) {
throw new Error('grade must be either `stable` or `devel`');
}
return this.values.grade;
}
get categories() {
return this.makerOptions.categories || [];
}
get stagePackages() {
this.values.stagePackages = this.makerOptions.stagePackages || SnapValues.defaultStagePackages;
if (this.values.stagePackages.includes('default')) {
this.values.stagePackages = [...this.values.stagePackages.filter(i => i !== 'default'),
...SnapValues.defaultStagePackages];
}
return this.values.stagePackages;
}
get plugs() {
this.values.plugs = this.makerOptions.plugs || SnapValues.defaultPlugs;
if (this.values.plugs.includes('default')) {
this.values.plugs = [...this.values.plugs.filter(i => i !== 'default'),
...SnapValues.defaultPlugs];
}
return this.values.plugs;
}
get layout() {
return this.makerOptions.layout;
}
_sanatizeExecutableName(name) {
const execName = name.toLowerCase().replace(/ /g, '-');
return execName.replace(/[^a-z\d\\-]/g, '');
}
}
SnapValues.defaultStagePackages = [
'libnss3',
'libnspr4',
'libasound2',
// See #21 'libgconf2-4',
// See #21 'libnotify4',
'libpcre3',
'libpulse0',
'libxss1',
'libxtst6'
];
SnapValues.defaultPlugs = [
'alsa',
'browser-support',
'desktop',
'desktop-legacy',
'gsettings',
'home',
'network',
'opengl',
'pulseaudio',
'unity7',
'wayland',
'x11'
];
module.exports = SnapValues;