Skip to content

Commit

Permalink
Merge pull request #1 from DxCx/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
DxCx committed Sep 19, 2016
2 parents db8a944 + 4194899 commit c4a8a4d
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 148 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
*
!modules/
!modules/*
!src/
!src/**/*
!*.js
!*.json
!*.md
!.babelrc
!mocha-webpack.opts
!.gitignore
!.travis.yml
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*
!lib/*
!dist/**/*
!package.json
!*.md
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: node_js

node_js:
- "6.2"
- "6.3"
- "6.4"
- "6.5"
- "4.4"

install:
- npm config set spin=false
- npm install -g coveralls
- npm install

script:
- npm test
- npm run coverage
- coveralls < ./coverage/lcov.info || true # if coveralls doesn't have it covered

# Allow Travis tests to run in containers.
sudo: false
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# ts-library-starter
[![NPM version](https://img.shields.io/npm/v/ts-library-starter.svg)](https://www.npmjs.com/package/ts-library-starter)
[![Build Status](https://travis-ci.org/DxCx/ts-library-starter.svg?branch=master)](https://travis-ci.org/DxCx/ts-library-starter)
[![Coverage Status](https://coveralls.io/repos/DxCx/ts-library-starter/badge.svg?branch=)](https://coveralls.io/r/DxCx/ts-library-starter?branch=master)
[![Standard Version](https://img.shields.io/badge/release-standard%20version-brightgreen.svg)](https://github.com/conventional-changelog/standard-version)

Example git project that is used for typescript libraries as a starter pack

What does it include:
----
1. exported class as example for an npm moudle
2. packaging for npm modules (webpack + tslint + awesome-typescript-loader + dts-bundle)
3. testings for npm modules (mocha + chai)
4. code coverage (istanbul) when running tests
3. testings for npm modules (jest)
4. code coverage (jest) when running tests
5. Typescript => ES6 => ES5 (babel)
6. Two versions embed in the package, one for node, one for browser (browserify)

Expand All @@ -17,37 +21,34 @@ Please note that you will need to rename the library name in some files:

1. webpack.config.js (bundle_opts)
2. package.json (ofcourse ;))
Also don't forget to reset package version ;)

Useful commands:
----
npm run prebuild - install NPM dependancies
npm run build - build the library files
npm run test - run the tests
npm run test:watch - run the tests
npm run pack - build the library, make sure the tests passes, and then pack the library (creates .tgz)
npm publish - publish the library in npm repositories
npm run prebuild - install NPM dependancies
npm run build - build the library files
npm run test - run the tests
npm run test:watch - run the tests (watch-mode)
npm run coverage - run the tests with coverage
npm run coverage:watch - run the tests with coverage (watch-mode)
npm run pack - build the library, make sure the tests passes, and then pack the library (creates .tgz)
npm run release - prepare package for next release

Files explained:
----
1. modules - directory is used for typescript code that is part of the project
1a. modules/Example.ts - Just an example exported library, used to should import in tests.
1b. modules/Example.spec.ts - tests for the example class
1c. modules/index.ts - index, which functionality is exported from the library
1d. modules/main.ts - just wrapper for index
1d. modules/main.test.ts - test runner
2. mocha-webpack.opts - options for mocha-webpack (tests)
1. src - directory is used for typescript code that is part of the project
1a. src/Example.ts - Just an example exported library, used to should import in tests.
1b. src/Example.spec.ts - tests for the example class
1c. src/index.ts - index, which functionality is exported from the library
1d. src/main.ts - just wrapper for index
3. package.json - file is used to describe the library
4. tsconfig.json - configuration file for the library compilation
5. tsconfig.test.json - configuration file for the tests compilation
6. tslint.json - configuration file for the linter (both test and library)
7. typings.json - typings needed for the library/tests
8. webpack.config.js - configuration file of the compilation automation process for the library
9. webpack.config.test.js - configuration file of the compilation automation process for the test

Output files explained:
----
1. node_modules - directory npm creates with all the dependencies of the module (result of npm install)
2. lib - directory contains the compiled library (javascript + typings)
1. node_modules - directory npm creates with all the dependencies of the module (result of npm install)
2. dist - directory contains the compiled library (javascript + typings)
3. <module_name>-<module_version>.tgz - final tgz file for publish. (result of npm run pack)
4. html-report - code coverage report output made by istanbul
5. .tmp - temporary file built for tests
4. coverage - code coverage report output made by istanbul
4 changes: 0 additions & 4 deletions mocha-webpack.opts

This file was deleted.

19 changes: 0 additions & 19 deletions modules/Example.spec.ts

This file was deleted.

19 changes: 0 additions & 19 deletions modules/main.test.ts

This file was deleted.

45 changes: 26 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
"name": "ts-library-starter",
"version": "0.0.6",
"description": "Example git project that is used for typescript libraries as a starter pack",
"main": "lib/main.js",
"typings": "lib/main.d.ts",
"main": "dist/main.js",
"typings": "dist/main.d.ts",
"jam": {
"main": "./lib/main.browser.js"
"main": "./dist/main.browser.js"
},
"browser": {
"lib/main.js": "./lib/main.browser.js"
"dist/main.js": "./dist/main.browser.js"
},
"scripts": {
"prebuild": "npm install",
"build": "webpack || echo not ok",
"test": "mocha-webpack",
"test": "jest",
"test:watch": "npm test -- --watch",
"prepack": "standard-version && npm run build && npm test",
"pack": "npm pack"
"coverage": "npm test -- --coverage --no-cache",
"coverage:watch": "npm run coverage -- --watch",
"prerelease": "npm run build && npm test",
"release": "standard-version && npm pack"
},
"repository": {
"type": "git",
Expand All @@ -32,10 +34,10 @@
"dts-bundle",
"package",
"tslint",
"mocha",
"chai",
"jest",
"babel",
"tsloader",
"boilerplate",
"awesome-typescript-loader"
],
"author": "Hagai Cohen",
Expand All @@ -45,28 +47,33 @@
},
"homepage": "https://github.com/DxCx/ts-library-starter#readme",
"devDependencies": {
"@types/chai": "^3.4.32",
"@types/mocha": "^2.2.31",
"@types/jest": "^0.9.31",
"@types/node": "^6.0.38",
"awesome-typescript-loader": "^2.2.1",
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.14.0",
"browserify": "^13.1.0",
"chai": "^3.5.0",
"delete-empty": "^0.1.3",
"dts-bundle": "^0.5.0",
"istanbul": "^0.4.5",
"mocha": "^3.0.2",
"mocha-istanbul-spec": "^0.3.0-remap",
"mocha-webpack": "^0.6.0",
"jest": "^15.1.1",
"standard-version": "^2.4.0",
"tslint": "^3.15.1",
"tslint-loader": "^2.1.5",
"typescript": "2.0.0",
"typescript-babel-jest": "^0.1.2",
"webpack": "^2.1.0-beta.22",
"webpack-fail-plugin": "^1.0.5",
"webpack-istanbul-plugin": "0.0.3",
"webpack-node-externals": "^1.3.3"
"webpack-node-externals": "^1.4.3"
},
"dependencies": {},
"jest": {
"scriptPreprocessor": "node_modules/typescript-babel-jest",
"testEnvironment": "node",
"testRegex": ".*\\.spec\\.ts$",
"moduleFileExtensions": [
"ts",
"js",
"json"
]
}
}
14 changes: 14 additions & 0 deletions src/Example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

import 'jest';
import { Example } from "./Example";

describe("Example", () => {
it("Should be pass sanity", () => {
expect(typeof Example).toBe("function");
});

it("Should be able to create new instance", () => {
expect(typeof new Example()).toBe("object");
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"emitDecoratorMetadata": true,
"sourceMap": false,
"declaration": true,
"outDir": "lib",
"outDir": "dist",
"removeComments": false,
"typeRoots": [
"node_modules/@types"
Expand All @@ -20,7 +20,7 @@
]
},
"files": [
"modules/main.ts"
"src/main.ts"
],
"exclude": [
"node_modules"
Expand Down
23 changes: 10 additions & 13 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ var fs = require('fs');
var os = require('os');
var dts = require('dts-bundle');
var deleteEmpty = require('delete-empty');
var failPlugin = require('webpack-fail-plugin');

/* helper function to get into build directory */
var libPath = function(name) {
if ( undefined === name ) {
return 'lib';
return 'dist';
}

return path.join('lib', name);
return path.join('dist', name);
}

/* helper to clean leftovers */
Expand Down Expand Up @@ -82,18 +81,18 @@ var bundle_opts = {
// if you want to load all .d.ts files from a path recursively you can use "path/project/**/*.d.ts"
// ^ *** Experimental, TEST NEEDED, see "All .d.ts files" section
// - either relative or absolute
main: 'modules/main.d.ts',
main: 'src/main.d.ts',

// Optional

// base directory to be used for discovering type declarations (i.e. from this project itself)
// - default: dirname of main
baseDir: 'modules',
baseDir: 'src',
// path of output file. Is relative from baseDir but you can use absolute paths.
// if starts with "~/" then is relative to current path. See https://github.com/TypeStrong/dts-bundle/issues/26
// ^ *** Experimental, TEST NEEDED
// - default: "<baseDir>/<name>.d.ts"
out: '../lib/main.d.ts',
out: '../dist/main.d.ts',
// include typings outside of the 'baseDir' (i.e. like node.d.ts)
// - default: false
externals: false,
Expand All @@ -116,7 +115,7 @@ var bundle_opts = {
indent: ' ',
// prefix for rewriting module names
// - default ''
prefix: '__',
prefix: '',
// separator for rewriting module 'path' names
// - default: forward slash (like sub-modules)
separator: '/',
Expand All @@ -132,11 +131,11 @@ var bundle_opts = {
// - default: false
emitOnNoIncludedFileNotFound: false,
// output d.ts as designed for module folder. (no declare modules)
outputAsModuleFolder: true
outputAsModuleFolder: false
};

var webpack_opts = {
entry: './modules/main.ts',
entry: './src/main.ts',
target: 'node',
output: {
filename: libPath('main.js'),
Expand All @@ -146,7 +145,7 @@ var webpack_opts = {
extensions: ['', '.ts', '.js'],
modules: [
'node_modules',
'modules',
'src',
]
},
module: {
Expand All @@ -155,9 +154,7 @@ var webpack_opts = {
},
externals: [nodeExternals()],
plugins: [
failPlugin,
// TODO: Minifiy JS.
// new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.UglifyJsPlugin(),
new webpack.ProgressPlugin(percentage_handler)
],
tslint: {
Expand Down
Loading

0 comments on commit c4a8a4d

Please sign in to comment.