@rokelamen/md2html 0.1.0 → 0.1.1
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.
- package/README.md +4 -0
- package/dist/index.js +46 -7
- package/package.json +11 -9
package/README.md
ADDED
package/dist/index.js
CHANGED
|
@@ -1,11 +1,50 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { program } from 'commander';
|
|
3
|
-
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
/* The main parse logic */
|
|
5
|
+
function parse(content) {
|
|
6
|
+
const transform = content.trim();
|
|
7
|
+
return `<p>${transform}</p>`;
|
|
8
|
+
}
|
|
9
|
+
// Import these from package.json in the future
|
|
10
|
+
const name = 'md2html';
|
|
11
|
+
const version = '0.1.1';
|
|
12
|
+
const description = 'A simple tool to convert markdown content to html';
|
|
13
|
+
/* Command-line tool logic */
|
|
14
|
+
function command() {
|
|
15
|
+
/* Set basic info */
|
|
16
|
+
program
|
|
17
|
+
.name(name)
|
|
18
|
+
.version(version)
|
|
19
|
+
.description(description);
|
|
20
|
+
/* Config arguments info */
|
|
4
21
|
program
|
|
5
|
-
.
|
|
6
|
-
.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
22
|
+
.option('-f, --file <path>', 'source file path')
|
|
23
|
+
.argument('[input]', 'input content');
|
|
24
|
+
/* Parse the cli options */
|
|
25
|
+
program.parse(process.argv);
|
|
26
|
+
/* Validation check */
|
|
27
|
+
const options = program.opts();
|
|
28
|
+
const input = program.args[0];
|
|
29
|
+
const hasFile = typeof options.file === 'string';
|
|
30
|
+
const hasInput = typeof input === 'string';
|
|
31
|
+
// XOR validation
|
|
32
|
+
if (hasFile === hasInput) {
|
|
33
|
+
console.error('error: exactly one content source must be provided (either <input> or -f, --file).');
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
/* Define one-source content */
|
|
37
|
+
const content = hasFile
|
|
38
|
+
? (() => {
|
|
39
|
+
try {
|
|
40
|
+
return fs.readFileSync(options.file, 'utf-8');
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
console.error(`error: failed to read file "${options.file}"`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
})()
|
|
47
|
+
: input;
|
|
48
|
+
console.log(parse(content));
|
|
10
49
|
}
|
|
11
|
-
|
|
50
|
+
command();
|
package/package.json
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokelamen/md2html",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
3
|
"type": "module",
|
|
4
|
+
"version": "0.1.1",
|
|
5
|
+
"description": "A simple tool to convert markdown content to html",
|
|
6
|
+
"author": "rokelamen <rogerskelamen@gmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "dist/index.js",
|
|
7
9
|
"bin": {
|
|
8
|
-
"md2html
|
|
10
|
+
"md2html": "./dist/index.js"
|
|
9
11
|
},
|
|
10
12
|
"scripts": {
|
|
11
13
|
"clean": "rimraf dist",
|
|
12
14
|
"build": "npm run clean && tsc",
|
|
13
|
-
"dev": "ts-node src/index.ts",
|
|
14
15
|
"prepublishOnly": "npm run build"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"dist"
|
|
18
19
|
],
|
|
19
|
-
"keywords": [
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
"keywords": [
|
|
21
|
+
"cli",
|
|
22
|
+
"typescript",
|
|
23
|
+
"md2html"
|
|
24
|
+
],
|
|
22
25
|
"devDependencies": {
|
|
23
26
|
"@types/commander": "^2.12.0",
|
|
24
27
|
"@types/node": "^25.0.3",
|
|
25
28
|
"rimraf": "^6.1.2",
|
|
26
|
-
"ts-node": "^10.9.2",
|
|
27
29
|
"typescript": "^5.9.3"
|
|
28
30
|
},
|
|
29
31
|
"dependencies": {
|