Skip to content

Commit

Permalink
resolves #1510 Add D2 sketch option (#1520)
Browse files Browse the repository at this point in the history
Co-authored-by: root <root@FELIX-PC>
  • Loading branch information
felixvanoost and root authored Apr 25, 2023
1 parent c3f18b1 commit c2013f7
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 487 deletions.
14 changes: 5 additions & 9 deletions ci/tasks/update-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ try {

const dockerfileContent = await fs.readFile(ospath.join(rootDir, 'server', 'ops', 'docker', 'jdk11-jammy', 'Dockerfile'), 'utf8')
for (const line of dockerfileContent.split('\n')) {
const d2VersionFound = line.match(/^ARG D2_VERSION="(?<version>.+)"$/)
if (d2VersionFound) {
const { version } = d2VersionFound.groups
diagramLibraryVersions.d2 = version
}
const erdVersionFound = line.match(/^FROM yuzutech\/kroki-builder-erd:(?<version>\S+) AS kroki-builder-static-erd$/)
if (erdVersionFound) {
const { version } = erdVersionFound.groups
Expand All @@ -195,15 +200,6 @@ try {
}
}

const d2GoModContent = await fs.readFile(ospath.join(rootDir, 'server', 'ops', 'docker', 'go.mod'), 'utf8')
for (const line of d2GoModContent.split('\n')) {
const d2VersionFound = line.match(/^require oss.terrastruct.com\/d2 v(?<version>.+)$/)
if (d2VersionFound) {
const { version } = d2VersionFound.groups
diagramLibraryVersions.d2 = version
}
}

const svgbobCargoContent = await fs.readFile(ospath.join(rootDir, 'server', 'ops', 'docker', 'Cargo.toml'), 'utf8')
for (const line of svgbobCargoContent.split('\n')) {
const svgbobVersionFound = line.match(/^svgbob_cli\s*=\s*"(?<version>.+)"$/)
Expand Down
79 changes: 43 additions & 36 deletions ci/tests/smoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,41 @@ import * as url from 'url'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))

const tests = [
{engine: 'graphviz', file: 'hello.dot', outputFormat: ['svg', 'jpeg']},
{engine: 'dot', file: 'hello.dot', outputFormat: ['svg', 'jpeg']},
{engine: 'blockdiag', file: 'kroki.diag', outputFormat: ['svg', 'png']},
{engine: 'seqdiag', file: 'sequence.diag', outputFormat: ['svg', 'png']},
{engine: 'actdiag', file: 'actions.diag', outputFormat: ['svg', 'png']},
{engine: 'nwdiag', file: 'network.diag', outputFormat: ['svg', 'png']},
{engine: 'c4plantuml', file: 'banking-system.puml', outputFormat: ['svg']},
{engine: 'dbml', file: 'dbml.dbml', outputFormat: ['svg']},
{engine: 'ditaa', file: 'components.ditaa', outputFormat: ['svg']},
{engine: 'erd', file: 'schema.erd', outputFormat: ['svg']},
{engine: 'mermaid', file: 'contribute.mmd', outputFormat: ['svg']},
{engine: 'bpmn', file: 'example.bpmn', outputFormat: ['svg']},
{engine: 'plantuml', file: 'architecture.puml', outputFormat: ['svg']},
{engine: 'svgbob', file: 'cloud.bob', outputFormat: ['svg']},
{engine: 'nomnoml', file: 'pirate.nomnoml', outputFormat: ['svg']},
{engine: 'packetdiag', file: 'packet.diag', outputFormat: ['svg', 'png']},
{engine: 'rackdiag', file: 'rack.diag', outputFormat: ['svg', 'png']},
{engine: 'vega', file: 'bar-chart.vega', outputFormat: ['svg', 'png', 'pdf']},
{engine: 'vegalite', file: 'discretizing-scale.vlite', outputFormat: ['svg', 'png', 'pdf']},
{engine: 'wavedrom', file: 'wavedrom.json5', outputFormat: ['svg']},
{engine: 'wavedrom', file: 'bitfield.json5', outputFormat: ['svg']},
{engine: 'bytefield', file: 'bytefield.bf', outputFormat: ['svg']},
{engine: 'umlet', file: 'umlet.xml', outputFormat: ['svg']},
{engine: 'excalidraw', file: 'venn.excalidraw', outputFormat: ['svg']},
{engine: 'pikchr', file: 'sqlite-architecture.pikchr', outputFormat: ['svg']},
{engine: 'structurizr', file: 'gettingstarted.structurizr', outputFormat: ['svg']},
{engine: 'diagramsnet', file: 'diagramsnet-infography.xml', outputFormat: ['svg', 'png']},
{engine: 'diagramsnet', file: 'diagramsnet-mindmap.xml', outputFormat: ['svg', 'png']},
{engine: 'diagramsnet', file: 'diagramsnet-network.xml', outputFormat: ['svg', 'png']},
{engine: 'diagramsnet', file: 'diagramsnet-ui.xml', outputFormat: ['svg', 'png']},
{engine: 'diagramsnet', file: 'diagramsnet-venn.xml', outputFormat: ['svg', 'png']},
{engine: 'd2', file: 'connections.d2', outputFormat: ['svg']},
{engine: 'wireviz', file: 'wireviz.yaml', outputFormat: ['svg', 'png']},
{engine: 'tikz', file: 'periodic-table.tex', outputFormat: ['jpeg', 'pdf', 'png', 'svg']}
{engine: 'graphviz', file: 'hello.dot', options: {}, outputFormat: ['svg', 'jpeg']},
{engine: 'dot', file: 'hello.dot', options: {}, outputFormat: ['svg', 'jpeg']},
{engine: 'blockdiag', file: 'kroki.diag', options: {}, outputFormat: ['svg', 'png']},
{engine: 'seqdiag', file: 'sequence.diag', options: {}, outputFormat: ['svg', 'png']},
{engine: 'actdiag', file: 'actions.diag', options: {}, outputFormat: ['svg', 'png']},
{engine: 'nwdiag', file: 'network.diag', options: {}, outputFormat: ['svg', 'png']},
{engine: 'c4plantuml', file: 'banking-system.puml', options: {}, outputFormat: ['svg']},
{engine: 'dbml', file: 'dbml.dbml', options: {}, outputFormat: ['svg']},
{engine: 'ditaa', file: 'components.ditaa', options: {}, outputFormat: ['svg']},
{engine: 'erd', file: 'schema.erd', options: {}, outputFormat: ['svg']},
{engine: 'mermaid', file: 'contribute.mmd', options: {}, outputFormat: ['svg']},
{engine: 'bpmn', file: 'example.bpmn', options: {}, outputFormat: ['svg']},
{engine: 'plantuml', file: 'architecture.puml', options: {}, outputFormat: ['svg']},
{engine: 'svgbob', file: 'cloud.bob', options: {}, outputFormat: ['svg']},
{engine: 'nomnoml', file: 'pirate.nomnoml', options: {}, outputFormat: ['svg']},
{engine: 'packetdiag', file: 'packet.diag', options: {}, outputFormat: ['svg', 'png']},
{engine: 'rackdiag', file: 'rack.diag', options: {}, outputFormat: ['svg', 'png']},
{engine: 'vega', file: 'bar-chart.vega', options: {}, outputFormat: ['svg', 'png', 'pdf']},
{engine: 'vegalite', file: 'discretizing-scale.vlite', options: {}, outputFormat: ['svg', 'png', 'pdf']},
{engine: 'wavedrom', file: 'wavedrom.json5', options: {}, outputFormat: ['svg']},
{engine: 'wavedrom', file: 'bitfield.json5', options: {}, outputFormat: ['svg']},
{engine: 'bytefield', file: 'bytefield.bf', options: {}, outputFormat: ['svg']},
{engine: 'umlet', file: 'umlet.xml', options: {}, outputFormat: ['svg']},
{engine: 'excalidraw', file: 'venn.excalidraw', options: {}, outputFormat: ['svg']},
{engine: 'pikchr', file: 'sqlite-architecture.pikchr', options: {}, outputFormat: ['svg']},
{engine: 'structurizr', file: 'gettingstarted.structurizr', options: {}, outputFormat: ['svg']},
{engine: 'diagramsnet', file: 'diagramsnet-infography.xml', options: {}, outputFormat: ['svg', 'png']},
{engine: 'diagramsnet', file: 'diagramsnet-mindmap.xml', options: {}, outputFormat: ['svg', 'png']},
{engine: 'diagramsnet', file: 'diagramsnet-network.xml', options: {}, outputFormat: ['svg', 'png']},
{engine: 'diagramsnet', file: 'diagramsnet-ui.xml', options: {}, outputFormat: ['svg', 'png']},
{engine: 'diagramsnet', file: 'diagramsnet-venn.xml', options: {}, outputFormat: ['svg', 'png']},
{engine: 'd2', file: 'connections.d2', options: {}, outputFormat: ['svg']},
{engine: 'd2', file: 'connections.d2', options: {sketch: 'true'}, outputFormat: ['svg']},
{engine: 'wireviz', file: 'wireviz.yaml', options: {}, outputFormat: ['svg', 'png']},
{engine: 'tikz', file: 'periodic-table.tex', options: {}, outputFormat: ['jpeg', 'pdf', 'png', 'svg']}
]

chai.use(chaiHttp)
Expand All @@ -54,13 +55,19 @@ const mimeType = {

const sendRequest = async (testCase, outputFormat) => {
try {
return await chai.request('localhost:8000')
let request = chai.request('localhost:8000')
.post(`/${testCase.engine}/${outputFormat}`)
.type('text/plain')
.set('Content-Type', 'text/plain')
.set('Accept', mimeType[outputFormat])
.timeout(10000)
.send(fs.readFileSync(`${__dirname}/diagrams/${testCase.file}`))

for (var key in testCase.options) {
request = request.set(`Kroki-Diagram-Options-${key}`, testCase.options[key])
}

return await request
} catch (err) {
console.error('error:', err)
throw err
Expand All @@ -71,7 +78,7 @@ describe('Diagrams', function () {
this.timeout(15000)
tests.forEach((testCase) => {
testCase.outputFormat.forEach(outputFormat => {
it(`${testCase.engine}/${outputFormat} should answer with HTTP 200`, async () => {
it(`${testCase.engine}/${outputFormat} with options ${JSON.stringify(testCase.options)} should answer with HTTP 200`, async () => {
const response = await sendRequest(testCase, outputFormat)
try {
expect(response.status).to.equal(200)
Expand Down
7 changes: 6 additions & 1 deletion docs/modules/setup/pages/diagram-options.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ With flag set, option takes effect.
* `terminal` (`300`)
* `terminal-grayscale` (`301`)

| See: https://d2lang.com/tour/themes/
|See: https://d2lang.com/tour/themes/

|sketch
|_flag_ +
empty string ("")
|Render diagram with a hand-drawn aesthetic: https://d2lang.com/tour/sketch/
|===

== GraphViz
Expand Down
60 changes: 23 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "kroki-ci",
"version": "1.0.0",
"description": "Utility scripts for continuous integration",
"type" : "module",
"type": "module",
"engines": {
"node": ">=18"
},
"private": true,
"dependencies": {
"chai": "^4.3.6",
"chai": "^4.3.7",
"chai-http": "^4.3.0"
},
"devDependencies": {
"mocha": "^10.0.0"
"mocha": "^10.2.0"
},
"scripts": {
"test": "mocha ci/tests/smoke.js",
Expand Down
55 changes: 0 additions & 55 deletions server/ops/docker/go.mod

This file was deleted.

Loading

0 comments on commit c2013f7

Please sign in to comment.