@seagull/code-generators
Advanced tools
Comparing version 0.4.2 to 0.5.0
@@ -7,3 +7,4 @@ import Class from './class'; | ||
body?: string; | ||
cache?: number; | ||
} | ||
export default function generateAPI(name: string, options: IOptions): Class; |
@@ -41,2 +41,11 @@ "use strict"; | ||
} | ||
const cache = typeof options.cache === 'number' ? options.cache : 0; | ||
const docCache = `The duration in seconds this API will get cached`; | ||
gen.addProp({ | ||
doc: docCache, | ||
name: 'cache', | ||
static: true, | ||
type: 'number', | ||
value: cache.toString(), | ||
}); | ||
const docHandle = `This handle function executes your code. Return one of the following method invocations: 'text', 'json', 'redirect', 'missing', 'error'`; | ||
@@ -43,0 +52,0 @@ gen.addMethod({ |
@@ -64,2 +64,14 @@ "use strict"; | ||
} | ||
'can generate API with activated cache'() { | ||
const opts = { path: '/ha', cache: 60 }; | ||
const gen = _lib_1.generateAPI('MyAPI', opts); | ||
const code = gen.toString(); | ||
chai_1.expect(code).to.contain(`static cache: number = 60`); | ||
} | ||
'can generate API without cache'() { | ||
const opts = { path: '/ha' }; | ||
const gen = _lib_1.generateAPI('MyAPI', opts); | ||
const code = gen.toString(); | ||
chai_1.expect(code).to.contain(`static cache: number = 0`); | ||
} | ||
}; | ||
@@ -108,2 +120,14 @@ __decorate([ | ||
], CodegenGenerateApiTest.prototype, "can generate API with path activated CORS", null); | ||
__decorate([ | ||
mocha_typescript_1.test, | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:returntype", void 0) | ||
], CodegenGenerateApiTest.prototype, "can generate API with activated cache", null); | ||
__decorate([ | ||
mocha_typescript_1.test, | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:returntype", void 0) | ||
], CodegenGenerateApiTest.prototype, "can generate API without cache", null); | ||
CodegenGenerateApiTest = __decorate([ | ||
@@ -110,0 +134,0 @@ mocha_typescript_1.suite |
{ | ||
"name": "@seagull/code-generators", | ||
"version": "0.4.2", | ||
"description": "Scaffolding capabilities and AST transforms for seagull apps", | ||
"main": "dist/src/index.js", | ||
"types": "dist/src/index.d.js", | ||
"scripts": { | ||
"build": "rm -rf dist && tsc && cp -R media dist", | ||
"test": "NODE_ENV=test mocha --opts test/mocha.opts", | ||
"test:watch": "NODE_ENV=test mocha --opts test/mocha.opts --watch" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/seagull-js/code-generators.git" | ||
}, | ||
"author": "Maximilian Stroh <hisako1337@gmail.com>", | ||
"license": "LGPL-3.0", | ||
"devDependencies": { | ||
"@types/chai": "^4.1.2", | ||
"@types/lodash": "^4.14.103", | ||
"@types/mocha": "^2.2.48", | ||
"@types/node": "^6.0.100", | ||
"chai": "^4.1.2", | ||
"mocha": "^5.0.1", | ||
"mocha-typescript": "^1.1.12", | ||
"mock-fs": "^4.4.2", | ||
"source-map-support": "^0.5.3", | ||
"ts-node": "^4.1.0", | ||
"tsconfig-paths": "^3.1.1", | ||
"tslint": "^5.9.1", | ||
"tslint-config-prettier": "^1.8.0", | ||
"typescript": "^2.7.2" | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.17.5", | ||
"prettier": "^1.10.2", | ||
"shelljs": "^0.8.1", | ||
"ts-simple-ast": "^8.1.0" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^2.7.2" | ||
} | ||
} | ||
"name": "@seagull/code-generators", | ||
"version": "0.5.0", | ||
"description": "Scaffolding capabilities and AST transforms for seagull apps", | ||
"main": "dist/src/index.js", | ||
"types": "dist/src/index.d.js", | ||
"scripts": { | ||
"build": "rm -rf dist && tsc && cp -R media dist", | ||
"test": "NODE_ENV=test mocha --opts test/mocha.opts", | ||
"test:watch": "NODE_ENV=test mocha --opts test/mocha.opts --watch" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/seagull-js/code-generators.git" | ||
}, | ||
"author": "Maximilian Stroh <hisako1337@gmail.com>", | ||
"license": "LGPL-3.0", | ||
"devDependencies": { | ||
"@types/chai": "^4.1.2", | ||
"@types/lodash": "^4.14.103", | ||
"@types/mocha": "^2.2.48", | ||
"@types/node": "^6.0.100", | ||
"chai": "^4.1.2", | ||
"mocha": "^5.0.1", | ||
"mocha-typescript": "^1.1.12", | ||
"mock-fs": "^4.4.2", | ||
"source-map-support": "^0.5.3", | ||
"ts-node": "^4.1.0", | ||
"tsconfig-paths": "^3.1.1", | ||
"tslint": "^5.9.1", | ||
"tslint-config-prettier": "^1.8.0", | ||
"typescript": "^2.7.2" | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.17.5", | ||
"prettier": "^1.10.2", | ||
"shelljs": "^0.8.1", | ||
"ts-simple-ast": "^8.1.0" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^2.7.2" | ||
} | ||
} |
@@ -9,2 +9,3 @@ import { isString } from 'lodash' | ||
body?: string | ||
cache?: number | ||
} | ||
@@ -52,2 +53,12 @@ | ||
const cache = typeof options.cache === 'number' ? options.cache : 0 | ||
const docCache = `The duration in seconds this API will get cached` | ||
gen.addProp({ | ||
doc: docCache, | ||
name: 'cache', | ||
static: true, | ||
type: 'number', | ||
value: cache.toString(), | ||
}) | ||
const docHandle = `This handle function executes your code. Return one of the following method invocations: 'text', 'json', 'redirect', 'missing', 'error'` | ||
@@ -54,0 +65,0 @@ gen.addMethod({ |
@@ -69,2 +69,18 @@ import { generateAPI } from '@lib' | ||
} | ||
@test | ||
'can generate API with activated cache'() { | ||
const opts = { path: '/ha', cache: 60 } | ||
const gen = generateAPI('MyAPI', opts) | ||
const code = gen.toString() | ||
expect(code).to.contain(`static cache: number = 60`) | ||
} | ||
@test | ||
'can generate API without cache'() { | ||
const opts = { path: '/ha' } | ||
const gen = generateAPI('MyAPI', opts) | ||
const code = gen.toString() | ||
expect(code).to.contain(`static cache: number = 0`) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1154979
3002