From 176fe5553c8ec2133c32d551493170f48673f2f4 Mon Sep 17 00:00:00 2001 From: YoungKi Lyu Date: Sun, 25 Sep 2022 21:03:52 +0900 Subject: [PATCH] Create plantuml encoded image url --- bin/cli.js | 8 +++++--- dist/main.cjs | 2 +- dist/main.mjs | 2 +- package-lock.json | 15 +++++++++++++-- package.json | 3 ++- src/schema_to_erd.js | 2 +- test/schema_to_erd.spec.js | 2 +- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 642019e..c8bf75d 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,7 +1,8 @@ #!/usr/bin/env node import { program } from 'commander'; -import { schemaToErd } from '../dist/main.mjs'; import fs from 'fs'; +import plantumlEncoder from 'plantuml-encoder'; +import { schemaToErd } from '../dist/main.mjs'; program .requiredOption('-s, --schema-file ', 'schema.sql file path') @@ -16,6 +17,7 @@ if (!(fs.existsSync(options.schemaFile))) { } (async () => { - const pumlFilePath = await schemaToErd(options.schemaFile, options.outputDir); - console.info(`Generate the plantuml file of ${pumlFilePath}`); + const { pumlStr } = await schemaToErd(options.schemaFile, options.outputDir); + const encoded = plantumlEncoder.encode(pumlStr); + console.info(`Look at the ERD image - http://www.plantuml.com/plantuml/img/${encoded}`); })(); diff --git a/dist/main.cjs b/dist/main.cjs index 2f26189..241dac7 100644 --- a/dist/main.cjs +++ b/dist/main.cjs @@ -63,7 +63,7 @@ ${E.join(` `)} @enduml -`}async function wo(s,t){let o=await zr.promises.readFile(s,"utf8"),E=Ea(o),T=Uo(E),c=t||Zr.default.parse(s).dir,O=Zr.default.join(c,`${Zr.default.parse(s).name}.puml`);return await zr.promises.mkdir(c,{recursive:!0}),await zr.promises.writeFile(O,T,"utf8"),O}0&&(module.exports={schemaToErd}); +`}async function wo(s,t){let o=await zr.promises.readFile(s,"utf8"),E=Ea(o),T=Uo(E),c=t||Zr.default.parse(s).dir,O=Zr.default.join(c,`${Zr.default.parse(s).name}.puml`);return await zr.promises.mkdir(c,{recursive:!0}),await zr.promises.writeFile(O,T,"utf8"),{pumlFilePath:O,pumlStr:T}}0&&(module.exports={schemaToErd}); /** * @license * Lodash diff --git a/dist/main.mjs b/dist/main.mjs index b98b3a4..060dd23 100644 --- a/dist/main.mjs +++ b/dist/main.mjs @@ -63,7 +63,7 @@ ${E.join(` `)} @enduml -`}async function ia(s,t){let o=await go.readFile(s,"utf8"),E=oa(o),T=vo(E),c=t||Mo.parse(s).dir,O=Mo.join(c,`${Mo.parse(s).name}.puml`);return await go.mkdir(c,{recursive:!0}),await go.writeFile(O,T,"utf8"),O}export{ia as schemaToErd}; +`}async function ia(s,t){let o=await go.readFile(s,"utf8"),E=oa(o),T=vo(E),c=t||Mo.parse(s).dir,O=Mo.join(c,`${Mo.parse(s).name}.puml`);return await go.mkdir(c,{recursive:!0}),await go.writeFile(O,T,"utf8"),{pumlFilePath:O,pumlStr:T}}export{ia as schemaToErd}; /** * @license * Lodash diff --git a/package-lock.json b/package-lock.json index 93abcee..513c3dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,18 @@ { "name": "schema-to-erd", - "version": "1.4.0", + "version": "1.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "schema-to-erd", - "version": "1.4.0", + "version": "1.4.1", "license": "MIT", "dependencies": { "commander": "^9.4.0", "glob": "^8.0.3", "lodash": "^4.17.21", + "plantuml-encoder": "^1.4.0", "sql-ddl-to-json-schema": "^4.0.6" }, "bin": { @@ -2840,6 +2841,11 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/plantuml-encoder": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/plantuml-encoder/-/plantuml-encoder-1.4.0.tgz", + "integrity": "sha512-sxMwpDw/ySY1WB2CE3+IdMuEcWibJ72DDOsXLkSmEaSzwEUaYBT6DWgOfBiHGCux4q433X6+OEFWjlVqp7gL6g==" + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -5496,6 +5502,11 @@ "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", "dev": true }, + "plantuml-encoder": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/plantuml-encoder/-/plantuml-encoder-1.4.0.tgz", + "integrity": "sha512-sxMwpDw/ySY1WB2CE3+IdMuEcWibJ72DDOsXLkSmEaSzwEUaYBT6DWgOfBiHGCux4q433X6+OEFWjlVqp7gL6g==" + }, "prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", diff --git a/package.json b/package.json index 55d369e..3186f3c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "schema-to-erd", - "version": "1.4.0", + "version": "1.4.1", "description": "Generate ERD UML file from Schema DDL file", "type": "module", "main": "dist/main.cjs", @@ -35,6 +35,7 @@ "commander": "^9.4.0", "glob": "^8.0.3", "lodash": "^4.17.21", + "plantuml-encoder": "^1.4.0", "sql-ddl-to-json-schema": "^4.0.6" }, "devDependencies": { diff --git a/src/schema_to_erd.js b/src/schema_to_erd.js index 5d48071..82fc05b 100644 --- a/src/schema_to_erd.js +++ b/src/schema_to_erd.js @@ -14,5 +14,5 @@ export default async function schemaToErd(schemaFilePath, outputDirPath) { await fs.mkdir(pumlDirPath, { recursive: true }); await fs.writeFile(pumlFilePath, pumlStr, 'utf8'); - return pumlFilePath; + return { pumlFilePath, pumlStr }; } diff --git a/test/schema_to_erd.spec.js b/test/schema_to_erd.spec.js index 72a6260..691e97a 100644 --- a/test/schema_to_erd.spec.js +++ b/test/schema_to_erd.spec.js @@ -36,7 +36,7 @@ console.log(fileList); describe('samples', () => { fileList.map((filePath) => { it(path.parse(filePath).base, async () => { - const pumlFilePath = await schemaToErd(filePath); + const { pumlFilePath } = await schemaToErd(filePath); const { dir, base } = path.parse(pumlFilePath); const pathParts = dir.split(path.sep); const expectedFilePath = path.join('./puml_examples', ...pathParts.slice(1), base);