Skip to content

Commit 0a2739a

Browse files
author
roman.vasilev
committed
Merge branch 'dev'
2 parents db0685a + 02d5cae commit 0a2739a

17 files changed

+628
-8
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 4
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false
14+
15+
[*.json]
16+
indent_size = 2

.eslintrc.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module.exports = {
2+
"root": true,
3+
"env": {
4+
"node": true,
5+
"jest": true,
6+
"jest/globals": true,
7+
},
8+
"parser": "@typescript-eslint/parser",
9+
"parserOptions": {
10+
"ecmaVersion": 2019,
11+
"sourceType": "module",
12+
"ecmaFeatures": {
13+
"jsx": false,
14+
},
15+
"project": "tsconfig.json",
16+
},
17+
"plugins": [
18+
"wix-editor",
19+
"unicorn",
20+
"import",
21+
"jest",
22+
"@typescript-eslint/tslint",
23+
"only-warn",
24+
],
25+
"extends": [
26+
"eslint:recommended",
27+
"plugin:unicorn/recommended",
28+
"plugin:import/errors",
29+
"plugin:import/warnings",
30+
"plugin:import/typescript",
31+
"plugin:jest/recommended",
32+
],
33+
"rules": {
34+
"quotes": [1, "single", { "allowTemplateLiterals": true }],
35+
"semi": [1, "always"],
36+
// wix-editor
37+
"wix-editor/augmented-assignment": 1,
38+
"wix-editor/no-instanceof-array": 1,
39+
"wix-editor/no-not-not": 1,
40+
"wix-editor/no-unneeded-match": 1,
41+
"wix-editor/prefer-filter": 1,
42+
"wix-editor/prefer-ternary": 1,
43+
"wix-editor/return-boolean": 1,
44+
"wix-editor/simplify-boolean-expression": 1,
45+
// unicorn
46+
"unicorn/import-index": 0,
47+
"unicorn/catch-error-name": 0,
48+
// import
49+
"import/newline-after-import": 0,
50+
"import/no-duplicates": 1,
51+
"import/max-dependencies": [1, { "max": 10 }],
52+
// tslint
53+
"@typescript-eslint/tslint/config": [1, {
54+
lintFile: "./tslint.json",
55+
}],
56+
}
57+
};

