Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite/publish #1

Merged
merged 10 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules
.directory
dist
lib
out
.idea
Empty file added .npmignore
Empty file.
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,6 @@ the call to `ng-openapi-gen`, like:

## Developing and contributing

The generator itself is written in TypeScript. When building, the code is transpiled to JavaScript in the `dist` folder. And the `dist` folder is the one that gets published to NPM. Even to prevent publishing from the wrong path, the `package.json` file has `"private": true`, which gets replaced by `false` in the build process.
The generator itself is written in TypeScript. When building, the code from `src` is transpiled to JavaScript and placed in the `lib` folder.

On the other hand, for developing / running tests, `jasmine-ts` is used, so the tests run directly from TypeScript. There's even a committed VisualStudio Code debug configuration for tests.

After developing the changes, to `link` the module and test it with other node projects, run the following:

```bash
npm run build
cd dist
npm link
```

At that point, the globally available ng-openapi-gen will be the one compiled to the `dist` folder.
During developing and testing, `jasmine-ts` is used, so the tests run directly from TypeScript. There's even a committed VisualStudio Code debug configuration for tests.
3 changes: 1 addition & 2 deletions lib/index.ts → bin/ng-openapi-gen.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env node

import { runNgOpenApiGen } from './ng-openapi-gen';
const { runNgOpenApiGen } = require('../lib/ng-openapi-gen');

// Run the main function
runNgOpenApiGen()
.catch(err => console.error(`Error on API generation: ${err}`));

89 changes: 62 additions & 27 deletions package-lock.json

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

40 changes: 23 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,51 @@
"url": "git+https://github.com/fllstx/ng-openapi-gen.git"
},
"bin": {
"ng-openapi-gen": "lib/index.js"
"ng-openapi-gen": "bin/ng-openapi-gen.js"
},
"main": "lib/ng-openapi-gen.js",
"files": [
"bin",
"lib",
"templates",
"ng-openapi-gen-schema.json"
],
"scripts": {
"test": "jasmine-ts tsconfig.json --config=jasmine.json",
"tslint": "tslint -c tslint.json -p tsconfig.json",
"compile": "tsc --project tsconfig.json && ncp \"LICENSE\" dist && ncp \"README.md\" \"dist/README.md\" && ncp \"templates\" \"dist/templates\" && ncp \"node_modules\" \"dist/node_modules\" && rimraf \"dist/test\" && replace-in-file \"\\\"private\\\": true\" \"\\\"private\\\": false\" dist/package.json",
"build": "npm run tslint && npm run compile && npm test",
"publish": "npm run build && cd dist && npm publish --access public"
"compile": "tsc --project tsconfig.json",
"build": "npm run tslint && npm run compile && npm test"
},
"husky": {
"hooks": {
"pre-commit": "npm run build"
}
},
"dependencies": {
"@loopback/openapi-v3-types": "^1.2.1",
"@types/argparse": "^1.0.36",
"@types/fs-extra": "^8.0.1",
"@types/jsesc": "^0.4.29",
"@types/json-schema": "^7.0.3",
"@types/lodash": "^4.14.144",
"@types/mkdirp": "^0.5.2",
"@types/node": "^12.11.1",
"argparse": "^1.0.10",
"esm": "^3.2.25",
"fs-extra": "^8.1.0",
"handlebars": "^4.4.3",
"jsesc": "^2.5.2",
"json-schema": "^0.2.5",
"json-schema-ref-parser": "^7.1.1",
"lodash": "^4.17.15",
"mkdirp": "^0.5.1",
"ts-node": "^8.4.1",
"typescript": "^3.6.4"
"mkdirp": "^0.5.1"
},
"peerDependencies": {
"@angular/core": ">=6.0.0",
"rxjs": ">=6.0.0"
},
"devDependencies": {
"@loopback/openapi-v3-types": "^1.2.1",
"@types/argparse": "^1.0.36",
"@types/fs-extra": "^8.0.1",
"@types/jasmine": "^3.4.4",
"@types/jsesc": "^0.4.29",
"@types/json-schema": "^7.0.3",
"@types/lodash": "^4.14.144",
"@types/mkdirp": "^0.5.2",
"@types/node": "^12.11.7",
"esm": "^3.2.25",
"husky": "^3.0.9",
"jasmine": "^3.5.0",
"jasmine-spec-reporter": "^4.2.1",
Expand All @@ -66,7 +70,9 @@
"ncp": "^2.0.0",
"replace-in-file": "^4.1.3",
"rimraf": "^2.7.1",
"ts-node": "^7.0.1",
"tslint": "^5.20.0",
"typescript": "^3.6.4",
"typescript-parser": "^2.6.1"
}
}
}
10 changes: 6 additions & 4 deletions lib/cmd-args.ts → src/cmd-args.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import path from 'path';
import fs from 'fs-extra';
import { ArgumentParser } from 'argparse';
import pkg from '../package.json';
import schema from '../ng-openapi-gen-schema.json';
import { Options } from './options.js';
import fs from 'fs';
import { Options } from './options';
import { kebabCase } from 'lodash';

