@@ -32,7 +32,7 @@ const defaultPlugs = ["desktop", "desktop-legacy", "home", "x11", "unity7", "bro
3232export default class SnapTarget extends Target {
3333 readonly options : SnapOptions = { ...this . packager . platformSpecificBuildOptions , ...( this . packager . config as any ) [ this . name ] }
3434
35- private isUsePrepackedSnap = true
35+ private isUseTemplateApp = false
3636
3737 constructor ( name : string , private readonly packager : LinuxPackager , private readonly helper : LinuxTargetHelper , readonly outDir : string ) {
3838 super ( name )
@@ -41,20 +41,14 @@ export default class SnapTarget extends Target {
4141 private replaceDefault ( inList : Array < string > | null | undefined , defaultList : Array < string > ) {
4242 const result = _replaceDefault ( inList , defaultList )
4343 if ( result !== defaultList ) {
44- this . isUsePrepackedSnap = false
44+ this . isUseTemplateApp = false
4545 }
4646 return result
4747 }
4848
49- async build ( appOutDir : string , arch : Arch ) : Promise < any > {
50- const packager = this . packager
51- const appInfo = packager . appInfo
49+ private createDescriptor ( snapName : string , appOutDir : string , isUseDocker : boolean ) : any {
50+ const appInfo = this . packager . appInfo
5251 const options = this . options
53- const snapName = packager . executableName . toLowerCase ( )
54- const buildPackages = asArray ( options . buildPackages )
55- const isUseDocker = process . platform !== "linux" || isEnvTrue ( process . env . SNAP_USE_DOCKER )
56- this . isUsePrepackedSnap = arch === Arch . x64 && buildPackages . length === 0
57-
5852 const snap : any = {
5953 name : snapName ,
6054 version : appInfo . version ,
@@ -64,7 +58,7 @@ export default class SnapTarget extends Target {
6458 grade : options . grade || "stable" ,
6559 apps : {
6660 [ snapName ] : {
67- command : `desktop-launch $SNAP/${ packager . executableName } ` ,
61+ command : `desktop-launch $SNAP/${ this . packager . executableName } ` ,
6862 environment : {
6963 TMPDIR : "$XDG_RUNTIME_DIR" ,
7064 ...options . environment ,
@@ -82,28 +76,39 @@ export default class SnapTarget extends Target {
8276 } ,
8377 }
8478
85- const wrapperFileName = `command-${ packager . executableName } .wrapper`
86- if ( this . isUsePrepackedSnap ) {
87- delete snap . parts
88- snap . apps [ snapName ] . command = wrapperFileName
79+ if ( options . assumes != null ) {
80+ snap . assumes = asArray ( options . assumes )
8981 }
82+ return snap
83+ }
9084
91- const snapFileName = `${ snap . name } _${ snap . version } _${ toLinuxArchString ( arch ) } .snap`
85+ async build ( appOutDir : string , arch : Arch ) : Promise < any > {
86+ const packager = this . packager
87+ const options = this . options
88+ const snapName = packager . executableName . toLowerCase ( )
89+ const buildPackages = asArray ( options . buildPackages )
90+ const isUseDocker = process . platform !== "linux" || isEnvTrue ( process . env . SNAP_USE_DOCKER )
91+ this . isUseTemplateApp = this . options . useTemplateApp !== false && arch === Arch . x64 && buildPackages . length === 0
92+
93+ const snapFileName = `${ snapName } _${ packager . appInfo . version } _${ toLinuxArchString ( arch ) } .snap`
9294 const artifactPath = path . join ( this . outDir , snapFileName )
9395 this . logBuilding ( "snap" , artifactPath , arch )
9496
95- if ( options . assumes != null ) {
96- snap . assumes = asArray ( options . assumes )
97+ const snap : any = this . createDescriptor ( snapName , appOutDir , isUseDocker )
98+ const wrapperFileName = `command-${ packager . executableName } .wrapper`
99+ if ( this . isUseTemplateApp ) {
100+ delete snap . parts
101+ snap . apps [ snapName ] . command = wrapperFileName
97102 }
98103
99104 const stageDir = await createStageDir ( this , packager , arch )
100105 // snapcraft.yaml inside a snap directory
101106 const snapDir = path . join ( stageDir . dir , "snap" )
102- const snapMetaDir = this . isUsePrepackedSnap ? path . join ( stageDir . dir , "meta" ) : snapDir
107+ const snapMetaDir = this . isUseTemplateApp ? path . join ( stageDir . dir , "meta" ) : snapDir
103108
104109 await this . helper . icons
105110 if ( this . helper . maxIconPath != null ) {
106- if ( ! this . isUsePrepackedSnap ) {
111+ if ( ! this . isUseTemplateApp ) {
107112 snap . icon = "snap/gui/icon.png"
108113 }
109114 await copyFile ( this . helper . maxIconPath , path . join ( snapMetaDir , "gui" , "icon.png" ) )
@@ -126,9 +131,9 @@ export default class SnapTarget extends Target {
126131 return
127132 }
128133
129- const snapcraftFile = path . join ( snapMetaDir , this . isUsePrepackedSnap ? "snap.yaml" : "snapcraft.yaml" )
134+ const snapcraftFile = path . join ( snapMetaDir , this . isUseTemplateApp ? "snap.yaml" : "snapcraft.yaml" )
130135 await outputFile ( snapcraftFile , serializeToYaml ( snap ) )
131- if ( this . isUsePrepackedSnap ) {
136+ if ( this . isUseTemplateApp ) {
132137 // noinspection SpellCheckingInspection
133138 await writeFile ( path . join ( stageDir . dir , wrapperFileName ) , `#!/bin/sh
134139export PATH="$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH"
@@ -146,7 +151,7 @@ exec "desktop-launch" "$SNAP/${packager.executableName}" "$@"
146151 }
147152
148153 if ( isUseDocker ) {
149- if ( this . isUsePrepackedSnap ) {
154+ if ( this . isUseTemplateApp ) {
150155 await this . buildUsingDockerAndPrepackedSnap ( snapFileName , stageDir )
151156 }
152157 else {
@@ -178,7 +183,7 @@ exec "desktop-launch" "$SNAP/${packager.executableName}" "$@"
178183 }
179184
180185 let primeDir : string
181- if ( this . isUsePrepackedSnap ) {
186+ if ( this . isUseTemplateApp ) {
182187 primeDir = stageDir
183188 }
184189 else {
0 commit comments