mushroom-cli 1.2.0-alpha.8 → 1.2.0-alpha.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.
@@ -1,6 +1,8 @@
1
1
  const fs = require("fs");
2
2
  const open = require("open");
3
3
  const common = require("../common.js");
4
+ const minify = require("minify");
5
+ const path = require("path");
4
6
 
5
7
  function reserveWhitelist(obj, whitelist) {
6
8
  if (obj === null && typeof obj !== "object") return null;
@@ -98,7 +100,7 @@ function flattenFields(fields, dict, prefix) {
98
100
 
99
101
  function removeDisallowedFields(fields, dict) {
100
102
  const allowFields = Object.keys(dict);
101
- if (allowFields.length) return;
103
+ if (!allowFields.length) return;
102
104
  reserveWhitelist(fields, allowFields);
103
105
  for (let m in fields) {
104
106
  const config = fields[m];
@@ -176,12 +178,49 @@ function filterEntityFields(entity) {
176
178
  removeDisallowedFields(entity.fields, whitelist);
177
179
  }
178
180
 
179
- function writeDocs(filePath, strTemplate, strData) {
180
- const placeholder = "undefined/*INJECT-HERE*/";
181
+ async function writeDocs(filePath, strTemplate, strData) {
182
+ //const placeholder = "/*INJECT-JAVASCRIPT-HERE*/";
183
+ /*const idx = strTemplate.indexOf(placeholder);
184
+ fs.writeFileSync(filePath, strTemplate.substr(0, idx));
185
+ fs.appendFileSync(filePath, "window.docs = ");
186
+ fs.appendFileSync(filePath, strData);
187
+ fs.appendFileSync(filePath, ";\n");
188
+ fs.appendFileSync(filePath, await minify(path.join(__dirname, "../docs/docs.v2.js"), {
189
+ js: {
190
+ compress: true
191
+ }
192
+ }));
193
+ fs.appendFileSync(filePath, strTemplate.substr(idx + placeholder.length));*/
194
+
195
+ const placeholder = '<script id="INJECT-JAVASCRIPT-HERE"></script>';
181
196
  const idx = strTemplate.indexOf(placeholder);
182
197
  fs.writeFileSync(filePath, strTemplate.substr(0, idx));
198
+ fs.appendFileSync(filePath, "<script>window.docs = ");
183
199
  fs.appendFileSync(filePath, strData);
200
+ fs.appendFileSync(filePath, ";\n");
201
+ fs.appendFileSync(filePath, fs.readFileSync(path.join(__dirname, "../docs/docs.v2.js")));
202
+ fs.appendFileSync(filePath, "</script>");
184
203
  fs.appendFileSync(filePath, strTemplate.substr(idx + placeholder.length));
204
+
205
+ fs.writeFileSync(filePath, await minify(filePath, {
206
+ "html": {
207
+ "removeComments": true,
208
+ "removeCommentsFromCDATA": true,
209
+ "removeCDATASectionsFromCDATA": true,
210
+ "collapseWhitespace": true,
211
+ "collapseBooleanAttributes": true,
212
+ "removeAttributeQuotes": true,
213
+ "removeRedundantAttributes": true,
214
+ "useShortDoctype": true,
215
+ "removeEmptyAttributes": true,
216
+ "removeEmptyElements": false,
217
+ "removeOptionalTags": true,
218
+ "removeScriptTypeAttributes": false,
219
+ "removeStyleLinkTypeAttributes": true,
220
+ "minifyJS": true,
221
+ "minifyCSS": true
222
+ }
223
+ }));
185
224
  }
186
225
 
187
226
  async function genDocs(args, projectName, project, alias, source) {
@@ -230,7 +269,7 @@ async function genDocs(args, projectName, project, alias, source) {
230
269
  if (args[3] === "tmp") {
231
270
  const htmlFilePath = aliasProject.output + "_tmp.html";
232
271
  console.log(`Writing to ${htmlFilePath}`);
233
- writeDocs(htmlFilePath, html, data);
272
+ await writeDocs(htmlFilePath, html, data);
234
273
 
235
274
  console.log("Opening file " + htmlFilePath);
236
275
  try {
@@ -252,7 +291,7 @@ async function genDocs(args, projectName, project, alias, source) {
252
291
  common.ensureFolder(aliasProject.output);
253
292
 
254
293
  console.log(`Writing to ${aliasProject.output}`);
255
- writeDocs(aliasProject.output, html, data);
294
+ await writeDocs(aliasProject.output, html, data);
256
295
  console.log(`Generated API docs for ${projectName}@${alias} to ${aliasProject.output}`)
257
296
  }
258
297
 
package/mr.js CHANGED
@@ -49,10 +49,6 @@ async function run(args) {
49
49
  case "update":
50
50
  await update(args);
51
51
  break;
52
- case "":
53
- case undefined:
54
- console.log(`Mushroom CLI`);
55
- break;
56
52
  case "help":
57
53
  case "man":
58
54
  help(args.slice(1).join());
@@ -63,7 +59,7 @@ async function run(args) {
63
59
  }
64
60
  }
65
61
  catch (e) {
66
- console.error(debugMode ? e : e.message);
62
+ console.error(debugMode ? e : "ERROR: " + e.message);
67
63
  }
68
64
  finally {
69
65
  console.log("Processed in", new Date().getTime() - startTime, "ms.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mushroom-cli",
3
- "version": "1.2.0-alpha.8",
3
+ "version": "1.2.0-alpha.9",
4
4
  "description": "Mushroom CLI",
5
5
  "main": "mr.js",
6
6
  "scripts": {
@@ -16,10 +16,11 @@
16
16
  },
17
17
  "author": "suco2007",
18
18
  "license": "ISC",
19
- "dependencies-comments": "node-fetch: 2.x; open: 8.x",
19
+ "dependencies-comments": "node-fetch: 2.x; open: 8.x; minify: 7.x",
20
20
  "dependencies": {
21
21
  "jsdom": "^22.1.0",
22
22
  "json5": "^2.2.3",
23
+ "minify": "7.2.2",
23
24
  "node-fetch": "^2.6.11",
24
25
  "open": "^8.4.2",
25
26
  "readline-sync": "^1.4.10",