const pkg = fs.readJSONSync(path.resolve(__dirname, '../package.json'));
const schema = fs.readJSONSync(path.resolve(__dirname, '../ng-openapi-gen-schema.json'));

const Mnemonics: { [key: string]: string } = { 'input': 'i', 'output': 'o' };
const DefaultConfig = 'ng-openapi-gen.json';

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions lib/ng-openapi-gen.ts → src/ng-openapi-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ export class NgOpenApiGen {
}

private readTemplates() {
const hasLib = __dirname.endsWith(path.sep + 'lib');
const builtInDir = path.join(__dirname, hasLib ? '../templates' : 'templates');
const builtInDir = path.resolve(__dirname, '../templates');
const customDir = this.options.templates || '';
this.globals = new Globals(this.options);
this.templates = new Templates(builtInDir, customDir);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions test/all-operations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OpenAPIObject } from 'openapi3-ts';
import { ClassDeclaration, TypescriptParser } from 'typescript-parser';
import { Content } from '../lib/content';
import { NgOpenApiGen } from '../lib/ng-openapi-gen';
import { Content } from '../src/content';
import { NgOpenApiGen } from '../src/ng-openapi-gen';
import options from './all-operations.config.json';
import allOperationsSpec from './all-operations.json';

Expand Down
4 changes: 2 additions & 2 deletions test/all-types.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OpenAPIObject } from '@loopback/openapi-v3-types';
import { ClassDeclaration, EnumDeclaration, InterfaceDeclaration, TypeAliasDeclaration, TypescriptParser } from 'typescript-parser';
import { NgOpenApiGen } from '../lib/ng-openapi-gen';
import { Options } from '../lib/options';
import { NgOpenApiGen } from '../src/ng-openapi-gen';
import { Options } from '../src/options';
import options from './all-types.config.json';
import allTypesSpec from './all-types.json';

Expand Down
4 changes: 2 additions & 2 deletions test/cyclos.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { OpenAPIObject } from 'openapi3-ts';
import { NgOpenApiGen } from '../lib/ng-openapi-gen';
import { NgOpenApiGen } from '../src/ng-openapi-gen';
import options from './cyclos.config.json';
import allOperationsSpec from './cyclos.json';
import { Options } from '../lib/options';
import { Options } from '../src/options';

const gen = new NgOpenApiGen(allOperationsSpec as OpenAPIObject, options as Options);
gen.generate();
Expand Down
2 changes: 1 addition & 1 deletion test/person-place.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InterfaceDeclaration, TypeAliasDeclaration, TypescriptParser } from 'typescript-parser';
import { NgOpenApiGen } from '../lib/ng-openapi-gen';
import { NgOpenApiGen } from '../src/ng-openapi-gen';
import options from './person-place.config.json';
import personAndPlaceSpec from './person-place.json';

Expand Down
Loading