|
4294 | 4294 | "Install a bundle from the local filesystem. The name of the bundle will be inferred from the bundle, or passed as a parameter :name in `config`."
|
4295 | 4295 | [path &keys config]
|
4296 | 4296 | (def path (bundle-rpath path))
|
4297 |
| - (def clean (get config :clean)) |
4298 |
| - (def check (get config :check)) |
4299 | 4297 | (def s (sep))
|
4300 |
| - # Check meta file for dependencies and default name |
4301 |
| - (def infofile-pre-1 (string path s "bundle" s "info.jdn")) |
4302 |
| - (def infofile-pre (if (fexists infofile-pre-1) infofile-pre-1 (string path s "info.jdn"))) # allow for alias |
4303 |
| - (var default-bundle-name nil) |
4304 |
| - (when (os/stat infofile-pre :mode) |
4305 |
| - (def info (-> infofile-pre slurp parse)) |
4306 |
| - (def deps (get info :dependencies @[])) |
4307 |
| - (set default-bundle-name (get info :name)) |
4308 |
| - (def missing (seq [d :in deps :when (not (bundle/installed? d))] (string d))) |
4309 |
| - (when (next missing) (errorf "missing dependencies %s" (string/join missing ", ")))) |
4310 |
| - (def bundle-name (get config :name default-bundle-name)) |
4311 |
| - (assertf bundle-name "unable to infer bundle name for %v, use :name argument" path) |
| 4298 | + # Detect bundle name |
| 4299 | + (def infofile-src1 (string path s "bundle" s "info.jdn")) |
| 4300 | + (def infofile-src2 (string path s "info.jdn")) |
| 4301 | + (def infofile-src (cond (fexists infofile-src1) infofile-src1 |
| 4302 | + (fexists infofile-src2) infofile-src2)) |
| 4303 | + (def info (-?> infofile-src slurp parse)) |
| 4304 | + (def bundle-name (get config :name (get info :name))) |
| 4305 | + (assertf bundle-name |
| 4306 | + "unable to infer bundle name for %v, use :name argument" path) |
4312 | 4307 | (assertf (not (string/check-set "\\/" bundle-name))
|
4313 | 4308 | "bundle name %v cannot contain path separators" bundle-name)
|
4314 |
| - (assert (next bundle-name) "cannot use empty bundle-name") |
| 4309 | + (assert (next bundle-name) |
| 4310 | + "cannot use empty bundle-name") |
4315 | 4311 | (assertf (not (fexists (get-manifest-filename bundle-name)))
|
4316 | 4312 | "bundle %v is already installed" bundle-name)
|
4317 | 4313 | # Setup installed paths
|
4318 | 4314 | (prime-bundle-paths)
|
4319 | 4315 | (os/mkdir (bundle-dir bundle-name))
|
4320 |
| - # Aliases for common bundle/ files |
4321 |
| - (def bundle.janet (string path s "bundle.janet")) |
4322 |
| - (when (fexists bundle.janet) (copyfile bundle.janet (bundle-file bundle-name "init.janet"))) |
4323 |
| - (when (fexists infofile-pre) (copyfile infofile-pre (bundle-file bundle-name "info.jdn"))) |
| 4316 | + # Copy infofile |
| 4317 | + (def infofile-dest (bundle-file bundle-name "info.jdn")) |
| 4318 | + (when infofile-src (copyfile infofile-src infofile-dest)) |
| 4319 | + # Copy initfile |
| 4320 | + (def initfile-alias (string path s "bundle.janet")) |
| 4321 | + (def initfile-dest (bundle-file bundle-name "init.janet")) |
| 4322 | + (when (fexists initfile-alias) (copyfile initfile-alias initfile-dest)) |
4324 | 4323 | # Copy some files into the new location unconditionally
|
4325 | 4324 | (def implicit-sources (string path s "bundle"))
|
4326 | 4325 | (when (= :directory (os/stat implicit-sources :mode))
|
4327 | 4326 | (copyrf implicit-sources (bundle-dir bundle-name)))
|
4328 | 4327 | (def man @{:name bundle-name :local-source path :files @[]})
|
4329 | 4328 | (merge-into man config)
|
4330 |
| - (def infofile (bundle-file bundle-name "info.jdn")) |
4331 |
| - (put man :auto-remove (get config :auto-remove)) |
4332 | 4329 | (sync-manifest man)
|
4333 | 4330 | (edefer (do (print "installation error, uninstalling") (bundle/uninstall bundle-name))
|
4334 |
| - (when (os/stat infofile :mode) |
4335 |
| - (def info (-> infofile slurp parse)) |
4336 |
| - (def deps (get info :dependencies @[])) |
4337 |
| - (def missing (filter (complement bundle/installed?) deps)) |
4338 |
| - (when (next missing) |
4339 |
| - (error (string "missing dependencies " (string/join missing ", ")))) |
4340 |
| - (put man :dependencies deps) |
4341 |
| - (put man :info info)) |
| 4331 | + (put man :info info) |
| 4332 | + (def deps (get config :dependencies @[])) |
| 4333 | + (def missing (filter (complement bundle/installed?) deps)) |
| 4334 | + (when (next missing) |
| 4335 | + (error (string "missing dependencies " (string/join missing ", ")))) |
4342 | 4336 | (def module (get-bundle-module bundle-name))
|
4343 | 4337 | (def all-hooks (seq [[k v] :pairs module :when (symbol? k) :unless (get v :private)] (keyword k)))
|
4344 | 4338 | (put man :hooks all-hooks)
|
4345 | 4339 | (do-hook module bundle-name :dependencies man)
|
4346 |
| - (when clean |
| 4340 | + (when (get config :clean) |
4347 | 4341 | (do-hook module bundle-name :clean man))
|
4348 | 4342 | (do-hook module bundle-name :build man)
|
4349 | 4343 | (do-hook module bundle-name :install man)
|
4350 | 4344 | (if (empty? (get man :files)) (print "no files installed, is this a valid bundle?"))
|
4351 | 4345 | (sync-manifest man)
|
4352 |
| - (when check |
| 4346 | + (when (get config :check) |
4353 | 4347 | (do-hook module bundle-name :check man)))
|
4354 | 4348 | (print "installed " bundle-name)
|
4355 | 4349 | (when (get man :has-bin-script)
|
|
0 commit comments