added shadow-cljs compilation to generate a js artifact

This commit is contained in:
dmitri.sotnikov@gmail.com 2020-02-27 20:23:48 -05:00
parent 72f85c1a51
commit 820cd2be82
4 changed files with 37 additions and 27 deletions

View file

@ -198,5 +198,29 @@
(exit-with-error (exit-with-error
(str "failed to connect to Tumblr account " account ": " (.-message e)))))) (str "failed to connect to Tumblr account " account ": " (.-message e))))))
(defn rss-parser [] (defn main []
(rss.)) (get-mastodon-timeline
(fn [timeline]
(let [last-post-time (-> timeline first :created_at (js/Date.))]
;;post from Twitter
(when-let [twitter-config (:twitter config)]
(let [{:keys [access-keys accounts include-replies? include-rts?]} twitter-config
client (twitter-client access-keys)]
(doseq [account accounts]
(.get client
"statuses/user_timeline"
#js {:screen_name account
:tweet_mode "extended"
:include_rts (boolean include-rts?)
:exclude_replies (not (boolean include-replies?))}
(post-tweets last-post-time)))))
;;post from Tumblr
(when-let [{:keys [access-keys accounts limit]} (:tumblr config)]
(doseq [account accounts]
(let [client (tumblr-client access-keys account)]
(.posts client #js {:limit (or limit 5)} (post-tumblrs last-post-time)))))
;;post from RSS
(when-let [feeds (some-> config :rss)]
(let [parser (rss.)]
(doseq [feed feeds]
(parse-feed last-post-time parser feed))))))))

View file

@ -4,28 +4,6 @@
(:require (:require
[mastodon-bot.core :as core])) [mastodon-bot.core :as core]))
(core/get-mastodon-timeline (core/main)
(fn [timeline]
(let [last-post-time (-> timeline first :created_at (js/Date.))]
;;post from Twitter
(when-let [twitter-config (:twitter core/config)]
(let [{:keys [access-keys accounts include-replies? include-rts?]} twitter-config
client (core/twitter-client access-keys)]
(doseq [account accounts]
(.get client
"statuses/user_timeline"
#js {:screen_name account
:tweet_mode "extended"
:include_rts (boolean include-rts?)
:exclude_replies (not (boolean include-replies?))}
(core/post-tweets last-post-time)))))
;;post from Tumblr
(when-let [{:keys [access-keys accounts limit tumblr-oauth]} (:tumblr core/config)]
(doseq [account accounts]
(let [client (core/tumblr-client access-keys account)]
(.posts client #js {:limit (or limit 5)} (core/post-tumblrs last-post-time)))))
;;post from RSS
(when-let [feeds (some-> core/config :rss)]
(let [parser (core/rss-parser)]
(doseq [feed feeds]
(core/parse-feed last-post-time parser feed)))))))

View file

@ -12,6 +12,9 @@
"deasync": "0.1.15", "deasync": "0.1.15",
"request": "2.88.0" "request": "2.88.0"
}, },
"devDependencies": {
"shadow-cljs": "^2.8.37"
},
"scripts": { "scripts": {
"start": "./mastodon_bot/main.cljs", "start": "./mastodon_bot/main.cljs",
"test": "MASTODON_BOT_CONFIG=test.edn ./mastodon_bot/core_test.cljs" "test": "MASTODON_BOT_CONFIG=test.edn ./mastodon_bot/core_test.cljs"

5
shadow-cljs.edn Normal file
View file

@ -0,0 +1,5 @@
{:source-paths ["mastodon_bot"]
:dependencies []
:builds {:app {:target :node-script
:output-to "target/mastodon-bot.js"
:main mastodon-bot.core/main}}}