.github/main.workflow

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
1-
workflow "Build and deploy on push" {
1+
workflow "Main" {
22
on = "push"
3-
resolves = ["GitHub Action for npm", "docker://node"]
3+
resolves = ["Publish"]
44
}
55

6-
action "GitHub Action for npm" {
7-
uses = "actions/npm@59b64a598378f31e49cb76f27d6f3312b582f680"
6+
action "Install" {
7+
uses = "docker://node"
8+
runs = "npm"
89
args = "install"
910
}
1011

11-
action "docker://node" {
12+
action "Test" {
13+
needs = "Install"
1214
uses = "docker://node"
1315
runs = "npm"
14-
args = "install"
16+
args = "test"
17+
}
18+
19+
action "Pre Build" {
20+
needs = "Install"
21+
uses = "docker://stedolan/jq"
22+
runs = "sh"
23+
args = "Taskfile prebuild"
24+
}
25+
26+
action "Build" {
27+
needs = "Pre Build"
28+
uses = "docker://node"
29+
runs = "npm"
30+
args = "run build"
31+
}
32+
33+
# Filter for master branch
34+
action "Master" {
35+
needs = ["Test", "Build"]
36+
uses = "actions/bin/filter@master"
37+
args = "branch master"
38+
}
39+
40+
action "Publish" {
41+
needs = "Master"
42+
uses = "docker://node"
43+
runs = "npx"
44+
args = "semantic-release"
45+
secrets = ["NPM_TOKEN", "GITHUB_TOKEN"]
1546
}

.gitignore

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
dist/
2+
### https://raw.github.com/github/gitignore/5d896f6791c4257b74696714c66b2530b8d95a51/Node.gitignore
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
*.pid.lock
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
# Coverage directory used by tools like istanbul
17+
coverage
18+
# nyc test coverage
19+
.nyc_output
20+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21+
.grunt
22+
# Bower dependency directory (https://bower.io/)
23+
bower_components
24+
# node-waf configuration
25+
.lock-wscript
26+
# Compiled binary addons (http://nodejs.org/api/addons.html)
27+
build/Release
28+
# Dependency directories
29+
node_modules/
30+
jspm_packages/
31+
# Typescript v1 declaration files
32+
typings/
33+
# Optional npm cache directory
34+
.npm
35+
# Optional eslint cache
36+
.eslintcache
37+
# Optional REPL history
38+
.node_repl_history
39+
# Output of 'npm pack'
40+
*.tgz
41+
# Yarn Integrity file
42+
.yarn-integrity
43+
# dotenv environment variables file
44+
.env
45+
# Custom
46+
~*
47+
.idea
48+
.awcache
49+
.vscode
50+
.rts2_cache_*

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock = false

.releaserc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
"plugins": [
3+
"@semantic-release/commit-analyzer",
4+
"@semantic-release/release-notes-generator",
5+
"@semantic-release/changelog",
6+
[
7+
"@semantic-release/npm",
8+
{
9+
"pkgRoot": "dist"
10+
}
11+
],
12+
"@semantic-release/github",
13+
"@semantic-release/git",
14+
]
15+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,92 @@
1-
# typescript-transform-x
2-
Typescript transform plugin
1+
# typescript-transform-unspec
2+
Typescript transform plugin removes spec definition from source file.
3+
Inspired by [unassert](https://github.com/unassert-js/unassert).
4+
5+
## Motivation
6+
Imagine we have `function.ts` with single function. Usually we create `function.spec.ts` with tests.
7+
But what if we can keep tests in same file, and remove spec defenition for production.
8+
9+
## Example
10+
11+
### Before
12+
```ts
13+
export function hello(greet = 'world') {
14+
return `hello ${greet}`;
15+
}
16+
17+
it('hello world test', () => {
18+
expect(hello()).toBe('hello world');
19+
});
20+
```
21+
22+
### After (`it` removed)
23+
```js
24+
function hello(greet) {
25+
if (greet === void 0) { greet = 'world'; }
26+
return "hello " + greet;
27+
}
28+
````
29+
30+
### Pros and Cons
31+
\+ All in one file
32+
\- Collecting coverage can be tricky
33+
34+
## Installation
35+
```sh
36+
npm install --save-dev typescript-transform-unspec
37+
```
38+
39+
## Usage
40+
41+
#### webpack (with ts-loader or awesome-typescript-loader)
42+
```js
43+
// webpack.config.js
44+
const unspecTransformer = require('typescript-transform-unspec');
45+
46+
rules: [
47+
{
48+
test: /\.tsx?$/,
49+
loader: 'ts-loader', // or 'awesome-typescript-loader'
50+
options: {
51+
getCustomTransformers: program => ({
52+
before: [
53+
unspecTransformer(program),
54+
]
55+
})
56+
}
57+
},
58+
]
59+
```
60+
61+
#### TTypescript
62+
```json
63+
// tsconfig.json
64+
{
65+
"compilerOptions": {
66+
"plugins": [
67+
{ "transform": "typescript-transform-unspec" },
68+
]
69+
},
70+
}
71+
```
72+
73+
#### Rollup (with rollup-plugin-typescript2)
74+
```js
75+
// rollup.config.js
76+
import typescript from 'rollup-plugin-typescript2';
77+
import unspecTransformer from 'typescript-transform-unspec';
78+
79+
plugins: [
80+
typescript({
81+
transformers: [
82+
service => ({
83+
before: [unspecTransformer(service.getProgram())],
84+
after: [],
85+
}),
86+
],
87+
}),
88+
]
89+
```
390

491
## Resources
592
- https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943

Taskfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
PATH="$PWD/node_modules/.bin":$PATH
3+
4+
prebuild() {
5+
rm -rf dist
6+
cp -rf src dist && /usr/bin/find dist -name '*.spec.ts' | xargs rm -f
7+
cat tsconfig.json | jq 'del(.include, .compilerOptions.outDir)' > dist/tsconfig.json
8+
cp README.md LICENSE package.json dist
9+
}
10+
11+
build() {
12+
cd dist
13+
rm example.ts
14+
tsc -p .
15+
rm tsconfig.json
16+
cd ..
17+
}
18+
19+
"$@"

jest.config.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
transform: {
4+
'^.+\\.tsx?$': 'ts-jest'
5+
},
6+
collectCoverage: false,
7+
coverageDirectory: 'coverage',
8+
coverageReporters: [
9+
// 'lcov',
10+
'text',
11+
],
12+
collectCoverageFrom: [
13+
'src/**/*.ts',
14+
'!src/**/*.spec.ts',
15+
],
16+
testMatch: [
17+
'<rootDir>/src/**/*.spec.ts',
18+
'<rootDir>/src/example.ts',
19+
],
20+
moduleFileExtensions: [
21+
'ts',
22+
'tsx',
23+
'js',
24+
'jsx',
25+
'json',
26+
],
27+
modulePathIgnorePatterns: [
28+
'<rootDir>/dist',
29+
],
30+
globals: {
31+
'ts-jest': {
32+
diagnostics: false,
33+
isolatedModules: true,
34+
tsConfig: {
35+
target: 'esnext',
36+
}
37+
},
38+
},
39+
};

0 commit comments

Comments
 (0)