Skip to content

Commit bb4b4ac

Browse files
authored
Merge pull request #51 from maxdavidson/refactor-again
Refactor again
2 parents 0d5cc11 + 341fdc8 commit bb4b4ac

File tree

10 files changed

+163
-3132
lines changed

10 files changed

+163
-3132
lines changed

.gitignore

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,45 @@
1-
# Created by https://www.gitignore.io/api/node,visualstudiocode
1+
# Created by https://www.gitignore.io/api/node,visualstudiocode,macos
2+
3+
# Generated stuff
4+
.code
5+
dist
6+
lib
7+
es
8+
9+
### macOS ###
10+
*.DS_Store
11+
.AppleDouble
12+
.LSOverride
13+
14+
# Icon must end with two \r
15+
Icon
16+
17+
# Thumbnails
18+
._*
19+
20+
# Files that might appear in the root of a volume
21+
.DocumentRevisions-V100
22+
.fseventsd
23+
.Spotlight-V100
24+
.TemporaryItems
25+
.Trashes
26+
.VolumeIcon.icns
27+
.com.apple.timemachine.donotpresent
28+
29+
# Directories potentially created on remote AFP share
30+
.AppleDB
31+
.AppleDesktop
32+
Network Trash Folder
33+
Temporary Items
34+
.apdisk
235

336
### Node ###
437
# Logs
538
logs
639
*.log
740
npm-debug.log*
41+
yarn-debug.log*
42+
yarn-error.log*
843

944
# Runtime data
1045
pids
@@ -24,14 +59,21 @@ coverage
2459
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
2560
.grunt
2661

62+
# Bower dependency directory (https://bower.io/)
63+
bower_components
64+
2765
# node-waf configuration
2866
.lock-wscript
2967

3068
# Compiled binary addons (http://nodejs.org/api/addons.html)
3169
build/Release
3270

3371
# Dependency directories
34-
node_modules
72+
node_modules/
73+
jspm_packages/
74+
75+
# Typescript v1 declaration files
76+
typings/
3577

3678
# Optional npm cache directory
3779
.npm
@@ -45,12 +87,17 @@ node_modules
4587
# Output of 'npm pack'
4688
*.tgz
4789

48-
# Distributed files
49-
dist
90+
# Yarn Integrity file
91+
.yarn-integrity
92+
93+
# dotenv environment variables file
94+
.env
5095

5196
### VisualStudioCode ###
5297
.vscode/*
53-
!.vscode/*.json
98+
!.vscode/settings.json
99+
!.vscode/tasks.json
100+
!.vscode/launch.json
101+
!.vscode/extensions.json
54102

55-
# Other stuff
56-
.code
103+
# End of https://www.gitignore.io/api/node,visualstudiocode,macos

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ node_js:
66
cache:
77
directories:
88
- node_modules
9-
before_install:
10-
- if [[ $(npm --version) == 2* ]]; then npm install -g npm@latest-3; fi
119
after_success:
1210
- npm i -g coveralls
1311
- cat coverage/remapped/lcov.info | coveralls

.vscode/launch.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [{
4+
"name": "Debug tests",
5+
"type": "node",
6+
"request": "launch",
7+
"protocol": "auto",
8+
"stopOnEntry": false,
9+
"console": "integratedTerminal",
10+
"args": [
11+
"node_modules/.bin/jest",
12+
"--no-cache",
13+
"--runInBand",
14+
"--env=node-debug",
15+
"--config=$(node jest.config.js)"
16+
],
17+
"skipFiles": [
18+
"<node_internals>/**/*.js",
19+
"${workspaceRoot}/node_modules/**/*.js"
20+
]
21+
}]
22+
}

jest.config.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
var semver = require('semver');
3+
4+
function getSupportedTypescriptTarget() {
5+
var nodeVersion = process.versions.node;
6+
7+
if (semver.gt(nodeVersion, '7.6.0')) {
8+
return 'es2017'
9+
} else if (semver.gt(nodeVersion, '7.0.0')) {
10+
return 'es2016';
11+
} else if (semver.gt(nodeVersion, '6.0.0')) {
12+
return 'es2015';
13+
} else if (semver.gt(nodeVersion, '4.0.0')) {
14+
return 'es5';
15+
} else {
16+
return 'es3';
17+
}
18+
}
19+
20+
var jestConfig = {
21+
transform: {
22+
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
23+
},
24+
testResultsProcessor: "<rootDir>/node_modules/ts-jest/coverageprocessor.js",
25+
testRegex: "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
26+
testPathIgnorePatterns: [
27+
"<rootDir>[/\\\\](dist|coverage|node_modules)[/\\\\]",
28+
"_\\w*.\\w+$"
29+
],
30+
moduleFileExtensions: ["ts", "tsx", "js"],
31+
globals: {
32+
__TS_CONFIG__: {
33+
target: getSupportedTypescriptTarget(),
34+
inlineSourceMap: true
35+
}
36+
}
37+
};
38+
39+
module.exports = jestConfig;
40+
41+
// If this file is run as an executable, print the config stringified to JSON
42+
if (require.main === module) {
43+
console.log(JSON.stringify(jestConfig));
44+
}

jest.config.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

