-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All resources loaded by slurp are moved to status-modules/resources dir in release builds and are loaded only by demand instead of being bundled into index.*.js.
- Loading branch information
Showing
8 changed files
with
94 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,3 +165,4 @@ conan.cmake | |
# modules | ||
status-modules/translations | ||
status-modules/cljs | ||
status-modules/resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
var fs = require("fs"); | ||
var path = require('path'); | ||
var dirs = ["status-modules/cljs", "status-modules/resources"]; | ||
|
||
var modules = [ | ||
"i18n" | ||
]; | ||
|
||
modules.forEach( | ||
function (moduleName) { | ||
fs.readFile(`status-modules/cljs/${moduleName}-raw.js`, "utf8", function (err, data) { | ||
if (err) throw err; | ||
fs.writeFile(`status-modules/cljs/${moduleName}.js`, | ||
("module.exports=`" + data.replace(/[\\$'"]/g, "\\$&") + "`;"), | ||
function (err) { | ||
if (err) { | ||
return console.log(err); | ||
} | ||
}); | ||
}); | ||
dirs.forEach(dir => { | ||
fs.readdir(dir, (err, files) => { | ||
if (files) { | ||
files.forEach(file => { | ||
if (file.endsWith("-raw.js")) { | ||
const filePath = path.resolve(dir, file); | ||
fs.readFile(filePath, "utf8", function (err, data) { | ||
if (err) throw err; | ||
fs.writeFile(filePath.replace("-raw.js", ".js"), | ||
("module.exports=`" + data.replace(/[\\$'"]/g, "\\$&") + "`;"), | ||
function (err) { | ||
if (err) { | ||
return console.log(err); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
(ns status-im.utils.slurp | ||
(:refer-clojure :exclude [slurp]) | ||
(:require [clojure.string :as string])) | ||
(:require [clojure.java.io :as io] | ||
[clojure.string :as str]) | ||
(:import (java.io File))) | ||
|
||
(def prod? (= "prod" (System/getenv "BUILD_ENV"))) | ||
|
||
(defn copy-file [source-path dest-path] | ||
(io/copy (io/file source-path) (io/file dest-path))) | ||
|
||
(def resources-dir "status-modules/resources/") | ||
|
||
(defn check-resources-dir [] | ||
(let [resources (File. resources-dir)] | ||
(when-not (.exists resources) | ||
(.mkdir resources)))) | ||
|
||
(defmacro slurp [file] | ||
(clojure.core/slurp file)) | ||
|
||
(defmacro slurp-bot [bot-name & files] | ||
(->> (concat files ["translations.js" "bot.js"]) | ||
(map (fn [file-name] | ||
(try | ||
(clojure.core/slurp | ||
(string/join "/" ["resources/js/bots" (name bot-name) file-name])) | ||
(catch Exception _ "")))) | ||
(apply str))) | ||
(if prod? | ||
(let [name (str/replace file #"[\/\.]" "_") | ||
file-name (str resources-dir name)] | ||
(check-resources-dir) | ||
(copy-file file (str file-name "-raw.js")) | ||
(let [res (gensym "res")] | ||
`(let [~res (atom nil)] | ||
(fn [] | ||
(or @~res | ||
(reset! ~res (js/require ~(str file-name ".js")))))))) | ||
`(fn [] | ||
~(clojure.core/slurp file)))) |