Back

make-parents (clj)

(source)

function

(make-parents f & more)
Given the same arg(s) as for file, creates all parent directories of the file they represent.

Examples

jepsen-io/jepsen
(ns jepsen.report
  "Prints out stuff."
  (:require [jepsen.util :as util]
            [clojure.java.io :as io]
            [clojure.pprint :refer [pprint]]))

(defmacro to
  "Binds stdout to a file for the duration of body."
  [filename & body]
  `(let [filename# ~filename]
    (io/make-parents filename#)
    (with-open [w# (io/writer filename#)]
      (try
        (binding [*out* w#] ~@body)
        (finally
          (println "Report written to" filename#))))))
clj-kondo/clj-kondo
(ns clj-kondo.config-paths-test
  (:require
   [babashka.fs :as fs]
   [clj-kondo.test-utils :refer [lint! assert-submaps native?]]
   [clojure.java.io :as io]
   [clojure.test :refer [deftest testing is]])
  (:import [java.nio.file Files]))

(foo.foo/foo [x 1 y 2])"]
      (try
        (System/setProperty "user.home" home-dir)
        (let [cfg-file (io/file home-dir ".config" "clj-kondo" "config.edn")]
          (io/make-parents cfg-file)
          (spit cfg-file "{:lint-as {foo.foo/foo clojure.core/let}}")
          (testing "config from home dir is picked up"
            (assert-submaps
             '({:level :warning, :message "unused binding x"}
               {:level :warning, :message "unused binding y"})
             (lint! prog)))
          (testing "ignoring home dir config"
            (spit (io/file project-cfg-dir "config.edn") "{:config-paths ^:replace []}")
            (is (empty? (lint! prog "--config-dir" project-cfg-dir)))))
        (finally
          (System/setProperty "user.home" old-home))))))
cljsjs/packages
(require '[cljsjs.boot-cljsjs.packaging :refer :all]
         '[boot.core :as boot]
         '[boot.tmpdir :as tmpd]
         '[clojure.java.io :as io]
         '[boot.util :refer [sh]])

(deftask build-forge []
  (let [tmp (boot/tmp-dir!)]
    (with-pre-wrap
      fileset
      ;; Copy all files in fileset to temp directory
      (doseq [f (->> fileset boot/input-files)
              :let [target (io/file tmp (tmpd/path f))]]
        (io/make-parents target)
        (io/copy (tmpd/file f) target))
      (binding [boot.util/*sh-dir* (str (io/file tmp (format "forge-%s" +lib-version+)))]
        (do ((sh "npm" "install"))
            ((sh "npm" "run" "bundle"))))
      (-> fileset (boot/add-resource tmp) boot/commit!))))
cljsjs/packages
(require '[cljsjs.boot-cljsjs.packaging :refer :all]
         '[boot.core :as boot]
         '[boot.tmpdir :as tmpd]
         '[clojure.java.io :as io]
         '[boot.util :refer [sh *sh-dir*]])

(deftask build []
  (let [tmp (boot/tmp-dir!)]
    (with-pre-wrap
      fileset
      (doseq [f (boot/input-files fileset)]
        (let [target (io/file tmp (tmpd/path f))]
          (io/make-parents target)
          (io/copy (tmpd/file f) target)))
      (io/copy
       (io/file tmp "build/webpack.config.js")
       (io/file tmp +lib-folder+ "webpack-cljsjs.config.js"))
      (binding [*sh-dir* (str (io/file tmp +lib-folder+))]
        ((sh "npm" "install"))
        ((sh "./node_modules/.bin/webpack" "--config" "webpack-cljsjs.config.js")))
      (-> fileset (boot/add-resource tmp) boot/commit!))))
cljsjs/packages
(require '[boot.core :as c]
         '[boot.pod  :as pod]
         '[boot.util :as util]
         '[clojure.java.io :as io]
         'asset-minifier.core)

(deftask minify-set
  "Minifies .js and .css files based on their file extension"
  []
  (let [tmp      (c/tmp-dir!)
        in->out-path (fn [path]
                       (when-let [[js-path parent ns] (re-matches #"cljsjs/three-examples/development/(.*/)?(.*)\.inc\.js" path)]
                         (str "cljsjs/three-examples/production/" parent ns ".min.inc.js")))]
    (with-pre-wrap
      fileset
      (let [dev-files (->> fileset c/input-files (c/by-re [#"^cljsjs/three-examples/development/.*\.inc\.js"]))
            out-paths (map (comp in->out-path c/tmp-path) dev-files)]
        (util/info "Minifying javascript.\n")
        (doall (map (fn [in-file out-path]
                      (let [in-path (.getPath (c/tmp-file in-file))
                            out-file (io/file tmp out-path)]
                        (io/make-parents out-file)
                        (when (pos? (count (:errors (asset-minifier.core/minify-js in-path (.getPath out-file) {:quiet? true}))))
                          (util/warn "Could not minify %s, copying original.\n" (.getName (c/tmp-file in-file)))
                          (util/sh "cp" in-path (.getPath out-file)))))
                    dev-files
                    out-paths))
        (-> fileset
            (c/add-resource tmp)
            c/commit!)))))

(deftask generate-externs []
  (let [tmp (c/tmp-dir!)
        externs-file (io/file tmp "cljsjs/three-examples/common/three-examples.ext.js")]
    (with-pre-wrap
      fileset
      (let [threejs-path (->> fileset
                              c/input-files
                              (c/by-re [#"build/three.js"])
                              (map (comp #(.getPath %) c/tmp-file))
                              first)
            package-file (->> fileset
                              c/input-files
                              (c/by-re [#"package.json"])
                              (map c/tmp-file)
                              first)
            input-string (->> fileset
                              c/input-files
                              (c/by-re [#"examples/js/.*\.js"])
                              (map (comp #(.getPath %) c/tmp-file))
                              (cons threejs-path)
                              (clojure.string/join ","))]
        (util/info "Generating externs.\n")
        (io/make-parents externs-file)
        (io/copy package-file (io/file tmp "package.json"))
        (binding [boot.util/*sh-dir* (str tmp)]
          ((sh "npm" "install" "externs-generator"))
          ((sh "node_modules/externs-generator/bin/extern"
               "-f" input-string
               "-n" "THREE"
               "-o" (.getPath externs-file))))
        (-> fileset (c/add-resource tmp) c/commit!)))))