Skip to content

Refactor again #51

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

Merged
merged 5 commits into from
Mar 20, 2017
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
61 changes: 54 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
# Created by https://www.gitignore.io/api/node,visualstudiocode
# Created by https://www.gitignore.io/api/node,visualstudiocode,macos

# Generated stuff
.code
dist
lib
es

### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

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

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

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

# Dependency directories
node_modules
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm
Expand All @@ -45,12 +87,17 @@ node_modules
# Output of 'npm pack'
*.tgz

# Distributed files
dist
# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

### VisualStudioCode ###
.vscode/*
!.vscode/*.json
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# Other stuff
.code
# End of https://www.gitignore.io/api/node,visualstudiocode,macos
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ node_js:
cache:
directories:
- node_modules
before_install:
- if [[ $(npm --version) == 2* ]]; then npm install -g npm@latest-3; fi
after_success:
- npm i -g coveralls
- cat coverage/remapped/lcov.info | coveralls
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": "0.2.0",
"configurations": [{
"name": "Debug tests",
"type": "node",
"request": "launch",
"protocol": "auto",
"stopOnEntry": false,
"console": "integratedTerminal",
"args": [
"node_modules/.bin/jest",
"--no-cache",
"--runInBand",
"--env=node-debug",
"--config=$(node jest.config.js)"
],
"skipFiles": [
"<node_internals>/**/*.js",
"${workspaceRoot}/node_modules/**/*.js"
]
}]
}
44 changes: 44 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node
var semver = require('semver');

function getSupportedTypescriptTarget() {
var nodeVersion = process.versions.node;

if (semver.gt(nodeVersion, '7.6.0')) {
return 'es2017'
} else if (semver.gt(nodeVersion, '7.0.0')) {
return 'es2016';
} else if (semver.gt(nodeVersion, '6.0.0')) {
return 'es2015';
} else if (semver.gt(nodeVersion, '4.0.0')) {
return 'es5';
} else {
return 'es3';
}
}

var jestConfig = {
transform: {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
testResultsProcessor: "<rootDir>/node_modules/ts-jest/coverageprocessor.js",
testRegex: "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
testPathIgnorePatterns: [
"<rootDir>[/\\\\](dist|coverage|node_modules)[/\\\\]",
"_\\w*.\\w+$"
],
moduleFileExtensions: ["ts", "tsx", "js"],
globals: {
__TS_CONFIG__: {
target: getSupportedTypescriptTarget(),
inlineSourceMap: true
}
}
};

module.exports = jestConfig;

// If this file is run as an executable, print the config stringified to JSON
if (require.main === module) {
console.log(JSON.stringify(jestConfig));
}
16 changes: 0 additions & 16 deletions jest.config.json

This file was deleted.

57 changes: 30 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
"description": "Boilerplate for TypeScript 2.0 libraries",
"author": "Max Davidson <[email protected]>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/maxdavidson/typescript-library-boilerplate.git"
},
"main": "dist/cjs/index.js",
"module": "dist/es/index.js",
"browser": "bundle.js",
"typings": "typings.d.ts",
"repository": "git+https://github.com/maxdavidson/typescript-library-boilerplate.git",
"main": "lib/index.js",
"module": "es/index.js",
"browser": "dist/bundle.js",
"types": "dist/bundle.d.ts",
"scripts": {
"build": "npm run build:cjs & npm run build:umd",
"build:cjs": "tsc --outDir dist/cjs --module commonjs",
"build:es": "tsc --outDir dist/es --module es2015",
"build:umd": "npm run build:es && rollup --config && dts-bundle --name typings --main dist/es --outputAsModuleFolder",
"clean": "rimraf dist coverage",
"build": "npm run build:lib & npm run build:umd",
"build:lib": "tsc --outDir lib --module commonjs",
"build:es": "tsc --outDir es --module es2015",
"build:umd": "npm run build:es && rollup --config && dts-bundle --name dist/bundle --main es --outputAsModuleFolder",
"clean": "rimraf dist es lib coverage",
"typecheck": "tsc --noEmit",
"lint": "tslint --project tsconfig.json --type-check --format stylish",
"test": "jest --config jest.config.json --coverage --no-cache --runInBand",
"test:watch": "jest --config jest.config.json --watch",
"test": "jest --coverage --no-cache --config $(node jest.config.js)",
"test:watch": "jest --watch --updateSnapshot --config $(node jest.config.js)",
"prepare": "npm run build",
"prebuild": "npm run clean",
"postbuild": "rimraf {lib,es}/**/__tests__",
"posttest": "npm run typecheck && npm run lint",
"preversion": "npm test",
"postversion": "git push && git push --tags"
Expand All @@ -34,27 +33,31 @@
"boilerplate"
],
"files": [
"lib",
"es",
"dist"
],
"dependencies": {
"@types/node": "^7.0.5",
"tslib": "^1.5.0"
"@types/node": "^7.0.8",
"tslib": "^1.6.0"
},
"devDependencies": {
"@types/jest": "^18.1.1",
"@types/jest": "^19.2.2",
"dts-bundle": "^0.7.2",
"jest": "^19.0.0",
"pascal-case": "^2.0.0",
"rimraf": "^2.5.4",
"rollup": "^0.41.4",
"rollup-plugin-commonjs": "^7.0.0",
"rollup-plugin-node-builtins": "^2.0.0",
"jest": "^19.0.2",
"jest-environment-node-debug": "^2.0.0",
"pascal-case": "^2.0.1",
"rimraf": "^2.6.1",
"rollup": "^0.41.6",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-builtins": "^2.1.0",
"rollup-plugin-node-globals": "^1.1.0",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-sourcemaps": "^0.4.1",
"rollup-plugin-uglify": "^1.0.1",
"ts-jest": "^19.0.0",
"tslint": "^4.4.2",
"typescript": "^2.2.0"
"semver": "^5.3.0",
"ts-jest": "^19.0.2",
"tslint": "^4.5.1",
"typescript": "^2.2.1"
}
}
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const pkg = require('./package');
export default {
moduleId: pkg.name,
moduleName: pascalCase(pkg.name),
entry: 'dist/es/index.js',
entry: 'es/index.js',
dest: 'dist/bundle.js',
format: 'umd',
exports: 'named',
Expand Down
8 changes: 6 additions & 2 deletions src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { HelloWorld } from '..';
import { HelloWorld, doSomethingAsync } from '..';
import * as utils from '../utils';

test('hello world', () => {
const thing = new HelloWorld('neat');

expect(thing.getMessage()).toBe('Hello, this is neat');
});

test('utils', () => {
expect(utils.add(1, 4)).toBe(5);
});

test('async', async () => {
const result = await doSomethingAsync();
expect(result).toBe('hello');
});
11 changes: 6 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"rootDir": "src",
"outDir": ".code",
"newLine": "LF",
"importHelpers": true,
"lib": ["es2015", "es2016", "es2017"],
"moduleResolution": "node",
"importHelpers": true,
"declaration": true,
"pretty": true,
"sourceMap": true,
"inlineSources": true,
"noUnusedLocals": true,
"strictNullChecks": true
},
"include": [
"src/**/*"
],
"exclude": [
"src/**/__tests__/*"
"node_modules",
"dist",
"es",
"lib"
]
}
Loading