package.json

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,24 @@
44
"description": "Boilerplate for TypeScript 2.0 libraries",
55
"author": "Max Davidson <[email protected]>",
66
"license": "MIT",
7-
"repository": {
8-
"type": "git",
9-
"url": "https://github.com/maxdavidson/typescript-library-boilerplate.git"
10-
},
11-
"main": "dist/cjs/index.js",
12-
"module": "dist/es/index.js",
13-
"browser": "bundle.js",
14-
"typings": "typings.d.ts",
7+
"repository": "git+https://github.com/maxdavidson/typescript-library-boilerplate.git",
8+
"main": "lib/index.js",
9+
"module": "es/index.js",
10+
"browser": "dist/bundle.js",
11+
"types": "dist/bundle.d.ts",
1512
"scripts": {
16-
"build": "npm run build:cjs & npm run build:umd",
17-
"build:cjs": "tsc --outDir dist/cjs --module commonjs",
18-
"build:es": "tsc --outDir dist/es --module es2015",
19-
"build:umd": "npm run build:es && rollup --config && dts-bundle --name typings --main dist/es --outputAsModuleFolder",
20-
"clean": "rimraf dist coverage",
13+
"build": "npm run build:lib & npm run build:umd",
14+
"build:lib": "tsc --outDir lib --module commonjs",
15+
"build:es": "tsc --outDir es --module es2015",
16+
"build:umd": "npm run build:es && rollup --config && dts-bundle --name dist/bundle --main es --outputAsModuleFolder",
17+
"clean": "rimraf dist es lib coverage",
2118
"typecheck": "tsc --noEmit",
2219
"lint": "tslint --project tsconfig.json --type-check --format stylish",
23-
"test": "jest --config jest.config.json --coverage --no-cache --runInBand",
24-
"test:watch": "jest --config jest.config.json --watch",
20+
"test": "jest --coverage --no-cache --config $(node jest.config.js)",
21+
"test:watch": "jest --watch --updateSnapshot --config $(node jest.config.js)",
22+
"prepare": "npm run build",
2523
"prebuild": "npm run clean",
24+
"postbuild": "rimraf {lib,es}/**/__tests__",
2625
"posttest": "npm run typecheck && npm run lint",
2726
"preversion": "npm test",
2827
"postversion": "git push && git push --tags"
@@ -34,27 +33,31 @@
3433
"boilerplate"
3534
],
3635
"files": [
36+
"lib",
37+
"es",
3738
"dist"
3839
],
3940
"dependencies": {
40-
"@types/node": "^7.0.5",
41-
"tslib": "^1.5.0"
41+
"@types/node": "^7.0.8",
42+
"tslib": "^1.6.0"
4243
},
4344
"devDependencies": {
44-
"@types/jest": "^18.1.1",
45+
"@types/jest": "^19.2.2",
4546
"dts-bundle": "^0.7.2",
46-
"jest": "^19.0.0",
47-
"pascal-case": "^2.0.0",
48-
"rimraf": "^2.5.4",
49-
"rollup": "^0.41.4",
50-
"rollup-plugin-commonjs": "^7.0.0",
51-
"rollup-plugin-node-builtins": "^2.0.0",
47+
"jest": "^19.0.2",
48+
"jest-environment-node-debug": "^2.0.0",
49+
"pascal-case": "^2.0.1",
50+
"rimraf": "^2.6.1",
51+
"rollup": "^0.41.6",
52+
"rollup-plugin-commonjs": "^8.0.2",
53+
"rollup-plugin-node-builtins": "^2.1.0",
5254
"rollup-plugin-node-globals": "^1.1.0",
5355
"rollup-plugin-node-resolve": "^2.0.0",
5456
"rollup-plugin-sourcemaps": "^0.4.1",
5557
"rollup-plugin-uglify": "^1.0.1",
56-
"ts-jest": "^19.0.0",
57-
"tslint": "^4.4.2",
58-
"typescript": "^2.2.0"
58+
"semver": "^5.3.0",
59+
"ts-jest": "^19.0.2",
60+
"tslint": "^4.5.1",
61+
"typescript": "^2.2.1"
5962
}
6063
}

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const pkg = require('./package');
1111
export default {
1212
moduleId: pkg.name,
1313
moduleName: pascalCase(pkg.name),
14-
entry: 'dist/es/index.js',
14+
entry: 'es/index.js',
1515
dest: 'dist/bundle.js',
1616
format: 'umd',
1717
exports: 'named',

src/__tests__/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import { HelloWorld } from '..';
1+
import { HelloWorld, doSomethingAsync } from '..';
22
import * as utils from '../utils';
33

44
test('hello world', () => {
55
const thing = new HelloWorld('neat');
6-
76
expect(thing.getMessage()).toBe('Hello, this is neat');
87
});
98

109
test('utils', () => {
1110
expect(utils.add(1, 4)).toBe(5);
1211
});
12+
13+
test('async', async () => {
14+
const result = await doSomethingAsync();
15+
expect(result).toBe('hello');
16+
});

tsconfig.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
"compilerOptions": {
33
"target": "es5",
44
"module": "commonjs",
5+
"rootDir": "src",
56
"outDir": ".code",
67
"newLine": "LF",
7-
"importHelpers": true,
88
"lib": ["es2015", "es2016", "es2017"],
99
"moduleResolution": "node",
10+
"importHelpers": true,
1011
"declaration": true,
1112
"pretty": true,
1213
"sourceMap": true,
1314
"inlineSources": true,
1415
"noUnusedLocals": true,
1516
"strictNullChecks": true
1617
},
17-
"include": [
18-
"src/**/*"
19-
],
2018
"exclude": [
21-
"src/**/__tests__/*"
19+
"node_modules",
20+
"dist",
21+
"es",
22+
"lib"
2223
]
2324
}

0 commit comments

Comments
 (0)