11const builder = require ( 'electron-builder' )
2- const { preductname } = require ( './package.json' )
2+ const JavaScriptObfuscator = require ( 'javascript-obfuscator' ) ;
3+ const fs = require ( "fs" ) ;
4+ const { preductname, url } = require ( './package.json' )
35
6+ class Index {
7+ async init ( ) {
8+ this . obf = true
9+ process . argv . forEach ( val => {
10+ if ( val . startsWith ( '--obf' ) ) this . obf = JSON . parse ( val . split ( '=' ) [ 1 ] )
11+ } ) ;
12+ this . Fileslist = this . getFiles ( "src" ) ;
13+ await this . Obfuscate ( ) ;
14+ await this . build ( )
15+ }
16+
17+ async Obfuscate ( ) {
18+ if ( fs . existsSync ( "./app" ) ) fs . rmSync ( "./app" , { recursive : true } )
19+
20+ for ( let path of this . Fileslist ) {
21+ let fileName = path . split ( '/' ) . pop ( )
22+ let extFile = fileName . split ( "." ) . pop ( )
23+ let folder = path . replace ( `/${ fileName } ` , '' ) . replace ( 'src' , 'app' )
24+
25+ if ( ! fs . existsSync ( folder ) ) fs . mkdirSync ( folder , { recursive : true } )
26+
27+ if ( extFile == 'js' ) {
28+ let code = fs . readFileSync ( path , "utf8" ) ;
29+ code = code . replace ( / s r c \/ / g, 'app/' ) ;
30+ if ( this . obf ) {
31+ await new Promise ( ( resolve ) => {
32+ console . log ( `Obfuscate ${ path } ` ) ;
33+ let obf = JavaScriptObfuscator . obfuscate ( code , { optionsPreset : 'medium-obfuscation' } ) ;
34+ resolve ( fs . writeFileSync ( `${ folder } /${ fileName } ` , obf . getObfuscatedCode ( ) , { encoding : "utf-8" } ) ) ;
35+ } )
36+ } else {
37+ console . log ( `Copy ${ path } ` ) ;
38+ fs . writeFileSync ( `${ folder } /${ fileName } ` , code , { encoding : "utf-8" } ) ;
39+ }
40+ } else {
41+ fs . copyFileSync ( path , `${ folder } /${ fileName } ` ) ;
42+ }
43+ }
44+ }
45+
46+ async build ( ) {
47+ builder . build ( {
48+ config : {
49+ generateUpdatesFilesForAllChannels : false ,
50+ appId : preductname ,
51+ productName : preductname ,
52+ artifactName : "${productName}-${os}-${arch}.${ext}" ,
53+ extraMetadata : { main : 'app/app.js' } ,
54+ files : [ "app/**/*" , "package.json" , "LICENSE.md" ] ,
55+ directories : { "output" : "dist" } ,
56+ compression : 'maximum' ,
57+ asar : true ,
58+ publish : [ {
59+ provider : "github" ,
60+ releaseType : 'release' ,
61+ } ] ,
62+ win : {
63+ icon : "./app/assets/images/icon.ico" ,
64+ target : [ {
65+ target : "nsis" ,
66+ arch : [ "x64" ]
67+ } ] ,
68+ } ,
69+ nsis : {
70+ oneClick : true ,
71+ allowToChangeInstallationDirectory : false ,
72+ createDesktopShortcut : true ,
73+ runAfterFinish : true
74+ } ,
75+ mac : {
76+ icon : "./app/assets/images/icon.icns" ,
77+ category : "public.app-category.games" ,
78+ target : [ {
79+ target : "dmg" ,
80+ arch : [ "x64" , "arm64" ]
81+ } ]
82+ } ,
83+ linux : {
84+ icon : "./app/assets/images/icon.png" ,
85+ target : [ {
86+ target : "AppImage" ,
87+ arch : [ "x64" ]
88+ } , {
89+ target : "tar.gz" ,
90+ arch : [ "x64" ]
91+ } ]
92+ }
93+ }
94+ } ) . then ( ( ) => {
95+ console . log ( 'le build est terminé' )
96+ } ) . catch ( err => {
97+ console . error ( 'Error during build!' , err )
98+ } )
99+ }
4100
5- builder . build ( {
6- config : {
7- generateUpdatesFilesForAllChannels : true ,
8- appId : preductname ,
9- productName : preductname ,
10- artifactName : "${productName}-${os}-${arch}.${ext}" ,
11- files : [ "src/**/*" , "package.json" , "LICENSE.md" ] ,
12- directories : { "output" : "dist" } ,
13- compression : 'maximum' ,
14- asar : true ,
15- publish : [ {
16- provider : "github" ,
17- releaseType : 'release' ,
18- } ] ,
19- win : {
20- icon : "./src/assets/images/icon.ico" ,
21- target : [ {
22- target : "nsis" ,
23- arch : [ "x64" ]
24- } ] ,
25- } ,
26- nsis : {
27- oneClick : true ,
28- allowToChangeInstallationDirectory : false ,
29- createDesktopShortcut : true ,
30- runAfterFinish : true
31- } ,
32- mac : {
33- icon : "./src/assets/images/icon.icns" ,
34- category : "public.app-category.games" ,
35- target : [ {
36- target : "dmg" ,
37- arch : [ "x64" , "arm64" ]
38- } ]
39- } ,
40- linux : {
41- icon : "./src/assets/images/icon.png" ,
42- target : [ {
43- target : "AppImage" ,
44- arch : [ "x64" ]
45- } , {
46- target : "tar.gz" ,
47- arch : [ "x64" ]
48- } ]
101+ getFiles ( path , file = [ ] ) {
102+ if ( fs . existsSync ( path ) ) {
103+ let files = fs . readdirSync ( path ) ;
104+ if ( files . length == 0 ) file . push ( path ) ;
105+ for ( let i in files ) {
106+ let name = `${ path } /${ files [ i ] } ` ;
107+ if ( fs . statSync ( name ) . isDirectory ( ) )
108+ this . getFiles ( name , file ) ;
109+ else
110+ file . push ( name ) ;
111+ }
49112 }
113+ return file ;
50114 }
51- } ) . then ( ( ) => {
52- console . log ( 'le build est terminé' )
53- } ) . catch ( err => {
54- console . error ( 'Error during build!' , err )
55- } )
115+ }
116+ new Index ( ) . init ( ) ;
0 commit comments