11#!/usr/bin/env node
22
3+ const fs = require ( 'fs' ) ;
34var yargs = require ( 'yargs' ) ;
5+ var nativefier = require ( 'nativefier' ) . default ;
6+ var process = require ( 'process' ) ;
7+ const request = require ( 'request' )
8+
9+
410const {
511 exec
612} = require ( "child_process" ) ;
13+
14+ var blankstr = ""
15+
16+
717console . log ( __dirname ) ;
18+ const dirname = __dirname ;
19+ var style = blankstr . concat ( __dirname , "/style.css" ) ;
20+ console . log ( style )
21+
822var argv = require ( 'yargs/yargs' ) ( process . argv . slice ( 2 ) )
923 . usage ( 'Make executable AppImages from any Website URL\n\nUsage: $0 [options]' )
1024 . help ( 'help' ) . alias ( 'help' , 'h' )
11- . version ( 'version' , '1.2 .0' ) . alias ( 'version' , 'V' )
25+ . version ( 'version' , '1.3 .0' ) . alias ( 'version' , 'V' )
1226 . options ( {
1327 name : {
1428 alias : 'n' ,
@@ -76,15 +90,28 @@ var argv = require('yargs/yargs')(process.argv.slice(2))
7690 } )
7791 . argv ;
7892
79- var blankstr = ""
8093
8194str = argv . name
8295var name = str . replace ( / \s + / g, '-' )
8396
84- var url = blankstr . concat ( '"' , argv . url , '"' )
97+ var url = argv . url
98+
99+ var appnativefydir = blankstr . concat ( process . env [ 'HOME' ] , "/appnativefy" ) ;
100+ console . log ( appnativefydir ) ;
101+ try {
102+ if ( ! fs . existsSync ( appnativefydir ) ) {
103+ fs . mkdirSync ( appnativefydir ) ;
104+ console . log ( "Directory is created." ) ;
105+ } else {
106+ console . log ( "Directory already exists." ) ;
107+ }
108+ } catch ( err ) {
109+ console . log ( err ) ;
110+ }
111+
85112
86113if ( argv . arch === undefined ) {
87- arch = "x64" ;
114+ var arch = "x64" ;
88115} else {
89116 var arch = argv . arch
90117}
@@ -96,7 +123,7 @@ if (argv.appCopyright === undefined) {
96123}
97124
98125if ( argv . appVersion === undefined ) {
99- var appversion = "" ;
126+ var appversion = "1.0.0 " ;
100127} else {
101128 var appversion = blankstr . concat ( "--app-version" , " " , '"' , argv . appVersion , '"' )
102129}
@@ -107,66 +134,79 @@ if (argv.electronVersion === undefined) {
107134 var electronversion = blankstr . concat ( "--electron-version" , " " , '"' , argv . electronVersion , '"' )
108135}
109136
110- var inject = "--inject style.css"
111137
112138if ( argv . widevine === true ) {
113- var widevine = "--widevine" ;
139+ var widevine = true
114140} else {
115- var widevine = ""
141+ var widevine = false
116142}
117143
144+ const download = ( favicongen , icon , callback ) => {
145+ request . head ( favicongen , ( err , res , body ) => {
146+ request ( favicongen )
147+ . pipe ( fs . createWriteStream ( icon ) )
148+ . on ( 'close' , callback )
149+ } )
150+ }
151+
118152if ( argv . favicon === true ) {
119- var favicongen = blankstr . concat ( " && wget " , '"' , "https://www.google.com/s2/favicons?sz=64&domain_url=" , argv . url , '"' , " " , "-O icon.png " ) ;
120- var icon = '--icon "icon.png"'
153+ var favicongen = blankstr . concat ( "https://www.google.com/s2/favicons?sz=64&domain_url=" , argv . url ) ;
154+ var icon = appnativefydir . concat ( "/icon.png" ) ;
155+ var customicon = blankstr . concat ( '"' , icon , '"' )
156+ download ( favicongen , icon , ( ) => {
157+ console . log ( '✅ Done!' )
158+ } )
121159} else {
122160 var favicongen = ""
123161 var icon = ""
124162}
125163
126164if ( argv . services === true ) {
127- var services = '--user-agent "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0"' ;
165+ var honest = false
166+ var services = '"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0"' ;
128167 if ( argv . internalurls === undefined ) {
129- var internalurls = '--internal-urls " (.*)" ' ;
168+ var internalurls = '(.*)' ;
130169 } else {
131- var internalurls = blankstr . concat ( "--internal-urls" , " " , argv . internalurls )
170+ var internalurls = argv . internalurls
132171 }
133172} else {
134- var services = "--honest"
173+ var honest = true
174+ var services = ""
135175 if ( argv . internalurls === undefined ) {
136- var internalurls = "" ;
176+ var internalurls = ".*? " ;
137177 } else {
138- var internalurls = blankstr . concat ( "--internal-urls" , " " , argv . internalurls )
178+ var internalurls = argv . internalurls
139179 }
140- }
180+ }
141181
142182if ( argv . saveAs === true ) {
143- var downloaddialog = '--file-download-options \'{"saveAs": true}\'' ;
183+ var downloaddialog = true ;
144184} else {
145- var downloaddialog = "" ;
185+ var downloaddialog = false ;
146186}
147187
148188if ( argv . noOverwrite === true ) {
149- var nooverwrite = '--no-overwrite "true"' ;
189+ var overwrite = false ;
150190} else {
151- var nooverwrite = ""
191+ var overwrite = true
152192}
153193
154194if ( argv . conceal === true ) {
155- var conceal = "--conceal" ;
195+ var conceal = true ;
156196} else {
157- var conceal = ""
197+ var conceal = false
158198}
159199
160200if ( argv . counter === true ) {
161- var counter = "--counter" ;
201+ var counter = true ;
162202} else {
163- var counter = ""
203+ var counter = false
164204}
165205
166206if ( argv . singleinstance === true ) {
167- var singleinstance = "--single-instance" ;
207+ var singleinstance = true ;
168208} else {
169- var singleinstance = ""
209+ var singleinstance = false
170210}
171211
172212
@@ -177,46 +217,106 @@ console.log("url:", url);
177217console . log ( "app copyright:" , argv . appCopyright ) ;
178218console . log ( "app version:" , argv . appVersion ) ;
179219console . log ( "electron version:" , argv . electronVersion ) ;
180- console . log ( "widevine support:" , argv . widevine ) ;
220+ console . log ( "widevine support:" , widevine ) ;
181221console . log ( "services:" , argv . services ) ;
182222console . log ( "internal urls:" , argv . internalurls )
183223console . log ( "no overwrite:" , argv . noOverwrite ) ;
184224console . log ( "conceal:" , argv . conceal ) ;
185225console . log ( "counter:" , argv . counter ) ;
186226console . log ( "single instance:" , argv . singleinstance )
187- console . log ( "css/js injection:" , inject ) ;
188-
189- var npxnativefier = blankstr . concat ( "mkdir -p ~/appnativefy && cd ~/appnativefy && mkdir -p .appimage-temp" , " " , favicongen , " && " , __dirname , "/node_modules/nativefier/lib/cli.js" )
190-
191- ///var commandvariable = npxnativefier.concat(" ", '"', url, '"', " ", "--name", " ", '"', name, '"', " ", widevine, " ", services, " ", singleinstance, " ", inject, " ");
192-
193- var commandvariable = npxnativefier . concat ( " " , url , " " , "--name" , " " , '"' , name , '"' , " " , icon , " " , appcopyright , " " , appversion , " " , electronversion , " " , downloaddialog , " " , widevine , " " , services , " " , internalurls , " " , nooverwrite , " " , conceal , " " , counter , " " , singleinstance , " " , inject , " " )
194-
195- console . log ( commandvariable ) ;
196-
197- var appimage = " rm style.css && rm -rf icon.png && "
198- var appimagescript = appimage . concat ( " sh script.sh" , " " , name , " " )
199-
200- var almostfinalvar = commandvariable . concat ( '&&' , appimagescript , ' && rm -r ~/appnativefy/.appimage-temp' , ' && rm -r ~/appnativefy/script.sh ' )
227+ console . log ( "css/js injection:" , style ) ;
228+
229+ var options = {
230+ name : name , // will be inferred if not specified
231+ targetUrl : url , // required
232+ platform : 'linux' , // defaults to the current system
233+ arch : 'x64' , // defaults to the current system
234+ version : appversion ,
235+ icon : customicon ,
236+ out : appnativefydir ,
237+ overwrite : overwrite ,
238+ asar : conceal , // see conceal
239+ counter : counter ,
240+ bounce : false ,
241+ width : 1280 ,
242+ height : 800 ,
243+ showMenuBar : false ,
244+ fastQuit : false ,
245+ userAgent : services , // will infer a default for your current system
246+ ignoreCertificate : false ,
247+ ignoreGpuBlacklist : false ,
248+ enableEs3Apis : false ,
249+ internalUrls : internalurls , // defaults to URLs on same second-level domain as app
250+ blockExternalUrls : true ,
251+ insecure : false ,
252+ honest : honest ,
253+ widevine : widevine ,
254+ zoom : 1.0 ,
255+ singleInstance : singleinstance ,
256+ verbose : true ,
257+ clearCache : false ,
258+ fileDownloadOptions : {
259+ saveAs : downloaddialog , // always show "Save As" dialog
260+ } ,
261+ } ;
262+
263+ nativefier ( options , function ( error , appPath ) {
264+ if ( error ) {
265+ console . error ( error ) ;
266+ return ;
267+ }
268+ console . log ( 'App has been nativefied to' , appPath ) ;
269+ var apptempdir = appnativefydir . concat ( "/.appimage-temp" ) ;
270+ var appimagetooldir = appnativefydir . concat ( "/.appimagetool" ) ;
271+
272+ console . log ( appnativefydir ) ;
273+ try {
274+ if ( ! fs . existsSync ( apptempdir ) ) {
275+ fs . mkdirSync ( apptempdir ) ;
276+ } else {
277+ }
278+ } catch ( err ) {
279+ console . log ( err ) ;
201280
202- var downloads = blankstr . concat ( "mkdir -p ~/appnativefy && cd ~/appnativefy && mkdir -p .appimage-temp && cp" , " " , __dirname , "/style.css style.css && cp" , " " , __dirname , "/script.sh script.sh" )
281+ }
282+ try {
283+ if ( ! fs . existsSync ( appimagetooldir ) ) {
284+ fs . mkdirSync ( appimagetooldir ) ;
285+ } else {
286+ }
287+ } catch ( err ) {
288+ console . log ( err ) ;
203289
204- var endofscript = blankstr . concat ( "echo " , '"' , "AppImage built to ~/appnativefy/" , name , "-x86_64.AppImage" , '"' )
290+ }
291+ var oldPath = appnativefydir . concat ( "/" , name , "-linux-x64" )
292+ var newPath = apptempdir . concat ( "/" , name , ".AppDir" )
205293
206- var finalvar = blankstr . concat ( downloads , " " , "&&" , " " , almostfinalvar , " " , "&&" , " " , endofscript )
294+ fs . rename ( oldPath , newPath , function ( err ) {
295+ if ( err ) throw err
296+ console . log ( 'Successfully moved file.' )
297+ } )
298+ var scriptsource = blankstr . concat ( __dirname , "/script.sh" )
299+ var scriptout = blankstr . concat ( appnativefydir , "/.script.sh" )
300+ fs . copyFile ( scriptsource , scriptout , ( err ) => {
301+ if ( err ) throw err ;
302+ console . log ( scriptsource , 'was copied to' , scriptout ) ;
303+ process . chdir ( appnativefydir ) ;
304+ commandscript = blankstr . concat ( "chmod 755 ~/appnativefy/.script.sh && ~/appnativefy/.script.sh" , " " , name , " " , dirname , " " , "&& rm -rf ~/appnativefy/.script.sh && rm -rf ~/appnativefy/.icon.png" )
305+ {
306+ exec ( commandscript , ( error , stdout , stderr ) => {
307+ if ( error ) {
308+ console . log ( `error: ${ error . message } ` ) ;
309+ return ;
310+ }
311+ if ( stderr ) {
312+ console . log ( `stderr: ${ stderr } ` ) ;
313+ return ;
314+ }
315+ console . log ( `stdout: ${ stdout } ` ) ;
316+ } ) ;
317+ } ;
318+ } ) ;
319+
207320
208321
209- exec ( finalvar , ( error , stdout , stderr ) => {
210- if ( error ) {
211- console . log ( `error: ${ error . message } ` ) ;
212- return ;
213- }
214- if ( stderr ) {
215- console . log ( `stderr: ${ stderr } ` ) ;
216- return ;
217- }
218- console . log ( `stdout: ${ stdout } ` ) ;
219322} ) ;
220-
221- var trueendofscript = blankstr . concat ( "AppImage building to ~/appnativefy/" , name , "-x86_64.AppImage" )
222- console . log ( trueendofscript ) ;
0 commit comments