highmark-cli 0.0.78 → 0.0.80

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,21 +1,21 @@
1
1
  "use strict";
2
2
 
3
- const markdownHTMLOperation = require("../operation/markdownHTML"),
3
+ const htmlOperation = require("../operation/html"),
4
+ markdownHTMLOperation = require("../operation/markdownHTML"),
4
5
  markdownStylesCSSOperation = require("../operation/markdownStylesCSS");
5
6
 
6
7
  const { executeOperations } = require("../utilities/operation"),
7
8
  { SUCCESSFUL_PUBLISH_MESSAGE, FAILED_PUBLISH_MESSAGE } = require("../messages");
8
9
 
9
10
  function publishAction(inputFilePath, outputFilePath) {
10
- const markdownFilePath = inputFilePath, ///
11
- htmlFilePath = outputFilePath, ///
12
- operations = [
11
+ const operations = [
12
+ markdownStylesCSSOperation,
13
13
  markdownHTMLOperation,
14
- markdownStylesCSSOperation
14
+ htmlOperation
15
15
  ],
16
16
  context = {
17
- htmlFilePath,
18
- markdownFilePath
17
+ inputFilePath,
18
+ outputFilePath
19
19
  };
20
20
 
21
21
  executeOperations(operations, (completed) => {
package/bin/actions.js CHANGED
@@ -4,7 +4,7 @@ const helpAction = require("./action/help"),
4
4
  versionAction = require("./action/version"),
5
5
  publishAction = require("./action/publish");
6
6
 
7
- const { DEFAULT_INPUT_FILE_PATH } = require("./defaults"),
7
+ const { DEFAULT_INPUT_FILE_PATH, DEFAULT_OUTPUT_FILE_PATH } = require("./defaults"),
8
8
  { HELP_OPTION, VERSION_OPTION } = require("./options"),
9
9
  { HELP_COMMAND, VERSION_COMMAND, PUBLISH_COMMAND } = require("./commands");
10
10
 
@@ -13,7 +13,7 @@ function actions(command, argument, options) {
13
13
  helpOptionPresent = options.hasOwnProperty(HELP_OPTION),
14
14
  versionOptionPresent = options.hasOwnProperty(VERSION_OPTION),
15
15
  { inputFilePath = DEFAULT_INPUT_FILE_PATH,
16
- outputFilePath = null } = options;
16
+ outputFilePath = DEFAULT_OUTPUT_FILE_PATH } = options;
17
17
 
18
18
  if (false) {
19
19
  ///
package/bin/constants.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const PERIOD = ".",
4
+ EMPTY_STRING = "",
4
5
  DOUBLE_SPACE = " ",
5
6
  HIGHMARK_CLI = "Highmark-CLI",
6
7
  DEFAULT_SELECTOR_STRING = "div",
@@ -8,6 +9,7 @@ const PERIOD = ".",
8
9
 
9
10
  module.exports = {
10
11
  PERIOD,
12
+ EMPTY_STRING,
11
13
  DOUBLE_SPACE,
12
14
  HIGHMARK_CLI,
13
15
  DEFAULT_SELECTOR_STRING,
package/bin/defaults.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
 
3
- const DEFAULT_INPUT_FILE_PATH = "default.md";
3
+ const DEFAULT_INPUT_FILE_PATH = "default.md",
4
+ DEFAULT_OUTPUT_FILE_PATH = "index.html";
4
5
 
5
6
  module.exports = {
6
- DEFAULT_INPUT_FILE_PATH
7
+ DEFAULT_INPUT_FILE_PATH,
8
+ DEFAULT_OUTPUT_FILE_PATH
7
9
  };
package/bin/importer.js CHANGED
@@ -4,7 +4,7 @@ const { readFile } = require("./utilities/fileSystem"),
4
4
  { divisionIdentifierFromFilePath } = require("./utilities/division"),
5
5
  { nodeFromTokens, tokensFromContent } = require("./utilities/markdown");
6
6
 
7
- function importer(filePath, indent) {
7
+ function importer(filePath, indent, context) {
8
8
  let html = null;
9
9
 
10
10
  const content = readFile(filePath);
@@ -15,11 +15,12 @@ function importer(filePath, indent) {
15
15
  node = nodeFromTokens(tokens);
16
16
 
17
17
  if (node !== null) {
18
- html = node.asHTML(indent, { ///
18
+ Object.assign(context, {
19
19
  tokens,
20
- importer,
21
20
  divisionIdentifier
22
21
  });
22
+
23
+ html = node.asHTML(indent, context);
23
24
  }
24
25
  }
25
26
 
package/bin/messages.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const FAILED_PUBLISH_MESSAGE = "Failed to publish.",
4
4
  SUCCESSFUL_PUBLISH_MESSAGE = "Published successfully.",
5
5
  UNABLE_TO_READ_FILE_MESSAGE = "Unable to read the file.",
6
+ UNABLE_TO_WRITE_FILE_MESSAGE = "Unable to write the file.",
6
7
  UNABLE_TO_READ_DIRECTORY_MESSAGE = "Unable to read the directory.",
7
8
  UNABLE_TO_PARSE_MARKDOWN_FILE_MESSAGE = "Unable to parse the markdown file.",
8
9
  UNABLE_TO_CONVERT_MARKDOWN_TO_HTML_MESSAGE = "Unable to convert Markdown to HTML.",
@@ -12,6 +13,7 @@ module.exports = {
12
13
  FAILED_PUBLISH_MESSAGE,
13
14
  SUCCESSFUL_PUBLISH_MESSAGE,
14
15
  UNABLE_TO_READ_FILE_MESSAGE,
16
+ UNABLE_TO_WRITE_FILE_MESSAGE,
15
17
  UNABLE_TO_READ_DIRECTORY_MESSAGE,
16
18
  UNABLE_TO_PARSE_MARKDOWN_FILE_MESSAGE,
17
19
  UNABLE_TO_CONVERT_MARKDOWN_TO_HTML_MESSAGE,
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ const { writeFile } = require("../utilities/fileSystem");
4
+
5
+ const { EMPTY_STRING } = require("../constants");
6
+
7
+ function htmlOperation(proceed, abort, context) {
8
+ const { title, markdownHTML, outputFilePath, markdownStylesCSS } = context,
9
+ titleHTML = titleHTMLFromTitle(title),
10
+ filePath = outputFilePath, ///
11
+ content = `<!DOCTYPE html>
12
+ <html>
13
+ <head>
14
+
15
+ ${titleHTML}
16
+
17
+ <meta charset="utf-8" />
18
+
19
+ <style>
20
+
21
+ *,
22
+ *::after,
23
+ *::before {
24
+ border: 0;
25
+ margin: 0;
26
+ padding: 0;
27
+ box-sizing: border-box;
28
+ }
29
+
30
+ </style>
31
+ <style>
32
+
33
+ ${markdownStylesCSS}
34
+
35
+ </style>
36
+ </head>
37
+ <body>
38
+
39
+ ${markdownHTML}
40
+
41
+ </body>
42
+ </html>
43
+ `;
44
+
45
+ writeFile(filePath, content);
46
+
47
+ proceed();
48
+ }
49
+
50
+ module.exports = htmlOperation;
51
+
52
+ function titleHTMLFromTitle(title) {
53
+ const titleHTML = (title === null) ?
54
+ EMPTY_STRING :
55
+ `<title>${title}</title>`;
56
+
57
+ return titleHTML;
58
+ }
@@ -6,10 +6,17 @@ const { DOUBLE_SPACE } = require("../constants"),
6
6
  { UNABLE_TO_CONVERT_MARKDOWN_TO_HTML_MESSAGE } = require("../messages");
7
7
 
8
8
  function markdownHTMLOperation(proceed, abort, context) {
9
- const { markdownFilePath } = context,
10
- filePath = markdownFilePath, ///
9
+ const { inputFilePath } = context,
10
+ filePath = inputFilePath, ///
11
11
  indent = DOUBLE_SPACE,
12
- html = importer(filePath, indent);
12
+ title = null;
13
+
14
+ Object.assign(context, {
15
+ title,
16
+ importer
17
+ });
18
+
19
+ const html = importer(filePath, indent, context);
13
20
 
14
21
  if (html === null) {
15
22
  const message = UNABLE_TO_CONVERT_MARKDOWN_TO_HTML_MESSAGE;
@@ -3,10 +3,13 @@
3
3
  const { pathUtilities, fileSystemUtilities } = require("necessary");
4
4
 
5
5
  const { isEntryNameHiddenName } = require("../utilities/name"),
6
- { UNABLE_TO_READ_FILE_MESSAGE, UNABLE_TO_READ_DIRECTORY_MESSAGE } = require("../messages");
6
+ { UNABLE_TO_READ_FILE_MESSAGE, UNABLE_TO_WRITE_FILE_MESSAGE, UNABLE_TO_READ_DIRECTORY_MESSAGE } = require("../messages");
7
7
 
8
8
  const { concatenatePaths } = pathUtilities,
9
- { isEntryFile, readFile: readFileAsync, readDirectory: readDirectoryAsync } = fileSystemUtilities;
9
+ { isEntryFile,
10
+ readFile: readFileAsync,
11
+ writeFile: writeFileAsync,
12
+ readDirectory: readDirectoryAsync } = fileSystemUtilities;
10
13
 
11
14
  function readFile(filePath) {
12
15
  let content = null;
@@ -30,6 +33,24 @@ function readFile(filePath) {
30
33
  return content;
31
34
  }
32
35
 
36
+ function writeFile(filePath, content) {
37
+ try {
38
+ writeFileAsync(filePath, content);
39
+
40
+ console.log(`Write file '${filePath}'.`);
41
+ } catch (error) {
42
+ let message;
43
+
44
+ message = UNABLE_TO_WRITE_FILE_MESSAGE;
45
+
46
+ console.log(message);
47
+
48
+ ({ message } = error);
49
+
50
+ console.log(message);
51
+ }
52
+ }
53
+
33
54
  function readDirectory(directoryPath, callback) {
34
55
  try {
35
56
  const entryNames = readDirectoryAsync(directoryPath);
@@ -48,7 +69,7 @@ function readDirectory(directoryPath, callback) {
48
69
  } else {
49
70
  const directoryPath = entryPath; ///
50
71
 
51
- readDirectory(directoryPath);
72
+ readDirectory(directoryPath, callback);
52
73
  }
53
74
  }
54
75
  });
@@ -67,5 +88,6 @@ function readDirectory(directoryPath, callback) {
67
88
 
68
89
  module.exports = {
69
90
  readFile,
91
+ writeFile,
70
92
  readDirectory
71
93
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "highmark-cli",
3
3
  "author": "James Smith",
4
- "version": "0.0.78",
4
+ "version": "0.0.80",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/highmark-cli",
7
7
  "description": "Extensible, styleable Markdown.",
@@ -11,8 +11,8 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "argumentative": "^2.0.28",
14
- "highmark-markdown": "^0.0.121",
15
- "highmark-markdown-style": "^0.0.172",
14
+ "highmark-markdown": "^0.0.125",
15
+ "highmark-markdown-style": "^0.0.174",
16
16
  "necessary": "^13.4.2",
17
17
  "occam-entities": "^1.0.83"
18
18
  },