From 46f5336a65406711229a097bb1933a8fd3aa8b66 Mon Sep 17 00:00:00 2001 From: YoungKi Lyu Date: Sun, 25 Sep 2022 19:26:44 +0900 Subject: [PATCH] Add bin field of package.json --- README.md | 6 +++++- bin/cli.js | 21 +++++++++++++++++++++ package-lock.json | 35 +++++++++++++++++++++++++++-------- package.json | 6 +++++- 4 files changed, 58 insertions(+), 10 deletions(-) create mode 100755 bin/cli.js diff --git a/README.md b/README.md index add0785..92dd0f1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Generate ERD UML file from Schema DDL file ## Installation ```sh -npm i schema-to-erd +$ npm i schema-to-erd ``` ## Usage @@ -24,6 +24,10 @@ const { schemaToErd } = require('schema-to-erd'); schemaToErd('./schema_samples/sakila-schema.sql'); ``` +```shell +$ schema2erd -s ./schema_samples/sakila-schema.sql +``` + ### Sample Schema files 1. [Sakila Sample Database](https://dev.mysql.com/doc/index-other.html) diff --git a/bin/cli.js b/bin/cli.js new file mode 100755 index 0000000..642019e --- /dev/null +++ b/bin/cli.js @@ -0,0 +1,21 @@ +#!/usr/bin/env node +import { program } from 'commander'; +import { schemaToErd } from '../dist/main.mjs'; +import fs from 'fs'; + +program + .requiredOption('-s, --schema-file ', 'schema.sql file path') + .option('-o, --output-dir ', 'output directory of uml file'); + +program.parse(); + +const options = program.opts(); +if (!(fs.existsSync(options.schemaFile))) { + console.error(`Not exist the schema.sql file(${options.schemaFile})`); + process.exit(1); +} + +(async () => { + const pumlFilePath = await schemaToErd(options.schemaFile, options.outputDir); + console.info(`Generate the plantuml file of ${pumlFilePath}`); +})(); diff --git a/package-lock.json b/package-lock.json index 90c5733..93abcee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,22 @@ { "name": "schema-to-erd", - "version": "1.3.0", + "version": "1.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "schema-to-erd", - "version": "1.3.0", + "version": "1.4.0", "license": "MIT", "dependencies": { + "commander": "^9.4.0", "glob": "^8.0.3", "lodash": "^4.17.21", "sql-ddl-to-json-schema": "^4.0.6" }, + "bin": { + "schema2erd": "bin/cli.js" + }, "devDependencies": { "@microsoft/eslint-formatter-sarif": "^3.0.0", "esbuild": "^0.15.7", @@ -557,9 +561,12 @@ "dev": true }, "node_modules/commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + "version": "9.4.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.4.0.tgz", + "integrity": "sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw==", + "engines": { + "node": "^12.20.0 || >=14" + } }, "node_modules/concat-map": { "version": "0.0.1", @@ -2592,6 +2599,11 @@ "url": "https://nearley.js.org/#give-to-nearley" } }, + "node_modules/nearley/node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -3892,9 +3904,9 @@ "dev": true }, "commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + "version": "9.4.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.4.0.tgz", + "integrity": "sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw==" }, "concat-map": { "version": "0.0.1", @@ -5311,6 +5323,13 @@ "moo": "^0.5.0", "railroad-diagrams": "^1.0.0", "randexp": "0.4.6" + }, + "dependencies": { + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + } } }, "normalize-path": { diff --git a/package.json b/package.json index 95a8e3f..55d369e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "schema-to-erd", - "version": "1.3.0", + "version": "1.4.0", "description": "Generate ERD UML file from Schema DDL file", "type": "module", "main": "dist/main.cjs", @@ -23,12 +23,16 @@ "UML" ], "author": "youngkiu@gmail.com", + "bin": { + "schema2erd": "bin/cli.js" + }, "license": "MIT", "bugs": { "url": "https://github.com/youngkiu/schema-to-erd/issues" }, "homepage": "https://github.com/youngkiu/schema-to-erd#readme", "dependencies": { + "commander": "^9.4.0", "glob": "^8.0.3", "lodash": "^4.17.21", "sql-ddl-to-json-schema": "^4.0.6"