Skip to content

Commit

Permalink
feat: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mitch-b committed Sep 24, 2017
0 parents commit 6c8672b
Show file tree
Hide file tree
Showing 74 changed files with 15,202 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Example Contributing Guidelines

This is an example of GitHub's contributing guidelines file. Check out GitHub's [CONTRIBUTING.md help center article](https://help.github.com/articles/setting-guidelines-for-repository-contributors/) for more information.
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* **I'm submitting a ...**
[ ] bug report
[ ] feature request
[ ] question about the decisions made in the repository
[ ] question about how to use this project

* **Summary**



* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
13 changes: 13 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
* **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...)



* **What is the current behavior?** (You can also link to an open issue here)



* **What is the new behavior (if this is a feature change)?**



* **Other information**:
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
build
test
src/**.js

coverage
.nyc_output
*.log
14 changes: 14 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
src
config
examples
test
tsconfig.json
tslint.json
.travis.yml
.github
build/temp
build/docs

coverage
.nyc_output
*.log
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sudo: false
language: node_js
node_js:
- 8
- 6
- 4
after_success:
- yarn send-coverage
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Change Log

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Mitchell Barry

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.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# <img src='http://svgshare.com/i/38a.svg' height='20px' alt='TypeDeck' /> TypeDeck
_`typedeck`_

A [TypeScript](https://www.typescriptlang.org/) library for playing cards.

## All package scripts

You can run the `info` script for information on each script intended to be individually run.

```
yarn run info
info:
Display information about the scripts
build:
(Trash and re)build the library
lint:
Lint all typescript source files
unit:
Build the library and run unit tests
test:
Lint, build, and test the library
watch:
Watch source files, rebuild library on changes, rerun relevant tests
cov:
Run tests, generate the HTML coverage report, and open it in a browser
docs:
Generate HTML API documentation and open it in a browser
docs:publish:
Generate HTML API documentation and push it to GitHub Pages
docs:json:
Generate API documentation in typedoc JSON format
release:
Bump package.json version, update CHANGELOG.md, tag a release
reset:
Delete all untracked files and reset the repo to the last commit
publish:
Reset, build, test, publish docs, and prepare release (a one-step publish process)
```

## Credits

* Card images by Ben Davis from the Noun Project
* This library package is built from work by Jason Dreyzehner's [typescript-starter](https://github.com/bitjson/typescript-starter) project. This was the building block for docs, code coverage, and testing (among others).
41 changes: 41 additions & 0 deletions config/exports/build-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// this script watches the tests exported by typescript, copies them to the test directories, and modifies the require("PKG.NAME") statements to test each build
const cpx = require("cpx");
const separator = require("path").sep;
const Transform = require("stream").Transform;
const pkg = require('../../package');
const req = (path) => 'require("' + path + '")';
const pathUp = (levels) => Array.from(Array(levels), () => '../').join('');

// replace instances of pkg.name with the proper route to the build being tested
const makeTransform = (filePath, buildPath) => {
const buildPathParts = buildPath.split(separator);
// filePath includes build/main (-2), test/BUILD is 2 deep (+2),
// remove filename (-1). Total is length - 2
const pathToRoot = pathUp(filePath.split(separator).length - 1);
const placeholder = req(pkg.name);
return new Transform({
transform(chunk, encoding, done) {
const str = chunk.toString();
const parts = str.split(placeholder)
const newPath = req(pathToRoot + buildPath)
const result = parts.join(newPath);
this.push(result);
done();
}
});
}

// copy, then watch for changes to the tests
const testsFromRoot = 'build/main/**/*.spec.js';
const watchMode = process.argv.indexOf('-w') !== -1 ? true : false;
const browserTests = process.argv.indexOf('--no-browser') !== -1 ? true : false;
const task = watchMode ? cpx.watch : cpx.copy;

task(testsFromRoot, 'test/main', {
transform: (filePath) => makeTransform(filePath, pkg.main)
});
if (!browserTests) {
task(testsFromRoot, 'test/browser', {
transform: (filePath) => makeTransform(filePath, pkg.browser.replace('.js', '.cjs.js'))
});
}
21 changes: 21 additions & 0 deletions config/exports/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// rollup.config.js
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
import alias from 'rollup-plugin-alias';

