plexus / chestnut

Application template for Clojure + ClojureScript web apps
Eclipse Public License 1.0
1.32k stars 99 forks source link

[Help] Tweaking the template to work with nodejs repl #222

Closed abhi18av closed 6 years ago

abhi18av commented 6 years ago

Hi guys,

I've been trying to get chestnut working with a nodejs-repl instead of a browser-replbut I'm lost in the configurations of cljsbuild . Could you help me achieve this ?

abhi18av commented 6 years ago

I've tweaked the cljsbuild section to include the following

         {:id "nodejs"
                :source-paths ["src/cljs" "src/cljc" "dev"]
                :compiler {:main cljs.user
                           :target :nodejs
                           :asset-path "js/compiled/out"
                           :output-to "resources/public/js/compiled/nodejs/nodejs.js"
                           :output-dir "resources/public/js/compiled/nodejs"
                           :source-map-timestamp true}}
abhi18av commented 6 years ago

I've started to work on a seperate branch with chestnut/master as base here https://github.com/abhi18av/devnagri-ui-tests/tree/node-repl

I've made progress with the configuration here

            {:id "nodejs"
                :source-paths ["src/nodejs" "src/cljc" ]
                :compiler {:main cljs.user
                           :target :nodejs
                           ;:asset-path "js/compiled/out"
                           :output-to "resources/public/js/compiled/nodejs/nodejs.js"
                           :output-dir "resources/public/js/compiled/nodejs"
                           :pretty-print true
                           :optimizations :simple
                           ;:optimizations :advanced :simple :whitespace :none
                           :parallel-build true
                           :npm-deps {"chalk" "2.1.0"}
                           :install-deps true
                           ;:source-map-timestamp true
                           ;:source-map true 
                           :warnings false}}

And the code in src/nodejs/devnagri_ui_tests/nodejs.cljs is as follows

(ns devnagri-ui-tests.nodejs
  (:require [clojure.string :as str]
            [cljs.nodejs :as nodejs]))

(nodejs/enable-util-print!)

(defn -main [& args]
  (-> (str/join " " args)
      (str/replace #"cker\b" "xor")
      (str/replace #"e|E" "3")
      (str/replace #"i|I" "1")
      (str/replace #"o|O" "0")
      (str/replace #"s|S" "5")
      (str/replace #"a|A" "4")
      (str/replace #"t|T" "7")
      (str/replace #"b|B" "6")
      (str/replace #"c|C" "(")
      println))

(set! *main-cli-fn* -main)

But running the node on the output doesn't print out anything at all

❯ npm test

> devnagri-ui-tests@1.0.0 test /Users/eklavya/Projects/ProjectEklavya/BlueCollar/devnagri-ui-tests
> /Users/eklavya/.nvm/versions/node/v8.1.3/bin/node resources/public/js/compiled/nodejs/nodejs.js

The expected output is as follows

$ l33t I am a leet hacker
1 4m 4 l337 h4x0r

This is taken from blog-post by plexus here https://lambdaisland.com/blog/02-05-2017-nodejs-scripts-clojurescript

featheredtoast commented 6 years ago

Hey there!

The one issue I was running into with your code specifically was that your version of clojurescript didn't seem to like compiling node. The following worked: [org.clojure/clojurescript "1.9.946" :scope "provided"].

Your cljs main should probably also be devnagri-ui-tests.nodejs:

{:id "nodejs"
                :source-paths ["src/nodejs" "src/cljc" ]
                :compiler {:main devnagri-ui-tests.nodejs
                           :target :nodejs
                           ;:asset-path "js/compiled/out"
                           :output-to "resources/public/js/compiled/nodejs/nodejs.js"
                           :output-dir "resources/public/js/compiled/nodejs"
                           :pretty-print true
                           :optimizations :simple
                           ;:optimizations :advanced :simple :whitespace :none
                           :parallel-build true
                           :npm-deps {"chalk" "2.1.0"}
                           :install-deps true
                           ;:source-map-timestamp true
                           ;:source-map true 
                           :warnings false}}

In the future, this kind of thing would be ideal to bring up in the mailing list or on the clojurian slack, not as an issue here.