@mryhryki/markdown-preview 0.4.3 → 0.5.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 +1 -1
- package/index.js +1 -1
- package/package.json +45 -13
- package/src/index.js +46 -43
- package/src/lib/directory.js +9 -13
- package/src/lib/file.js +15 -14
- package/src/lib/file_watcher.js +56 -56
- package/src/lib/logger.js +41 -22
- package/src/lib/params.js +161 -180
- package/src/lib/params.test.js +97 -97
- package/src/lib/show.js +37 -18
- package/src/lib/socket_manager.js +20 -24
- package/src/lib/socket_manager.test.js +27 -36
- package/src/markdown.js +19 -14
- package/src/websocket.js +39 -38
- package/static/css/github-markdown-dark.min.css +1 -1
- package/static/css/github-markdown-light.min.css +1 -1
- package/static/javascript/highlight.min.js +1065 -1215
- package/static/javascript/marked.min.js +3 -3
- package/template/default-dark.html +3 -3
- package/template/default.html +3 -3
- package/.editorconfig +0 -7
- package/.eslintrc.yaml +0 -34
- package/.github/dependabot.yml +0 -15
- package/.github/workflows/check.yml +0 -32
- package/.github/workflows/update_packages.yml +0 -35
- package/.prettierrc.json +0 -3
- package/CODEOWNERS +0 -1
- package/download_static_files.sh +0 -26
- package/test/markdown/markdown1.md +0 -1
- package/test/template/template1.html +0 -16
package/README.md
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mryhryki/markdown-preview",
|
|
3
3
|
"description": "Markdown realtime preview on browser",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"author": "mryhryki",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
@@ -20,32 +20,64 @@
|
|
|
20
20
|
"url": "https://github.com/mryhryki/markdown-preview/issues"
|
|
21
21
|
},
|
|
22
22
|
"engines": {
|
|
23
|
-
"node": ">=
|
|
24
|
-
"npm": ">=
|
|
23
|
+
"node": ">=18.0.0",
|
|
24
|
+
"npm": ">=9.0.0"
|
|
25
25
|
},
|
|
26
26
|
"main": "index.js",
|
|
27
27
|
"bin": {
|
|
28
28
|
"markdown-preview": "index.js"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"express": "^4.18.
|
|
31
|
+
"express": "^4.18.3",
|
|
32
32
|
"express-ws": "^5.0.2",
|
|
33
33
|
"log4js": "^6.9.1",
|
|
34
34
|
"opener": "^1.5.2",
|
|
35
35
|
"serve-index": "^1.9.1",
|
|
36
|
-
"ws": "^8.
|
|
36
|
+
"ws": "^8.16.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"
|
|
41
|
-
"
|
|
39
|
+
"@types/express": "^4.17.21",
|
|
40
|
+
"@types/express-ws": "^3.0.4",
|
|
41
|
+
"@types/jest": "^29.5.12",
|
|
42
|
+
"@types/opener": "^1.4.3",
|
|
43
|
+
"@types/serve-index": "^1.9.4",
|
|
44
|
+
"eslint": "^8.57.0",
|
|
45
|
+
"eslint-config-prettier": "^9.1.0",
|
|
46
|
+
"eslint-plugin-jest": "^27.9.0",
|
|
47
|
+
"eslint-plugin-node": "^11.1.0",
|
|
48
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
49
|
+
"eslint-plugin-react": "^7.34.1",
|
|
50
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
51
|
+
"eslint-plugin-simple-import-sort": "^12.0.0",
|
|
52
|
+
"eslint-plugin-unused-imports": "^3.1.0",
|
|
53
|
+
"jest": "^29.7.0",
|
|
54
|
+
"nodemon": "^3.1.0",
|
|
55
|
+
"ts-jest": "^29.1.2",
|
|
56
|
+
"typescript": "^5.4.2"
|
|
42
57
|
},
|
|
43
58
|
"scripts": {
|
|
44
|
-
"
|
|
45
|
-
"dev": "nodemon --watch ./src/
|
|
46
|
-
"lint": "
|
|
47
|
-
"lint:fix": "
|
|
59
|
+
"build": "tsc",
|
|
60
|
+
"dev": "nodemon --watch ./src/ --ext 'ts' --exec 'npm start -- --no-opener --log-level debug'",
|
|
61
|
+
"lint": "eslint ./src/",
|
|
62
|
+
"lint:fix": "eslint ./src/ --fix",
|
|
63
|
+
"release": "npm run build && npm publish",
|
|
64
|
+
"start": "npm run build && node ./index.js",
|
|
48
65
|
"test": "jest",
|
|
49
|
-
"test:watch": "jest --watchAll"
|
|
66
|
+
"test:watch": "jest --watchAll",
|
|
67
|
+
"type": "tsc --noEmit",
|
|
68
|
+
"type:watch": "tsc --noEmit --watch"
|
|
69
|
+
},
|
|
70
|
+
"files": [
|
|
71
|
+
"index.js",
|
|
72
|
+
"src/**/*.js",
|
|
73
|
+
"static/**/*",
|
|
74
|
+
"template/**/*"
|
|
75
|
+
],
|
|
76
|
+
"prettier": {
|
|
77
|
+
"printWidth": 120
|
|
78
|
+
},
|
|
79
|
+
"jest": {
|
|
80
|
+
"preset": "ts-jest",
|
|
81
|
+
"testEnvironment": "node"
|
|
50
82
|
}
|
|
51
83
|
}
|
package/src/index.js
CHANGED
|
@@ -1,46 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const express_1 = __importDefault(require("express"));
|
|
7
|
+
const express_ws_1 = __importDefault(require("express-ws"));
|
|
8
|
+
const serve_index_1 = __importDefault(require("serve-index"));
|
|
9
|
+
const opener_1 = __importDefault(require("opener"));
|
|
10
|
+
const logger_1 = require("./lib/logger");
|
|
11
|
+
const show_1 = require("./lib/show");
|
|
12
|
+
const markdown_1 = require("./markdown");
|
|
13
|
+
const websocket_1 = require("./websocket");
|
|
14
|
+
const directory_1 = require("./lib/directory");
|
|
15
|
+
const params_1 = require("./lib/params");
|
|
14
16
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
17
|
+
const params = new params_1.Params(process.env, process.argv.slice(2));
|
|
18
|
+
if (params.help)
|
|
19
|
+
(0, show_1.showUsage)();
|
|
20
|
+
if (params.version)
|
|
21
|
+
(0, show_1.showVersion)();
|
|
22
|
+
const logger = (0, logger_1.getLogger)(params.logLevel);
|
|
23
|
+
const previewUrl = `http://localhost:${params.port}`;
|
|
24
|
+
console.log("Root Directory :", directory_1.rootDir);
|
|
25
|
+
console.log("Default File :", params.filepath);
|
|
26
|
+
console.log("Extensions :", params.extensions.join(", "));
|
|
27
|
+
console.log("Template File :", params.template);
|
|
28
|
+
console.log(`Preview URL : ${previewUrl}`);
|
|
29
|
+
const app = (0, express_1.default)();
|
|
30
|
+
(0, express_ws_1.default)(app);
|
|
31
|
+
app.get("/", (_req, res) => res.redirect(params.filepath));
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
app.ws("/ws", (0, websocket_1.WebSocketHandler)(logger));
|
|
35
|
+
params.extensions.forEach((ext) => {
|
|
36
|
+
app.get(new RegExp(`^/.+\.${ext}$`), (0, markdown_1.MarkdownHandler)(params.template));
|
|
37
|
+
});
|
|
38
|
+
app.use(express_1.default.static(directory_1.rootDir, { index: false }));
|
|
39
|
+
app.use(express_1.default.static(directory_1.staticDir, { index: false }));
|
|
40
|
+
app.use((0, serve_index_1.default)(directory_1.rootDir, { icons: true, view: "details" }));
|
|
41
|
+
app.listen(params.port);
|
|
42
|
+
if (!params.noOpener) {
|
|
43
|
+
(0, opener_1.default)(previewUrl);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
console.error(err);
|
|
48
|
+
(0, show_1.showUsage)(true);
|
|
46
49
|
}
|
package/src/lib/directory.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const rootDir = process.cwd();
|
|
6
|
-
const projectDir = path.resolve(__dirname, "..", "..");
|
|
7
|
-
const staticDir = path.resolve(projectDir, "static");
|
|
8
|
-
const templateDir = path.resolve(projectDir, "template");
|
|
9
|
-
|
|
10
|
-
module.exports = {
|
|
11
|
-
rootDir,
|
|
12
|
-
projectDir,
|
|
13
|
-
staticDir,
|
|
14
|
-
templateDir,
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.templateDir = exports.staticDir = exports.projectDir = exports.rootDir = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
exports.rootDir = process.cwd();
|
|
9
|
+
exports.projectDir = path_1.default.resolve(__dirname, "..", "..");
|
|
10
|
+
exports.staticDir = path_1.default.resolve(exports.projectDir, "static");
|
|
11
|
+
exports.templateDir = path_1.default.resolve(exports.projectDir, "template");
|
package/src/lib/file.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const existsFile = (filepath) => {
|
|
6
|
-
try {
|
|
7
|
-
fs.statSync(filepath);
|
|
8
|
-
return true;
|
|
9
|
-
} catch (_) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
existsFile,
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
4
|
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.existsFile = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
function existsFile(filepath) {
|
|
9
|
+
try {
|
|
10
|
+
fs_1.default.statSync(filepath);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch (_) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.existsFile = existsFile;
|
package/src/lib/file_watcher.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FileWatcher = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const directory_1 = require("./directory");
|
|
7
10
|
class FileWatcher {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return { filepath, markdown };
|
|
56
|
-
}
|
|
11
|
+
constructor(logger) {
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
this._target = {};
|
|
14
|
+
setInterval(() => {
|
|
15
|
+
Object.keys(this._target).forEach((filepath) => {
|
|
16
|
+
try {
|
|
17
|
+
const fileinfo = this._target[filepath];
|
|
18
|
+
const currentLastModified = this.getFileLastModified(filepath);
|
|
19
|
+
if (fileinfo.lastModified !== currentLastModified) {
|
|
20
|
+
this.logger.info("File update:", path_1.default.resolve(directory_1.rootDir, filepath));
|
|
21
|
+
fileinfo.lastModified = currentLastModified;
|
|
22
|
+
if (this._onFileChanged != null) {
|
|
23
|
+
this._onFileChanged(this.getFileInfo(filepath));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.error(err);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}, 250 /* check 4 times per second */);
|
|
32
|
+
}
|
|
33
|
+
onFileChanged(callback) {
|
|
34
|
+
this._onFileChanged = callback;
|
|
35
|
+
}
|
|
36
|
+
addTargetFile(filepath) {
|
|
37
|
+
if (this._target[filepath] != null)
|
|
38
|
+
return;
|
|
39
|
+
this.logger.debug("Add watch target:", filepath);
|
|
40
|
+
this._target[filepath] = {
|
|
41
|
+
lastModified: this.getFileLastModified(filepath),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
removeTargetFile(filepath) {
|
|
45
|
+
if (this._target[filepath] == null)
|
|
46
|
+
return;
|
|
47
|
+
this.logger.debug("Remove watch target:", filepath);
|
|
48
|
+
delete this._target[filepath];
|
|
49
|
+
}
|
|
50
|
+
getFileLastModified(filepath) {
|
|
51
|
+
return fs_1.default.statSync(path_1.default.resolve(directory_1.rootDir, filepath)).mtimeMs;
|
|
52
|
+
}
|
|
53
|
+
getFileInfo(filepath) {
|
|
54
|
+
const absolutePath = path_1.default.resolve(directory_1.rootDir, filepath);
|
|
55
|
+
const markdown = fs_1.default.readFileSync(absolutePath, "utf-8");
|
|
56
|
+
return { filepath, markdown };
|
|
57
|
+
}
|
|
57
58
|
}
|
|
58
|
-
|
|
59
|
-
module.exports = FileWatcher;
|
|
59
|
+
exports.FileWatcher = FileWatcher;
|
package/src/lib/logger.js
CHANGED
|
@@ -1,23 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
log4js.configure({
|
|
5
|
-
appenders: {
|
|
6
|
-
console: {
|
|
7
|
-
type: "console",
|
|
8
|
-
layout: {
|
|
9
|
-
type: "basic",
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
categories: {
|
|
14
|
-
default: {
|
|
15
|
-
appenders: ["console"],
|
|
16
|
-
level: logLevel,
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
return log4js.getLogger();
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
4
|
};
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getLogger = exports.getLogLevel = void 0;
|
|
7
|
+
const log4js_1 = __importDefault(require("log4js"));
|
|
8
|
+
const LogLevels = ["trace", "debug", "info", "warn", "error", "fatal"];
|
|
9
|
+
function getLogLevel(level) {
|
|
10
|
+
switch (level) {
|
|
11
|
+
case "trace":
|
|
12
|
+
case "debug":
|
|
13
|
+
case "info":
|
|
14
|
+
case "warn":
|
|
15
|
+
case "error":
|
|
16
|
+
case "fatal":
|
|
17
|
+
return level;
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Undefined log level: ${level}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.getLogLevel = getLogLevel;
|
|
23
|
+
function getLogger(logLevel) {
|
|
24
|
+
log4js_1.default.configure({
|
|
25
|
+
appenders: {
|
|
26
|
+
console: {
|
|
27
|
+
type: "console",
|
|
28
|
+
layout: {
|
|
29
|
+
type: "basic",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
categories: {
|
|
34
|
+
default: {
|
|
35
|
+
appenders: ["console"],
|
|
36
|
+
level: logLevel,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
return log4js_1.default.getLogger();
|
|
41
|
+
}
|
|
42
|
+
exports.getLogger = getLogger;
|