-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-ts): initial implementation of baset-plugin-ts
- Loading branch information
Showing
7 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
!/bin/**/* | ||
!/dist/**/* | ||
/src/ | ||
tsconfig.json | ||
tslint.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Ihor Chulinda | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# BaseT Core | ||
> TypeScript reader plugin for [BaseT](https://github.com/Igmat/baset) project. | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "baset-plugin-ts", | ||
"version": "0.4.1", | ||
"description": "TypeScript plugin for BaseT project.", | ||
"keywords": [ | ||
"baset-plugin-ts", | ||
"typescript", | ||
"baseline", | ||
"unit-test", | ||
"test", | ||
"testing", | ||
"e2e-test" | ||
], | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "npm run tslint && tsc", | ||
"watch": "npm run tslint && tsc -w", | ||
"tslint": "tslint -c tslint.json -p tsconfig.json", | ||
"test": "baset", | ||
"accept": "baset accept", | ||
"doctoc": "doctoc README.md", | ||
"prepublish": "npm run doctoc" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "^9.3.0", | ||
"baset": "^0.4.1", | ||
"doctoc": "^1.3.0", | ||
"tslint": "^5.9.1", | ||
"typescript": "^2.6.2" | ||
}, | ||
"dependencies": { | ||
"typescript": "^2.6.2", | ||
"find-up": "^2.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { sync } from 'find-up'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { CompilerOptions, transpileModule } from 'typescript'; | ||
import { isPrimitive, promisify } from 'util'; | ||
|
||
const readFile = promisify(fs.readFile); | ||
|
||
export interface ITypeScriptReaderOptions { | ||
config: string | { compilerOptions: CompilerOptions }; | ||
} | ||
export default class TypeScriptReader { | ||
private compilerOptions: CompilerOptions; | ||
constructor(private options?: ITypeScriptReaderOptions) { | ||
const config = (!options) | ||
? (() => { | ||
const configPath = sync('tsconfig.json'); | ||
if (!configPath) throw new Error("We can't find TS config file for your tests"); | ||
|
||
return configPath; | ||
})() | ||
: options.config; | ||
|
||
this.compilerOptions = (typeof config === 'string') | ||
? require(path.resolve(config)) | ||
: config; | ||
} | ||
|
||
read = async (filePath: string, spec: string | Promise<string>) => { | ||
if (typeof spec !== 'string' || spec.length) throw new Error('TypeScript plugin have to be first in plugins chain'); | ||
const src = await readFile(filePath, { encoding: 'utf8' }); | ||
|
||
return transpileModule(src, { | ||
compilerOptions: this.compilerOptions, | ||
fileName: filePath, | ||
}).outputText; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2015", | ||
"module": "commonjs", | ||
"sourceMap": true, | ||
"declaration": true, | ||
"outDir": "dist", | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"noImplicitThis": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"moduleResolution": "node", | ||
"baseUrl": ".", | ||
"paths": { | ||
"*": [ | ||
"node_modules/*", | ||
"src/types/*" | ||
] | ||
}, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": [ | ||
"../../tslint.json" | ||
], | ||
"rules": { | ||
"no-default-export": false | ||
} | ||
} |