catto.js 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/Server.js +6 -5
  2. package/package.json +1 -1
package/Server.js CHANGED
@@ -35,6 +35,7 @@ class Server extends EventEmitter {
35
35
  "storeOptions": {},
36
36
  "ejs": !1,
37
37
  "cjs": !1,
38
+ "cjsClient": !0,
38
39
  "proxies": 0,
39
40
  "bodyCompatible": !1,
40
41
  "secureCookie": !0,
@@ -63,7 +64,7 @@ class Server extends EventEmitter {
63
64
  this.app.set("view engine", "ejs");
64
65
  }
65
66
  if (this.options.cjs) {
66
- Server.injectCJS(this.app);
67
+ Server.injectCJS(this.app, !1, this.options.cjsClient);
67
68
  }
68
69
  if (this.options.secret) {
69
70
  this.app.use(session({
@@ -166,14 +167,14 @@ class Server extends EventEmitter {
166
167
  }
167
168
  return this;
168
169
  }
169
- static renderCJS(app, filepath, options, callback) {
170
+ static renderCJS(app, wclient, filepath, options, callback) {
170
171
  var code = fs.readFileSync(filepath).toString("utf-8");
171
172
  var doctype = code.startsWith("<!DOCTYPE html>");
172
173
  if (doctype) {
173
174
  code = code.replace(/^<!DOCTYPE html>(\r?\n)?/, "");
174
175
  }
175
176
  var parts = code.split(/<%s(?:erver)?(?!\*)(?!=) +(.+?) +%>/g);
176
- var compile = `var __output = "${doctype ? "<!DOCTYPE html>\\n" : ""}<script src=\\"/_cattojs/cjs_client.js\\"></script>\\n";\nfunction __escape(str) {\n if (str === void 0) {\n return "undefined";\n }\n if (typeof str !== "string") {\n str = str.toString();\n }\n return str.split("<").join("&lt;").split(">").join("&gt;");\n}\n`;
177
+ var compile = `var __output = "${doctype ? "<!DOCTYPE html>\\n" : ""}${wclient ? `<script src=\\"/_cattojs/cjs_client.js\\"></script>\\n` : ""}";\nfunction __escape(str) {\n if (str === void 0) {\n return "undefined";\n }\n if (typeof str !== "string") {\n str = str.toString();\n }\n return str.split("<").join("&lt;").split(">").join("&gt;");\n}\n`;
177
178
  parts.forEach((part, index) => {
178
179
  compile += ((index + 1) % 2 < 1 ? `${part}\n` : `__output += ${JSON.stringify(part)}.replace(/<%s(?:erver)?(?!\\*)= +(.+?) +%>/g, (_, g) => __escape(eval(g))).replace(/<%s(?:erver)?(?!\\*)- +(.+?) +%>/g, (_, g) => eval(g)).replace(/<%s(erver)\\*?# +(.+?) +%>/g, "");\n`);
179
180
  });
@@ -186,8 +187,8 @@ class Server extends EventEmitter {
186
187
  }
187
188
  return context.__output;
188
189
  }
189
- static injectCJS(app, nows) {
190
- app.engine("cjs", Server.renderCJS.bind(null, app)).set("view engine", "cjs").get("/_cattojs/cjs_client.js", (req, res) => {
190
+ static injectCJS(app, nows, wclient) {
191
+ app.engine("cjs", Server.renderCJS.bind(null, app, wclient)).set("view engine", "cjs").get("/_cattojs/cjs_client.js", (req, res) => {
191
192
  res.sendFile(path.join(__dirname, "cjs_client.js"));
192
193
  });
193
194
  if (!nows && !app.ws) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catto.js",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Universal module for everything.",
5
5
  "main": "index.js",
6
6
  "scripts": {