highmark-cli 0.0.95 → 0.0.97

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.
@@ -7,14 +7,28 @@ function helpAction() {
7
7
 
8
8
  Commands:
9
9
 
10
- [help] Show this help
10
+ help Show this help
11
11
 
12
+ version Show the version
13
+
14
+ [publish] Publish the input Markdown file to the output HTML file.
15
+
12
16
  Options:
13
17
 
14
18
  --help|-h Show this help
15
19
 
16
20
  --version|-v Show the version
17
21
 
22
+ --port|-p The server port. The default is 8888.
23
+
24
+ --server|-s Start a server to view the output file
25
+
26
+ --copy-fonts|-f Copy the fonts to a fonts folder next to the output file
27
+
28
+ --input-file-path|-i The input file path. The default is 'default.md'.
29
+
30
+ --output-file-path|-o The output file path. The default is 'index.html'.
31
+
18
32
  Further information:
19
33
 
20
34
  Please see the readme file on GitHub:
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ const serverOperation = require("../operation/server");
4
+
5
+ const { executeOperations } = require("../utilities/operation"),
6
+ { SUCCESSFUL_SERVER_MESSAGE, FAILED_SERVER_MESSAGE } = require("../messages");
7
+
8
+ function serverAction(port, server, outputFilePath) {
9
+ const operations = [
10
+ serverOperation
11
+ ],
12
+ context = {
13
+ port,
14
+ server,
15
+ outputFilePath
16
+ };
17
+
18
+ executeOperations(operations, (completed) => {
19
+ const success = completed, ///
20
+ message = success ?
21
+ SUCCESSFUL_SERVER_MESSAGE :
22
+ FAILED_SERVER_MESSAGE;
23
+
24
+ console.log(message);
25
+ }, context);
26
+ }
27
+
28
+ module.exports = serverAction;
package/bin/commands.js CHANGED
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  const HELP_COMMAND = "help",
4
+ SERVER_COMMAND = "server",
4
5
  VERSION_COMMAND = "version",
5
6
  PUBLISH_COMMAND = 'publish';
6
7
 
7
8
  module.exports = {
8
9
  HELP_COMMAND,
10
+ SERVER_COMMAND,
9
11
  VERSION_COMMAND,
10
12
  PUBLISH_COMMAND
11
13
  };
package/bin/main.js CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  const helpAction = require("./action/help"),
4
+ serverAction = require("./action/server"),
4
5
  versionAction = require("./action/version"),
5
6
  publishAction = require("./action/publish");
6
7
 
7
- const { HELP_OPTION, VERSION_OPTION } = require("./options"),
8
- { HELP_COMMAND, VERSION_COMMAND, PUBLISH_COMMAND } = require("./commands"),
8
+ const { HELP_OPTION, SERVER_OPTION, VERSION_OPTION } = require("./options"),
9
+ { HELP_COMMAND, SERVER_COMMAND, VERSION_COMMAND, PUBLISH_COMMAND } = require("./commands"),
9
10
  { DEFAULT_PORT,
10
11
  DEFAULT_SERVER,
11
12
  DEFAULT_COPY_FONTS,
@@ -15,6 +16,7 @@ const { HELP_OPTION, VERSION_OPTION } = require("./options"),
15
16
  function main(command, argument, options) {
16
17
  const commandMissing = (command === null),
17
18
  helpOptionPresent = options.hasOwnProperty(HELP_OPTION),
19
+ serverOptionPresent = options.hasOwnProperty(SERVER_OPTION),
18
20
  versionOptionPresent = options.hasOwnProperty(VERSION_OPTION),
19
21
  { port = DEFAULT_PORT,
20
22
  server = DEFAULT_SERVER,
@@ -26,18 +28,23 @@ function main(command, argument, options) {
26
28
  ///
27
29
  } else if (versionOptionPresent) {
28
30
  command = VERSION_COMMAND;
29
- } else if (commandMissing || helpOptionPresent) {
30
- command = HELP_COMMAND;
31
+ } else if (commandMissing) {
32
+ if (false) {
33
+ ///
34
+ } else if (helpOptionPresent) {
35
+ command = HELP_COMMAND;
36
+ } else if (serverOptionPresent) {
37
+ command = SERVER_COMMAND;
38
+ }
31
39
  }
32
40
 
33
41
  switch (command) {
34
42
  case HELP_COMMAND: helpAction(); break;
43
+ case SERVER_COMMAND: serverAction(port, server, outputFilePath); break;
35
44
  case VERSION_COMMAND: versionAction(); break;
36
45
  case PUBLISH_COMMAND: publishAction(port, server, copyFonts, inputFilePath, outputFilePath); break;
37
46
 
38
47
  default :
39
- argument = command; ///
40
-
41
48
  publishAction(port, server, copyFonts, inputFilePath, outputFilePath);
42
49
 
43
50
  break;
package/bin/messages.js CHANGED
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
 
3
- const FAILED_PUBLISH_MESSAGE = "Failed to publish.",
3
+ const FAILED_SERVER_MESSAGE = "Failed to serve.",
4
+ FAILED_PUBLISH_MESSAGE = "Failed to publish.",
5
+ SUCCESSFUL_SERVER_MESSAGE = "Served successfully.",
4
6
  SUCCESSFUL_PUBLISH_MESSAGE = "Published successfully.",
7
+ UNABLE_TO_COPY_FILE_MESSAGE = "Unable to copy the file.",
5
8
  UNABLE_TO_READ_FILE_MESSAGE = "Unable to read the file.",
6
9
  UNABLE_TO_WRITE_FILE_MESSAGE = "Unable to write the file.",
7
10
  UNABLE_TO_START_SERVER_MESSAGE = "Unable to start the server",
@@ -12,8 +15,11 @@ const FAILED_PUBLISH_MESSAGE = "Failed to publish.",
12
15
  UNABLE_TO_CONVERT_MARKDOWN_STYLES_TO_CSS_MESSAGE = "Unable to convert Markdown styles to CSS.";
13
16
 
14
17
  module.exports = {
18
+ FAILED_SERVER_MESSAGE,
15
19
  FAILED_PUBLISH_MESSAGE,
20
+ SUCCESSFUL_SERVER_MESSAGE,
16
21
  SUCCESSFUL_PUBLISH_MESSAGE,
22
+ UNABLE_TO_COPY_FILE_MESSAGE,
17
23
  UNABLE_TO_READ_FILE_MESSAGE,
18
24
  UNABLE_TO_WRITE_FILE_MESSAGE,
19
25
  UNABLE_TO_START_SERVER_MESSAGE,
@@ -4,8 +4,8 @@ const { pathUtilities } = require("necessary"),
4
4
  { getFontDirectoryPath } = require("highmark-fonts");
5
5
 
6
6
  const { FONT } = require("../constants"),
7
- { fileNameFromFilePath, directoryPathFromFilePath } = require("../utilities/path"),
8
- { readFile, writeFile, readDirectory, createDirectory } = require("../utilities/fileSystem");
7
+ { copyFile, readDirectory, createDirectory } = require("../utilities/fileSystem"),
8
+ { fileNameFromFilePath, directoryPathFromFilePath } = require("../utilities/path");
9
9
 
10
10
  const { concatenatePaths } = pathUtilities;
11
11
 
@@ -29,16 +29,15 @@ function copyFontsOperation(proceed, abort, context) {
29
29
 
30
30
  fontDirectoryPath = getFontDirectoryPath();
31
31
 
32
- const recursive = false;
32
+ const recursive = false,
33
+ targetDirectoryPath = concatenatePaths(outputDirectoryPath, FONT);
33
34
 
34
35
  readDirectory(fontDirectoryPath, (filePath) => {
35
- const content = readFile(filePath),
36
- fileName = fileNameFromFilePath(filePath),
37
- directoryPath = concatenatePaths(outputDirectoryPath, FONT);
36
+ const fileName = fileNameFromFilePath(filePath),
37
+ sourceFilePath = filePath, ///
38
+ targetFilePath = concatenatePaths(targetDirectoryPath, fileName); ///
38
39
 
39
- filePath = concatenatePaths(directoryPath, fileName); ///
40
-
41
- writeFile(filePath, content);
40
+ copyFile(sourceFilePath, targetFilePath);
42
41
  }, recursive);
43
42
 
44
43
  proceed();
@@ -3,7 +3,8 @@
3
3
  const { pathUtilities, fileSystemUtilities } = require("necessary");
4
4
 
5
5
  const { isEntryNameHiddenName } = require("../utilities/path"),
6
- { UNABLE_TO_READ_FILE_MESSAGE,
6
+ { UNABLE_TO_COPY_FILE_MESSAGE,
7
+ UNABLE_TO_READ_FILE_MESSAGE,
7
8
  UNABLE_TO_WRITE_FILE_MESSAGE,
8
9
  UNABLE_TO_READ_DIRECTORY_MESSAGE,
9
10
  UNABLE_TO_CREATE_DIRECTORY_MESSAGE } = require("../messages");
@@ -11,11 +12,34 @@ const { isEntryNameHiddenName } = require("../utilities/path"),
11
12
  const { concatenatePaths } = pathUtilities,
12
13
  { isEntryFile,
13
14
  checkEntryExists,
15
+ copyFile: copyFileAsync,
14
16
  readFile: readFileAsync,
15
17
  writeFile: writeFileAsync,
16
18
  readDirectory: readDirectoryAsync,
17
19
  createDirectory: createDirectoryAsync } = fileSystemUtilities;
18
20
 
21
+ function copyFile(sourceFilePath, targetFilePath) {
22
+ let content = null;
23
+
24
+ try {
25
+ content = copyFileAsync(sourceFilePath, targetFilePath);
26
+
27
+ console.log(`Copy file '${sourceFilePath}' to '${targetFilePath}'.`);
28
+ } catch (error) {
29
+ let message;
30
+
31
+ message = UNABLE_TO_COPY_FILE_MESSAGE;
32
+
33
+ console.log(message);
34
+
35
+ ({ message } = error);
36
+
37
+ console.log(message);
38
+ }
39
+
40
+ return content;
41
+ }
42
+
19
43
  function readFile(filePath) {
20
44
  let content = null;
21
45
 
@@ -119,6 +143,7 @@ function createDirectory(directoryPath) {
119
143
  }
120
144
 
121
145
  module.exports = {
146
+ copyFile,
122
147
  readFile,
123
148
  writeFile,
124
149
  readDirectory,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "highmark-cli",
3
3
  "author": "James Smith",
4
- "version": "0.0.95",
4
+ "version": "0.0.97",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/highmark-cli",
7
7
  "description": "Extensible, styleable Markdown.",