const substituteModulePaths = {
'crypto': 'build/module/adapters/crypto.browser.js',
'hash.js': 'build/temp/hash.js'
}

export default {
entry: 'build/module/index.js',
sourceMap: true,
plugins: [
alias(substituteModulePaths),
nodeResolve({
browser: true
}),
commonjs()
]
}
9 changes: 9 additions & 0 deletions config/exports/tsconfig.module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "../../build/module",
"rootDir": "../../src",
"module": "es6",
"declaration": false
}
}
5 changes: 5 additions & 0 deletions config/tsconfig.flexible.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"strictNullChecks": true
}
}
12 changes: 12 additions & 0 deletions config/tsconfig.strict.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny" : true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true
}
}
21 changes: 21 additions & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "typedeck-example-browser",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"start": "http-server -c-1 ./build/ -o",
"build": "rollup -c && cpy src/index.html build/"
},
"devDependencies": {
"cpy-cli": "^1.0.1",
"http-server": "^0.9.0",
"rollup": "^0.41.4",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-typescript": "^0.8.1",
"typescript": "^2.2.0"
},
"dependencies": {
"typedeck": "^0.0.1"
},
"private": true
}
27 changes: 27 additions & 0 deletions examples/browser/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// rollup.config.js
import typescript from 'rollup-plugin-typescript';
import nodeResolve from 'rollup-plugin-node-resolve';

const pkg = require('./package');

export default {
entry: 'src/test.ts',
moduleId: pkg.name,
moduleName: 'BrowserTest',
// entry: 'dist/es/index.js',
dest: 'build/test.js',
format: 'iife',
sourceMap: true,
plugins: [
typescript({
typescript: require('typescript') // use local version
}),
nodeResolve({
module: true,
jsnext: true,
browser: true,
extensions: [ '.js', '.json' ],
preferBuiltins: false
})
]
}
10 changes: 10 additions & 0 deletions examples/browser/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>

<head>
<script src="test.js"></script>
</head>

<body>
</body>

</html>
11 changes: 11 additions & 0 deletions examples/browser/src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PlayingCard, CardName, Suit } from 'typedeck'

let playingCard = new PlayingCard(CardName.Jack, Suit.Clubs)

let expectedString = 'Jack of Clubs'

if (playingCard.toString() === expectedString) {
console.log('Success!')
} else {
console.log('Card did not contain expected value')
}
16 changes: 16 additions & 0 deletions examples/browser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "build",
"rootDir": "src",
"module": "es6",
"declaration": false,
"removeComments": true,
"lib": [
"dom"
]
},
"include": [
"src/*.ts"
]
}
17 changes: 17 additions & 0 deletions examples/node-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "typedeck-example-node-typescript",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"start": "node build/test.js",
"build": "tsc"
},
"devDependencies": {
"@types/node": "^7.0.5",
"typescript": "^2.1.6"
},
"dependencies": {
"typedeck": "^0.0.1"
},
"private": true
}
7 changes: 7 additions & 0 deletions examples/node-typescript/src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Typescript should resolve this using the same algorithm as Node.js.
// See examples/node-vanilla for more info.
import { ICard } from 'typedeck'
import * as assert from 'assert'

assert(12 === 12)
console.log('✔ double(6) === 12')
10 changes: 10 additions & 0 deletions examples/node-typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "build",
"rootDir": "src"
},
"include": [
"src/*.ts"
]
}
12 changes: 12 additions & 0 deletions examples/node-vanilla/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "typedeck-example-node-vanilla",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"start": "node test.js"
},
"dependencies": {
"typedeck": "^0.0.1"
},
"private": true
}
9 changes: 9 additions & 0 deletions examples/node-vanilla/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Node.js should resolve this to the root of the repo. Since the path returns a
// directory, node will look for the `main` property in `package.json`, which
// should point to the `main` build.
var typedeck = require('typedeck');

// now we can use the library
var assert = require('assert');

assert(true);
Loading

0 comments on commit 6c8672b

Please sign in to comment.