Skip to content

Commit

Permalink
Create plantuml encoded image url
Browse files Browse the repository at this point in the history
  • Loading branch information
youngkiu committed Sep 25, 2022
1 parent 46f5336 commit 176fe55
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 10 deletions.
8 changes: 5 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -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 <sql file path>', 'schema.sql file path')
Expand All @@ -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}`);
})();
2 changes: 1 addition & 1 deletion dist/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://lodash.com/>
Expand Down
2 changes: 1 addition & 1 deletion dist/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://lodash.com/>
Expand Down
15 changes: 13 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/schema_to_erd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
2 changes: 1 addition & 1 deletion test/schema_to_erd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 176fe55

Please sign in to comment.