FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
atom/script/lib/install-application.js at master · SamB/atom · GitHub
SamB
/
atom
Public
forked from
atom/atom
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
atom
/
script
/
lib
/
install-application.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
234 lines (216 loc) · 7.34 KB
Breadcrumbs
atom
/
script
/
lib
/
install-application.js
Copy path
File metadata and controls
234 lines (216 loc) · 7.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
'use strict'
;
const
fs
=
require
(
'fs-extra'
)
;
const
handleTilde
=
require
(
'./handle-tilde'
)
;
const
path
=
require
(
'path'
)
;
const
template
=
require
(
'lodash.template'
)
;
const
startCase
=
require
(
'lodash.startcase'
)
;
const
execSync
=
require
(
'child_process'
)
.
execSync
;
const
CONFIG
=
require
(
'../config'
)
;
function
install
(
installationDirPath
,
packagedAppFileName
,
packagedAppPath
)
{
if
(
fs
.
existsSync
(
installationDirPath
)
)
{
console
.
log
(
`Removing previously installed "
${
packagedAppFileName
}
" at "
${
installationDirPath
}
"`
)
;
fs
.
removeSync
(
installationDirPath
)
;
}
console
.
log
(
`Installing "
${
packagedAppFileName
}
" at "
${
installationDirPath
}
"`
)
;
fs
.
copySync
(
packagedAppPath
,
installationDirPath
)
;
}
/**
* Finds the path to the base directory of the icon default icon theme
* This follows the freedesktop Icon Theme Specification:
* https://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html#install_icons
* and the XDG Base Directory Specification:
* https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
*/
function
findBaseIconThemeDirPath
(
)
{
const
defaultBaseIconThemeDir
=
'/usr/share/icons/hicolor'
;
const
dataDirsString
=
process
.
env
.
XDG_DATA_DIRS
;
if
(
dataDirsString
)
{
const
dataDirs
=
dataDirsString
.
split
(
path
.
delimiter
)
;
if
(
dataDirs
.
includes
(
'/usr/share/'
)
||
dataDirs
.
includes
(
'/usr/share'
)
)
{
return
defaultBaseIconThemeDir
;
}
else
{
return
path
.
join
(
dataDirs
[
0
]
,
'icons'
,
'hicolor'
)
;
}
}
else
{
return
defaultBaseIconThemeDir
;
}
}
module
.
exports
=
function
(
packagedAppPath
,
installDir
)
{
const
packagedAppFileName
=
path
.
basename
(
packagedAppPath
)
;
if
(
process
.
platform
===
'darwin'
)
{
const
installPrefix
=
installDir
!==
''
?
handleTilde
(
installDir
)
:
path
.
join
(
path
.
sep
,
'Applications'
)
;
const
installationDirPath
=
path
.
join
(
installPrefix
,
packagedAppFileName
)
;
install
(
installationDirPath
,
packagedAppFileName
,
packagedAppPath
)
;
}
else
if
(
process
.
platform
===
'win32'
)
{
const
installPrefix
=
installDir
!==
''
?
installDir
:
process
.
env
.
LOCALAPPDATA
;
const
installationDirPath
=
path
.
join
(
installPrefix
,
packagedAppFileName
,
'app-dev'
)
;
try
{
install
(
installationDirPath
,
packagedAppFileName
,
packagedAppPath
)
;
}
catch
(
e
)
{
console
.
log
(
`Administrator elevation required to install into "
${
installationDirPath
}
"`
)
;
const
fsAdmin
=
require
(
'fs-admin'
)
;
return
new
Promise
(
(
resolve
,
reject
)
=>
{
fsAdmin
.
recursiveCopy
(
packagedAppPath
,
installationDirPath
,
error
=>
{
error
?
reject
(
error
)
:
resolve
(
)
;
}
)
;
}
)
;
}
}
else
{
const
atomExecutableName
=
CONFIG
.
channel
===
'stable'
?
'atom'
:
'atom-'
+
CONFIG
.
channel
;
const
apmExecutableName
=
CONFIG
.
channel
===
'stable'
?
'apm'
:
'apm-'
+
CONFIG
.
channel
;
const
appName
=
CONFIG
.
channel
===
'stable'
?
'Atom'
:
startCase
(
'Atom '
+
CONFIG
.
channel
)
;
const
appDescription
=
CONFIG
.
appMetadata
.
description
;
const
prefixDirPath
=
installDir
!==
''
?
handleTilde
(
installDir
)
:
path
.
join
(
'/usr'
,
'local'
)
;
const
shareDirPath
=
path
.
join
(
prefixDirPath
,
'share'
)
;
const
installationDirPath
=
path
.
join
(
shareDirPath
,
atomExecutableName
)
;
const
applicationsDirPath
=
path
.
join
(
shareDirPath
,
'applications'
)
;
const
binDirPath
=
path
.
join
(
prefixDirPath
,
'bin'
)
;
fs
.
mkdirpSync
(
applicationsDirPath
)
;
fs
.
mkdirpSync
(
binDirPath
)
;
install
(
installationDirPath
,
packagedAppFileName
,
packagedAppPath
)
;
{
// Install icons
const
baseIconThemeDirPath
=
findBaseIconThemeDirPath
(
)
;
const
fullIconName
=
atomExecutableName
+
'.png'
;
let
existingIconsFound
=
false
;
fs
.
readdirSync
(
baseIconThemeDirPath
)
.
forEach
(
size
=>
{
const
iconPath
=
path
.
join
(
baseIconThemeDirPath
,
size
,
'apps'
,
fullIconName
)
;
if
(
fs
.
existsSync
(
iconPath
)
)
{
if
(
!
existingIconsFound
)
{
console
.
log
(
`Removing existing icons from "
${
baseIconThemeDirPath
}
"`
)
;
}
existingIconsFound
=
true
;
fs
.
removeSync
(
iconPath
)
;
}
}
)
;
console
.
log
(
`Installing icons at "
${
baseIconThemeDirPath
}
"`
)
;
const
appIconsPath
=
path
.
join
(
CONFIG
.
repositoryRootPath
,
'resources'
,
'app-icons'
,
CONFIG
.
channel
,
'png'
)
;
fs
.
readdirSync
(
appIconsPath
)
.
forEach
(
imageName
=>
{
if
(
/
\.
p
n
g
$
/
.
test
(
imageName
)
)
{
const
size
=
path
.
basename
(
imageName
,
'.png'
)
;
const
iconPath
=
path
.
join
(
appIconsPath
,
imageName
)
;
fs
.
copySync
(
iconPath
,
path
.
join
(
baseIconThemeDirPath
,
`
${
size
}
x
${
size
}
`
,
'apps'
,
fullIconName
)
)
;
}
}
)
;
console
.
log
(
`Updating icon cache for "
${
baseIconThemeDirPath
}
"`
)
;
try
{
execSync
(
`gtk-update-icon-cache
${
baseIconThemeDirPath
}
--force`
)
;
}
catch
(
e
)
{
}
}
{
// Install xdg desktop file
const
desktopEntryPath
=
path
.
join
(
applicationsDirPath
,
`
${
atomExecutableName
}
.desktop`
)
;
if
(
fs
.
existsSync
(
desktopEntryPath
)
)
{
console
.
log
(
`Removing existing desktop entry file at "
${
desktopEntryPath
}
"`
)
;
fs
.
removeSync
(
desktopEntryPath
)
;
}
console
.
log
(
`Writing desktop entry file at "
${
desktopEntryPath
}
"`
)
;
const
desktopEntryTemplate
=
fs
.
readFileSync
(
path
.
join
(
CONFIG
.
repositoryRootPath
,
'resources'
,
'linux'
,
'atom.desktop.in'
)
)
;
const
desktopEntryContents
=
template
(
desktopEntryTemplate
)
(
{
appName
,
appFileName
:
atomExecutableName
,
description
:
appDescription
,
installDir
:
prefixDirPath
,
iconPath
:
atomExecutableName
}
)
;
fs
.
writeFileSync
(
desktopEntryPath
,
desktopEntryContents
)
;
}
{
// Add atom executable to the PATH
const
atomBinDestinationPath
=
path
.
join
(
binDirPath
,
atomExecutableName
)
;
if
(
fs
.
existsSync
(
atomBinDestinationPath
)
)
{
console
.
log
(
`Removing existing executable at "
${
atomBinDestinationPath
}
"`
)
;
fs
.
removeSync
(
atomBinDestinationPath
)
;
}
console
.
log
(
`Copying atom.sh to "
${
atomBinDestinationPath
}
"`
)
;
fs
.
copySync
(
path
.
join
(
CONFIG
.
repositoryRootPath
,
'atom.sh'
)
,
atomBinDestinationPath
)
;
}
{
// Link apm executable to the PATH
const
apmBinDestinationPath
=
path
.
join
(
binDirPath
,
apmExecutableName
)
;
try
{
fs
.
lstatSync
(
apmBinDestinationPath
)
;
console
.
log
(
`Removing existing executable at "
${
apmBinDestinationPath
}
"`
)
;
fs
.
removeSync
(
apmBinDestinationPath
)
;
}
catch
(
e
)
{
}
console
.
log
(
`Symlinking apm to "
${
apmBinDestinationPath
}
"`
)
;
fs
.
symlinkSync
(
path
.
join
(
'..'
,
'share'
,
atomExecutableName
,
'resources'
,
'app'
,
'apm'
,
'node_modules'
,
'.bin'
,
'apm'
)
,
apmBinDestinationPath
)
;
}
console
.
log
(
`Changing permissions to 755 for "
${
installationDirPath
}
"`
)
;
fs
.
chmodSync
(
installationDirPath
,
'755'
)
;
}
return
Promise
.
resolve
(
)
;
}
;
Back
|
FazBrowse Home
|
New Git URL