-
Notifications
You must be signed in to change notification settings - Fork 51
post-install and dry #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
post-install and dry #168
Conversation
|
I think it's moving in the right direction. Recursively walking everything makes it more consistent, and loading everything up front for configs shouldn't be an issue. |
ef70769 to
5fd625b
Compare
|
Ok, pushed some changes. It turns out that we cannot do without a topological sort to handle dependencies that depend on one another, so that's another change to the existing logic. It's almost ready, give me a bit of time to test it more. I spent the most of the time I had today building support for previews to make developing kit modules easier (it'll be a separate PR). I'll try to carve out some time tomorrow to finalize manual tests. |
c181314 to
a36f344
Compare
<!-- ps-id: 61126e84-56d0-467a-a886-86b08bff4a78 -->
The commit ads post-install hooks, allowing to run scripts after module installs,
along with a framework for adding hooks in other places.
Example `config.edn`:
```edn
{:default {:hooks {:post-install ["echo hello"]}}}
```
When installing modules, it will prompt the user before executing a hook, as a
safety measure. You can type "all" to accept all hooks.
```
The following hook actions will be performed:
$ mv test/resources/generated/install.sh test/resources/generated/post-install.txt
Run the hook? (y/n/all):
```
You can also mute the prompt:
```clojure
(kit/install-module :html {:accept-hooks? true})
```
You can always set `:accept-hooks?` to false to skip all hooks.
<!-- ps-id: a1adadcf-5c40-46e7-b4b3-5b9d409cde51 -->
This commit moves I/O out of module dependency resoultion. Before the changes configs were loaded gradually as dependencies were resolved and `:feature-requires` and `:feature-flag`s were applied. Now everything is loaded and resolved in modules.clj, upfront. Dependency calculation is now a pure function. This is a substantial change, but I believe I haven't changed the logic. <!-- ps-id: 4d041d63-cd84-451b-a12d-b5f25c927564 -->
While installing modules, it will prompt the user before executing each hook, as a
safety measure. You can type "all" to accept all hooks.
```
The following hook actions will be performed:
$ mv test/resources/generated/install.sh test/resources/generated/post-install.txt
Run the hook? (y/n/all):
```
You can also mute the prompt:
```clojure
(kit/install-module :html {:accept-hooks? true})
```
You can always set `:accept-hooks?` to false to skip all hooks.
<!-- ps-id: 2a209106-f576-4ee4-8fe1-04c8e8f2428c -->
<!-- ps-id: eba192d3-88ab-440d-aa47-d83fea910c60 -->
Dry-run mode lets the user see the planned changes before applying them:
```
(kit.api/install-module :meta "test/resources/kit.edn" {:feature-flag :with-hooks
:dry? true
:db {:feature-flag :migrations}})
ALREADY INSTALLED (skipped)
:db
:hooks
INSTALLATION PLAN
:migratus
adds support for migrations
- create test/resources/generated/src/clj/myapp/db/migratus.clj
:meta @with-hooks
meta-module adding support for html and cljs
- create test/resources/generated/resources/public/css/styles.css
- modify test/resources/generated/resources/system.edn
- run post-install hook
SUMMARY
2 module(s) already installed (skipped)
2 module(s) to install
```
<!-- ps-id: 8ae0336a-27e4-4a95-b671-d18aecc78109 -->
<!-- ps-id: 57ca589f-e08b-4542-8b0d-55d14e954ff1 -->
a36f344 to
824bc1a
Compare
See if that's ok by you:
Caveats
list-moduleswill require minor changes. I plan to try to use the workflows in creation of the starter module I had mentioned. Tomorrow is the day I set aside for this.Post-install hooks
The PR ads post-install hooks, allowing to run scripts after module installs,
along with a framework for adding hooks in other places.
Example
config.edn:{:default {:hooks {:post-install ["echo hello"]}}}When installing modules, it will prompt the user before executing a hook, as a
safety measure. You can type "all" to accept all hooks.
You can also mute the prompt:
You can also set
:accept-hooks?to false to skip all hooks.Dry run mode
Dry-run mode lets the user see the planned changes before applying them:
Internal changes
These are quite extensive, unfortunately. To cleanly implement the hooks, I
decided to refactor the code so that the changes are planned before they are
applied. In particular, you know the list of modules to be installed, in the
particular order, along with their configurations after resolving
:feature-requiresand:feature-flag. This allows collecting hooks andexecuting them in the correct order.
Minor breaking changes
:feature-requires. It wasn't true for other fields, e.g. :actions After: All
config fields are resolved using the same algorithm, while handling cyclic
dependencies.
Everything is loaded and resolved in modules.clj, upfront. Dependency
calculation is now a pure function. This is a substantial change, but I
believe I haven't changed the logic.
Looking forward to your feedback. :)