node-plantuml-2 1.0.0
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/LICENSE +21 -0
- package/README.md +1053 -0
- package/index.js +8 -0
- package/lib/node-plantuml-cmd.js +110 -0
- package/lib/node-plantuml.js +446 -0
- package/lib/plantuml-executor-wasm.js +295 -0
- package/lib/plantuml-executor.js +165 -0
- package/lib/plantuml-syntax-fixer.js +545 -0
- package/nail/plantumlnail.jar +0 -0
- package/package.json +66 -0
- package/resources/classic.puml +31 -0
- package/resources/monochrome.puml +1 -0
- package/scripts/download.js +95 -0
- package/scripts/get-vizjs.js +51 -0
- package/vendor/plantuml.jar +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var url = require('url')
|
|
4
|
+
var fs = require('fs')
|
|
5
|
+
|
|
6
|
+
var trace = []
|
|
7
|
+
var MAX_RETRIES = 5
|
|
8
|
+
var INITIAL_RETRY_DELAY = 2000 // 2 seconds
|
|
9
|
+
|
|
10
|
+
function sleep (ms) {
|
|
11
|
+
return new Promise(function (resolve) {
|
|
12
|
+
setTimeout(resolve, ms)
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function downloadWithRetry (uri, filename, changeExitCodeOnError, callback, retryCount) {
|
|
17
|
+
retryCount = retryCount || 0
|
|
18
|
+
trace.push('GET ' + uri + (retryCount > 0 ? ' (retry ' + retryCount + ')' : ''))
|
|
19
|
+
var protocol = url.parse(uri).protocol.slice(0, -1)
|
|
20
|
+
|
|
21
|
+
require(protocol).get(uri, function (res) {
|
|
22
|
+
trace.push('Reponse: ' + res.statusCode)
|
|
23
|
+
if (res.statusCode === 200) {
|
|
24
|
+
// Success, pipe to file
|
|
25
|
+
var fileStream = fs.createWriteStream(filename)
|
|
26
|
+
res.pipe(fileStream)
|
|
27
|
+
if (callback) {
|
|
28
|
+
res.on('end', function () {
|
|
29
|
+
callback()
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
fileStream.on('error', function (err) {
|
|
33
|
+
if (callback) {
|
|
34
|
+
callback(err)
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
} else if (res.headers.location) {
|
|
38
|
+
// Follow redirect
|
|
39
|
+
downloadWithRetry(res.headers.location, filename, changeExitCodeOnError, callback, retryCount)
|
|
40
|
+
} else if ((res.statusCode === 429 || res.statusCode === 503 || res.statusCode === 502) && retryCount < MAX_RETRIES) {
|
|
41
|
+
// Rate limited or server error - retry with exponential backoff
|
|
42
|
+
var retryDelay = INITIAL_RETRY_DELAY * Math.pow(2, retryCount)
|
|
43
|
+
var retryAfter = res.headers['retry-after']
|
|
44
|
+
if (retryAfter) {
|
|
45
|
+
retryDelay = parseInt(retryAfter) * 1000
|
|
46
|
+
}
|
|
47
|
+
console.log('Rate limited or server error (' + res.statusCode + '). Retrying in ' + (retryDelay / 1000) + ' seconds...')
|
|
48
|
+
sleep(retryDelay).then(function () {
|
|
49
|
+
downloadWithRetry(uri, filename, changeExitCodeOnError, callback, retryCount + 1)
|
|
50
|
+
})
|
|
51
|
+
} else {
|
|
52
|
+
// Error
|
|
53
|
+
trace.forEach(function (line) {
|
|
54
|
+
console.error(line)
|
|
55
|
+
})
|
|
56
|
+
var error = 'Failed to download ' + filename
|
|
57
|
+
console.error(error)
|
|
58
|
+
|
|
59
|
+
if (changeExitCodeOnError) {
|
|
60
|
+
process.exitCode = 1
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (callback) {
|
|
64
|
+
callback(error)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}).on('error', function (err) {
|
|
68
|
+
if (retryCount < MAX_RETRIES) {
|
|
69
|
+
// Network error - retry with exponential backoff
|
|
70
|
+
var retryDelay = INITIAL_RETRY_DELAY * Math.pow(2, retryCount)
|
|
71
|
+
console.log('Network error. Retrying in ' + (retryDelay / 1000) + ' seconds...')
|
|
72
|
+
sleep(retryDelay).then(function () {
|
|
73
|
+
downloadWithRetry(uri, filename, changeExitCodeOnError, callback, retryCount + 1)
|
|
74
|
+
})
|
|
75
|
+
} else {
|
|
76
|
+
trace.forEach(function (line) {
|
|
77
|
+
console.error(line)
|
|
78
|
+
})
|
|
79
|
+
var error = 'Failed to download ' + filename + ': ' + err.message
|
|
80
|
+
console.error(error)
|
|
81
|
+
|
|
82
|
+
if (changeExitCodeOnError) {
|
|
83
|
+
process.exitCode = 1
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (callback) {
|
|
87
|
+
callback(error)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = function download (uri, filename, changeExitCodeOnError, callback) {
|
|
94
|
+
downloadWithRetry(uri, filename, changeExitCodeOnError, callback, 0)
|
|
95
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
var fs = require('fs')
|
|
5
|
+
var path = require('path')
|
|
6
|
+
var download = require('./download')
|
|
7
|
+
|
|
8
|
+
var JAR_DIR_PATH = path.join(__dirname, '../vendor')
|
|
9
|
+
var VIZJS_JAR = path.join(JAR_DIR_PATH, 'vizjs.jar')
|
|
10
|
+
var J2V8_WIN_JAR = path.join(JAR_DIR_PATH, 'j2v8_win32_x86_64-3.1.6.jar')
|
|
11
|
+
var J2V8_LINUX_JAR = path.join(JAR_DIR_PATH, 'j2v8_linux_x86_64-3.1.6.jar')
|
|
12
|
+
var J2V8_MAC_JAR = path.join(JAR_DIR_PATH, 'j2v8_macosx_x86_64-3.1.6.jar')
|
|
13
|
+
|
|
14
|
+
var VIZJS_URL = 'http://beta.plantuml.net/vizjs.jar'
|
|
15
|
+
var J2V8_WIN_URL = 'http://beta.plantuml.net/j2v8_win32_x86_64-3.1.6.jar'
|
|
16
|
+
var J2V8_LINUX_URL = 'http://beta.plantuml.net/j2v8_linux_x86_64-3.1.6.jar'
|
|
17
|
+
var J2V8_MAC_URL = 'http://beta.plantuml.net/j2v8_macosx_x86_64-3.1.6.jar'
|
|
18
|
+
|
|
19
|
+
var plantuml = require('../lib/node-plantuml')
|
|
20
|
+
|
|
21
|
+
if (!fs.existsSync(JAR_DIR_PATH)) {
|
|
22
|
+
fs.mkdirSync(JAR_DIR_PATH)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
plantuml.testdot(function (isOk) {
|
|
26
|
+
if (isOk) {
|
|
27
|
+
console.info('graphviz was found on the system. Skipping download of vizjs.')
|
|
28
|
+
} else {
|
|
29
|
+
console.info('graphviz was not found on the system. Downloading vizjs instead. See http://plantuml.com/vizjs. This may take a few minutes.')
|
|
30
|
+
|
|
31
|
+
// download additional libraries for working without dot installed.
|
|
32
|
+
download(VIZJS_URL, VIZJS_JAR, false, function (err) {
|
|
33
|
+
if (!err) {
|
|
34
|
+
// also install the V8 engine just in case the currently installed Java does not have Nashorn
|
|
35
|
+
switch (process.platform) {
|
|
36
|
+
case 'win32':
|
|
37
|
+
download(J2V8_WIN_URL, J2V8_WIN_JAR, false)
|
|
38
|
+
break
|
|
39
|
+
case 'linux':
|
|
40
|
+
download(J2V8_LINUX_URL, J2V8_LINUX_JAR, false)
|
|
41
|
+
break
|
|
42
|
+
case 'darwin':
|
|
43
|
+
download(J2V8_MAC_URL, J2V8_MAC_JAR, false)
|
|
44
|
+
break
|
|
45
|
+
default:
|
|
46
|
+
console.error('Unsupported operating system for V8 jars.')
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
})
|
|
Binary file
|