1.0.1 • Published 3 years ago

tzed-cli v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

tzed-cli

A package for a cli, which should save everyday work.

Getting Started

Installation

This command installs tzed-cli globally.

npm i tzed-cli -g

Available Commands

init

Description:

This command creates your tzedconfig.json in your root folder for further configurations.

Constructions:

Navigate to your root folder of your project and insert in your command-line:

tzed init

swagger

Description:

This command automatically creates all available REST APIs from the swagger URLs specified in tzedconfig.json.

Constructions:

Prepare your tzedconfig.json with your swagger URLs and call following command:

tzed swagger
Example:
{
	"rootDir": "./",
	"outDir": "./dist",
	"sharedDir": "./dist/shared",
	"swaggerUrls": [
		"https://petstore.swagger.io/v2/swagger.json"
	]
}
  • rootDir: Root directory of the project.
  • outDir: Directory in which the swagger files should be stored
  • sharedDir: Directory in which the shared files for swagger should be stored
  • swaggerUrls: All JSON swagger URLs whose API files should be automatically produced

Create simple express app with swagger cli command

  1. Create project folder
  2. npm init
  3. tzed init
  4. Edit your tzedconfig.json and add your JSON Swagger URLs
  5. tzed swagger
  6. Add index.ts file to your specified "outDir":

index.ts:

import express from 'express';
import { init as globalInitRoutes } from './globalInitRoutes';

const app: express.Express = express();
const port: number = 3000;

app.get('/', (req, res) => res.send('Hello World!'));

globalInitRoutes(app, '/api');

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));
  1. Install missing dependencies:
npm i express && npm i glob && npm i axios && npm i --save-dev @types/express && npm i --save-dev @types/glob && npm i --save-dev tslib && npm i --save-dev rimraf
  1. Add tsconfig.json in your root directory:

tsconfig.json:

{
	"compilerOptions": {
		"baseUrl": "./",
		"outDir": "./bin/www",
		"sourceMap": true,
		"inlineSources": true,
		"strict": true,
		"forceConsistentCasingInFileNames": true,
		"esModuleInterop": true,
		"noImplicitReturns": true,
		"noFallthroughCasesInSwitch": true,
		"declaration": false,
		"downlevelIteration": true,
		"experimentalDecorators": true,
		"emitDecoratorMetadata": true,
		"moduleResolution": "node",
		"importHelpers": true,
		"target": "es5",
		"module": "commonjs",
		"lib": [
			"es2015",
			"dom"
		],
		"allowSyntheticDefaultImports": true
	}
}
  1. Update your scripts in your package.json:

package.json:

{
	"name": "test-tzed-cli",
	"version": "1.0.0",
	"description": "",
	"scripts": {
		"start": "npm run build && node ./bin/www/index.js",
		"build": "npm run clean && npm run transpile",
		"transpile": "tsc -p ./tsconfig.json",
		"clean": "rimraf ./bin"
	},
	"author": "",
	"license": "ISC",
	"dependencies": {
		"axios": "^0.21.1",
		"express": "^4.17.1",
		"glob": "^7.1.7"
	},
	"devDependencies": {
		"@types/express": "^4.17.13",
		"@types/glob": "^7.1.4",
		"rimraf": "^3.0.2",
		"tslib": "^2.3.0"
	}
}
  1. npm run start
  2. Browse to your swagger API URL: Example http://localhost:3000/api/v2/pet/1

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT