@@ -31,10 +31,10 @@ def cli():
31
31
pass
32
32
33
33
34
- @cli .command ()
35
- def init ():
36
- """Create a new applecrate project."""
37
- echo ("Creating a new applecrate project." )
34
+ # @cli.command()
35
+ # def init():
36
+ # """Create a new applecrate project."""
37
+ # echo("Creating a new applecrate project.")
38
38
39
39
40
40
# @cli.command()
@@ -104,6 +104,16 @@ def init():
104
104
"will install the file 'dist/app' to '/usr/local/bin/app-1.0.0' "
105
105
"if --app=app and --version=1.0.0." ,
106
106
)
107
+ @click .option (
108
+ "--link" ,
109
+ "-k" ,
110
+ metavar = "SRC TARGET" ,
111
+ nargs = 2 ,
112
+ multiple = True ,
113
+ help = "Create a symbolic link from SRC to DEST after installation. "
114
+ "SRC and TARGET must be absolute paths and both may include template variables {{ app }} and {{ version }}. "
115
+ 'For example: `--link "/Library/Application Support/{{ app }}/{{ version }}/app" "/usr/local/bin/{{ app }}-{{ version }}"` ' ,
116
+ )
107
117
@click .option (
108
118
"--post-install" ,
109
119
"-p" ,
@@ -136,6 +146,7 @@ def build(**kwargs):
136
146
no_uninstall = kwargs ["no_uninstall" ]
137
147
url = kwargs ["url" ]
138
148
install = kwargs ["install" ]
149
+ link = kwargs ["link" ]
139
150
license = kwargs ["license" ]
140
151
banner = kwargs ["banner" ]
141
152
post_install = kwargs ["post_install" ]
@@ -148,6 +159,8 @@ def build(**kwargs):
148
159
"url" : url ,
149
160
"install" : install ,
150
161
"banner" : banner ,
162
+ "link" : link ,
163
+ "post_install" : post_install ,
151
164
}
152
165
153
166
echo (f"Building installer package for { app } version { version } ." )
@@ -182,16 +195,25 @@ def build(**kwargs):
182
195
pathlib .Path (target ).chmod (0o755 )
183
196
echo (f"Created { target } " )
184
197
185
- echo ("Creating post-install script " )
198
+ echo ("Creating post-install scripts " )
186
199
target = BUILD_DIR / "scripts" / "postinstall"
187
- if post_install :
188
- copy_and_create_parents (post_install , target )
189
- else :
190
- template = get_template ("postinstall" )
191
- render_template (template , data , target )
200
+ template = get_template ("postinstall" )
201
+ render_template (template , data , target )
192
202
pathlib .Path (target ).chmod (0o755 )
193
203
echo (f"Created { target } " )
194
204
205
+ target = BUILD_DIR / "scripts" / "links"
206
+ template = get_template ("links" )
207
+ render_template (template , data , target )
208
+ pathlib .Path (target ).chmod (0o755 )
209
+ echo (f"Created { target } " )
210
+
211
+ if post_install :
212
+ target = BUILD_DIR / "scripts" / "postinstall_user"
213
+ copy_and_create_parents (post_install , target )
214
+ pathlib .Path (target ).chmod (0o755 )
215
+ echo (f"Created { target } " )
216
+
195
217
if banner :
196
218
echo ("Copying banner image" )
197
219
target = BUILD_DIR / "Resources" / "banner.png"
@@ -226,6 +248,16 @@ def render_build_kwargs(kwargs: dict[str, Any]) -> dict[str, Any]:
226
248
dest = pathlib .Path (template .render (app = app , version = version ))
227
249
new_install .append ((src , dest ))
228
250
rendered ["install" ] = new_install
251
+
252
+ if link := rendered .get ("link" ):
253
+ new_link = []
254
+ for src , target in link :
255
+ src_template = Template (str (src ))
256
+ target_template = Template (str (target ))
257
+ src = pathlib .Path (src_template .render (app = app , version = version ))
258
+ target = pathlib .Path (target_template .render (app = app , version = version ))
259
+ new_link .append ((src , target ))
260
+ rendered ["link" ] = new_link
229
261
return rendered
230
262
231
263
@@ -276,6 +308,18 @@ def validate_build_kwargs(**kwargs):
276
308
pathlib_install .append ((src , dest ))
277
309
kwargs ["install" ] = pathlib_install
278
310
311
+ if link := kwargs .get ("link" ):
312
+ pathlib_link = []
313
+ for src , target in link :
314
+ src = pathlib .Path (src )
315
+ target = pathlib .Path (target )
316
+ if not src .is_absolute ():
317
+ raise ValueError (f"Link source { src } must be an absolute path" )
318
+ if not target .is_absolute ():
319
+ raise ValueError (f"Link target { target } must be an absolute path" )
320
+ pathlib_link .append ((src , target ))
321
+ kwargs ["link" ] = pathlib_link
322
+
279
323
if banner := kwargs .get ("banner" ):
280
324
banner = pathlib .Path (banner )
281
325
if banner .suffix .lower () != ".png" :
0 commit comments