From 7a97664e8395989ca1f8adb5bba8ba8b5b65ad28 Mon Sep 17 00:00:00 2001 From: Luis Fernando Planella Gonzalez Date: Tue, 5 Feb 2019 17:45:33 -0200 Subject: [PATCH] Fixes on the build process --- .gitignore | 1 - .npmignore | 6 +- lib/index.js | 6 - lib/ng-openapi-gen.ts | 34 +++--- lib/x.ts | 3 - package-lock.json | 247 ++++++++++++++++++++++++++++++++++++++++- package.json | 10 +- test/all-types.spec.ts | 15 ++- 8 files changed, 281 insertions(+), 41 deletions(-) delete mode 100644 lib/x.ts diff --git a/.gitignore b/.gitignore index 64e6fbd..792bd1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ node_modules .directory -ng-openapi-gen.json dist out \ No newline at end of file diff --git a/.npmignore b/.npmignore index 387acb3..30d74d2 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1 @@ -node_modules -out -test -.directory -package-lock.json \ No newline at end of file +test \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 49f2dc1..fae61c7 100755 --- a/lib/index.js +++ b/lib/index.js @@ -1,11 +1,5 @@ #!/usr/bin/env node "use strict"; -const tsNode = require('ts-node'); -tsNode.register({ - project: `${__dirname}/../tsconfig.json`, - transpileOnly: true -}); - // Run the main function const runNgOpenApiGen = require('./ng-openapi-gen').runNgOpenApiGen; runNgOpenApiGen() diff --git a/lib/ng-openapi-gen.ts b/lib/ng-openapi-gen.ts index 8757c2f..379da04 100644 --- a/lib/ng-openapi-gen.ts +++ b/lib/ng-openapi-gen.ts @@ -11,22 +11,6 @@ import { Templates } from './templates'; import { parseOptions } from './cmd-args'; import $RefParser from 'json-schema-ref-parser'; -/** - * Parses the command-line arguments, reads the configuration file and run the generation - */ -export async function runNgOpenApiGen() { - const options = parseOptions(); - const refParser = new $RefParser(); - const input = options.input; - try { - const openApi = await refParser.bundle(input, { dereference: { circular: false } }) as OpenAPIObject; - const gen = new NgOpenApiGen(openApi, options); - gen.generate(); - } catch (err) { - console.error(`Error on API generation from ${input}: ${err}`); - } -} - /** * Main generator class */ @@ -250,3 +234,21 @@ export class NgOpenApiGen { return result; } } + +/////////////////////////////////////////////////////////////////////////// + +/** + * Parses the command-line arguments, reads the configuration file and run the generation + */ +export async function runNgOpenApiGen() { + const options = parseOptions(); + const refParser = new $RefParser(); + const input = options.input; + try { + const openApi = await refParser.bundle(input, { dereference: { circular: false } }) as OpenAPIObject; + const gen = new NgOpenApiGen(openApi, options); + gen.generate(); + } catch (err) { + console.error(`Error on API generation from ${input}: ${err}`); + } +} diff --git a/lib/x.ts b/lib/x.ts deleted file mode 100644 index cdc37db..0000000 --- a/lib/x.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface Ob { - status: Enum { A = 'x', B = 'y' } -} diff --git a/package-lock.json b/package-lock.json index b59af80..252d56b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ng-openapi-gen", - "version": "0.0.1", + "version": "0.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -625,6 +625,15 @@ "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=", "dev": true }, + "end-of-stream": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", + "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", + "dev": true, + "requires": { + "once": "^1.4.0" + } + }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -640,6 +649,11 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "esm": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.1.tgz", + "integrity": "sha512-+gxDed1gELD6mCn0P4TRPpknVJe7JvLtg3lJ9sRlLSpfw6J47QMGa5pi+10DN20VQ5z6OtbxjFoD9Z6PM+zb6Q==" + }, "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", @@ -1836,6 +1850,15 @@ "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", "integrity": "sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==" }, + "map-age-cleaner": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", + "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", + "dev": true, + "requires": { + "p-defer": "^1.0.0" + } + }, "map-cache": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz", @@ -1994,6 +2017,12 @@ } } }, + "nice-try": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", + "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", + "dev": true + }, "normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", @@ -2145,12 +2174,24 @@ "mem": "^1.1.0" } }, + "p-defer": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", + "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=", + "dev": true + }, "p-finally": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", "dev": true }, + "p-is-promise": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.0.0.tgz", + "integrity": "sha512-pzQPhYMCAgLAKPWD2jC3Se9fEfrD9npNos0y150EeqZll7akhEgGhTW/slB6lHku8AvYGiJ+YJ5hfHKePPgFWg==", + "dev": true + }, "p-limit": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", @@ -2265,6 +2306,16 @@ "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", "dev": true }, + "pump": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", + "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "dev": true, + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, "randomatic": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-3.1.1.tgz", @@ -2671,6 +2722,182 @@ "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", "dev": true }, + "replace-in-file": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/replace-in-file/-/replace-in-file-3.4.3.tgz", + "integrity": "sha512-m62vEDCIL1B8uzymh+YKMLb4N4LdX5A5ObxOjap4wyCHzWqblAUYO5vhjWwk7zfR8PkTRIdPZVo/u4h33clnew==", + "dev": true, + "requires": { + "chalk": "^2.4.1", + "glob": "^7.1.2", + "yargs": "^12.0.5" + }, + "dependencies": { + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + }, + "cliui": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", + "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", + "dev": true, + "requires": { + "string-width": "^2.1.1", + "strip-ansi": "^4.0.0", + "wrap-ansi": "^2.0.0" + } + }, + "cross-spawn": { + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", + "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "dev": true, + "requires": { + "nice-try": "^1.0.4", + "path-key": "^2.0.1", + "semver": "^5.5.0", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, + "execa": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", + "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", + "dev": true, + "requires": { + "cross-spawn": "^6.0.0", + "get-stream": "^4.0.0", + "is-stream": "^1.1.0", + "npm-run-path": "^2.0.0", + "p-finally": "^1.0.0", + "signal-exit": "^3.0.0", + "strip-eof": "^1.0.0" + } + }, + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "dev": true, + "requires": { + "locate-path": "^3.0.0" + } + }, + "get-stream": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", + "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", + "dev": true, + "requires": { + "pump": "^3.0.0" + } + }, + "invert-kv": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", + "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==", + "dev": true + }, + "lcid": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", + "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", + "dev": true, + "requires": { + "invert-kv": "^2.0.0" + } + }, + "locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "dev": true, + "requires": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + } + }, + "mem": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/mem/-/mem-4.1.0.tgz", + "integrity": "sha512-I5u6Q1x7wxO0kdOpYBB28xueHADYps5uty/zg936CiG8NTe5sJL8EjrCuLneuDW3PlMdZBGDIn8BirEVdovZvg==", + "dev": true, + "requires": { + "map-age-cleaner": "^0.1.1", + "mimic-fn": "^1.0.0", + "p-is-promise": "^2.0.0" + } + }, + "os-locale": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", + "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", + "dev": true, + "requires": { + "execa": "^1.0.0", + "lcid": "^2.0.0", + "mem": "^4.0.0" + } + }, + "p-limit": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.1.0.tgz", + "integrity": "sha512-NhURkNcrVB+8hNfLuysU8enY5xn2KXphsHBaC2YmRNTZRc7RWusw6apSpdEj3jo4CMb6W9nrF6tTnsJsJeyu6g==", + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "dev": true, + "requires": { + "p-limit": "^2.0.0" + } + }, + "p-try": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz", + "integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==", + "dev": true + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, + "requires": { + "ansi-regex": "^3.0.0" + } + }, + "yargs": { + "version": "12.0.5", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.5.tgz", + "integrity": "sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw==", + "dev": true, + "requires": { + "cliui": "^4.0.0", + "decamelize": "^1.2.0", + "find-up": "^3.0.0", + "get-caller-file": "^1.0.1", + "os-locale": "^3.0.0", + "require-directory": "^2.1.1", + "require-main-filename": "^1.0.1", + "set-blocking": "^2.0.0", + "string-width": "^2.0.0", + "which-module": "^2.0.0", + "y18n": "^3.2.1 || ^4.0.0", + "yargs-parser": "^11.1.1" + } + } + } + }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -3423,6 +3650,24 @@ } } }, + "yargs-parser": { + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-11.1.1.tgz", + "integrity": "sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ==", + "dev": true, + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + }, + "dependencies": { + "camelcase": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.0.0.tgz", + "integrity": "sha512-faqwZqnWxbxn+F1d399ygeamQNy3lPp/H9H6rNrqYh4FSVCtcY+3cub1MxA8o9mDd55mM8Aghuu/kuyYA6VTsA==", + "dev": true + } + } + }, "yn": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", diff --git a/package.json b/package.json index f9310d3..a2e5f8f 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,9 @@ { "name": "ng-openapi-gen", - "version": "0.1.0", + "version": "0.1.2", "license": "MIT", "author": "Cyclos development team", "description": "An OpenAPI 3 codegen for Angular 6+", - "private": false, "keywords": [ "angular", "openapi", @@ -14,12 +13,15 @@ "type": "git", "url": "git+https://github.com/cyclosproject/ng-openapi-gen.git" }, + "private": true, "bin": { "ng-openapi-gen": "lib/index.js" }, "scripts": { + "test": "jasmine-ts tsconfig.json --config=jasmine.json", "tslint": "tslint -c tslint.json -p tsconfig.json", - "test": "jasmine-ts tsconfig.json --config=jasmine.json" + "compile": "tsc --project tsconfig.json && cpx \".npmignore\" dist && cpx \"LICENSE\" dist && cpx \"README.md\" dist && cpx \"lib/index.js\" dist/lib && cpx \"templates/*\" dist/templates && replace-in-file \"\\\"private\\\": true\" \"\\\"private\\\": false\" dist/package.json", + "build": "npm run tslint && npm run compile && npm test" }, "dependencies": { "@loopback/openapi-v3-types": "^1.0.4", @@ -30,6 +32,7 @@ "@types/lodash": "^4.14.120", "@types/node": "^10.12.18", "argparse": "^1.0.10", + "esm": "^3.2.1", "handlebars": "^4.0.12", "jsesc": "^2.5.2", "json-schema": "^0.2.3", @@ -48,6 +51,7 @@ "jasmine": "^3.3.1", "jasmine-spec-reporter": "^4.2.1", "jasmine-ts": "^0.3.0", + "replace-in-file": "^3.4.3", "tslint": "^5.12.1", "typescript-parser": "^2.6.1" } diff --git a/test/all-types.spec.ts b/test/all-types.spec.ts index 552ae46..0bc4dc1 100644 --- a/test/all-types.spec.ts +++ b/test/all-types.spec.ts @@ -1,10 +1,11 @@ import { OpenAPIObject } from '@loopback/openapi-v3-types'; -import { InterfaceDeclaration, TypeAliasDeclaration, TypescriptParser } from 'typescript-parser'; +import { InterfaceDeclaration, TypeAliasDeclaration, TypescriptParser, EnumDeclaration } from 'typescript-parser'; import { NgOpenApiGen } from '../lib/ng-openapi-gen'; import options from './all-types.config.json'; import allTypesSpec from './all-types.json'; +import { Options } from '../lib/options'; -const gen = new NgOpenApiGen(allTypesSpec as OpenAPIObject, options); +const gen = new NgOpenApiGen(allTypesSpec as OpenAPIObject, options as Options); gen.generate(); describe('Generation tests using all-types.json', () => { @@ -15,11 +16,13 @@ describe('Generation tests using all-types.json', () => { parser.parseSource(ts).then(ast => { expect(ast.imports.length).toBe(0); expect(ast.declarations.length).toBe(1); - expect(ast.declarations[0]).toEqual(jasmine.any(TypeAliasDeclaration)); - const decl = ast.declarations[0] as TypeAliasDeclaration; + expect(ast.declarations[0]).toEqual(jasmine.any(EnumDeclaration)); + const decl = ast.declarations[0] as EnumDeclaration; expect(decl.name).toBe('RefEnum'); - const text = ts.substring(decl.start || 0, decl.end || ts.length); - expect(text).toBe(`export type RefEnum = 'valueA' | 'valueB' | 'valueC';`); + expect(decl.members.length).toBe(3); + expect(decl.members[0]).toBe('ValueA'); + expect(decl.members[1]).toBe('ValueB'); + expect(decl.members[2]).toBe('ValueC'); done(); }); });