mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Start to refactor mermaid.js
This commit is contained in:
parent
c071503f19
commit
626fdfe345
1
.ackrc
1
.ackrc
@ -1,3 +1,2 @@
|
|||||||
--ignore-dir=dist
|
--ignore-dir=dist
|
||||||
--ignore-file=match:/^yarn\.lock$/
|
--ignore-file=match:/^yarn\.lock$/
|
||||||
--ignore-dir=test
|
|
||||||
|
45
src/logger.new.js
Normal file
45
src/logger.new.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import moment from 'moment'
|
||||||
|
import chalk from 'chalk'
|
||||||
|
|
||||||
|
export const Log = {
|
||||||
|
debug: () => {},
|
||||||
|
info: () => {},
|
||||||
|
warn: () => {},
|
||||||
|
error: () => {},
|
||||||
|
fatal: () => {}
|
||||||
|
}
|
||||||
|
export const level = {
|
||||||
|
debug: 1,
|
||||||
|
info: 2,
|
||||||
|
warn: 3,
|
||||||
|
error: 4,
|
||||||
|
fatal: 5
|
||||||
|
}
|
||||||
|
|
||||||
|
export const setLogLevel = function (level) {
|
||||||
|
Log.fatal = () => {}
|
||||||
|
Log.error = () => {}
|
||||||
|
Log.warn = () => {}
|
||||||
|
Log.info = () => {}
|
||||||
|
Log.debug = () => {}
|
||||||
|
if (level <= level.fatal) {
|
||||||
|
Log.fatal = (message) => chalk.bgHex('#DDDDDD').red(format('FATAL', message))
|
||||||
|
}
|
||||||
|
if (level <= level.error) {
|
||||||
|
Log.error = (message) => chalk.bgHex('#DDDDDD').red(format('ERROR', message))
|
||||||
|
}
|
||||||
|
if (level <= level.warn) {
|
||||||
|
Log.warn = (message) => chalk.bgHex('#DDDDDD').orange(format('WARN', message))
|
||||||
|
}
|
||||||
|
if (level <= level.info) {
|
||||||
|
Log.info = (message) => chalk.bgHex('#DDDDDD').blue(format('INFO', message))
|
||||||
|
}
|
||||||
|
if (level <= level.debug) {
|
||||||
|
Log.debug = (message) => chalk.bgHex('#DDDDDD').green(format('DEBUG', message))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const format = (level, message) => {
|
||||||
|
const time = moment().format('HH:mm:ss (SSS)')
|
||||||
|
return `${level} : ${time} : ${message}`
|
||||||
|
}
|
@ -2,14 +2,13 @@
|
|||||||
* Web page integration module for the mermaid framework. It uses the mermaidAPI for mermaid functionality and to render
|
* Web page integration module for the mermaid framework. It uses the mermaidAPI for mermaid functionality and to render
|
||||||
* the diagrams to svg code.
|
* the diagrams to svg code.
|
||||||
*/
|
*/
|
||||||
|
var he = require('he')
|
||||||
|
|
||||||
var Logger = require('./logger')
|
var Logger = require('./logger')
|
||||||
var log = Logger.Log
|
var log = Logger.Log
|
||||||
var mermaidAPI = require('./mermaidAPI')
|
var mermaidAPI = require('./mermaidAPI')
|
||||||
var nextId = 0
|
var nextId = 0
|
||||||
|
|
||||||
var he = require('he')
|
|
||||||
|
|
||||||
module.exports.mermaidAPI = mermaidAPI
|
module.exports.mermaidAPI = mermaidAPI
|
||||||
/**
|
/**
|
||||||
* ## init
|
* ## init
|
||||||
@ -111,14 +110,14 @@ var init = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.init = init
|
module.exports.init = init
|
||||||
exports.parse = mermaidAPI.parse
|
module.exports.parse = mermaidAPI.parse
|
||||||
/**
|
/**
|
||||||
* ## version
|
* ## version
|
||||||
* Function returning version information
|
* Function returning version information
|
||||||
* @returns {string} A string containing the version info
|
* @returns {string} A string containing the version info
|
||||||
*/
|
*/
|
||||||
exports.version = function () {
|
module.exports.version = function () {
|
||||||
return 'v' + require('../package.json').version
|
return 'v' + require('../package.json').version
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +126,7 @@ exports.version = function () {
|
|||||||
* This function overrides the default configuration.
|
* This function overrides the default configuration.
|
||||||
* @param config
|
* @param config
|
||||||
*/
|
*/
|
||||||
exports.initialize = function (config) {
|
module.exports.initialize = function (config) {
|
||||||
log.debug('Initializing mermaid')
|
log.debug('Initializing mermaid')
|
||||||
if (typeof config.mermaid !== 'undefined') {
|
if (typeof config.mermaid !== 'undefined') {
|
||||||
if (typeof config.mermaid.startOnLoad !== 'undefined') {
|
if (typeof config.mermaid.startOnLoad !== 'undefined') {
|
||||||
@ -165,7 +164,7 @@ global.mermaid = {
|
|||||||
init.apply(null, arguments)
|
init.apply(null, arguments)
|
||||||
},
|
},
|
||||||
initialize: function (config) {
|
initialize: function (config) {
|
||||||
exports.initialize(config)
|
module.exports.initialize(config)
|
||||||
},
|
},
|
||||||
version: function () {
|
version: function () {
|
||||||
return mermaidAPI.version()
|
return mermaidAPI.version()
|
||||||
@ -187,14 +186,14 @@ global.mermaid = {
|
|||||||
* This function overrides the default configuration.
|
* This function overrides the default configuration.
|
||||||
* @param config
|
* @param config
|
||||||
*/
|
*/
|
||||||
exports.parseError = global.mermaid.parseError
|
module.exports.parseError = global.mermaid.parseError
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ##contentLoaded
|
* ##contentLoaded
|
||||||
* Callback function that is called when page is loaded. This functions fetches configuration for mermaid rendering and
|
* Callback function that is called when page is loaded. This functions fetches configuration for mermaid rendering and
|
||||||
* calls init for rendering the mermaid diagrams on the page.
|
* calls init for rendering the mermaid diagrams on the page.
|
||||||
*/
|
*/
|
||||||
exports.contentLoaded = function () {
|
module.exports.contentLoaded = function () {
|
||||||
var config
|
var config
|
||||||
// Check state of start config mermaid namespace
|
// Check state of start config mermaid namespace
|
||||||
if (typeof global.mermaid_config !== 'undefined') {
|
if (typeof global.mermaid_config !== 'undefined') {
|
||||||
@ -233,6 +232,6 @@ if (typeof document !== 'undefined') {
|
|||||||
* Wait for document loaded before starting the execution
|
* Wait for document loaded before starting the execution
|
||||||
*/
|
*/
|
||||||
window.addEventListener('load', function () {
|
window.addEventListener('load', function () {
|
||||||
exports.contentLoaded()
|
module.exports.contentLoaded()
|
||||||
}, false)
|
}, false)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user