Skip to content

TypeScript Boilerplate #17

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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions typescript/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions typescript/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
3 changes: 3 additions & 0 deletions typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
yarn.lock
dist
1 change: 1 addition & 0 deletions typescript/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 5 additions & 0 deletions typescript/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
9 changes: 9 additions & 0 deletions typescript/license
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) <%= name %> <<%= email %>> (<%= website %>)

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.
62 changes: 62 additions & 0 deletions typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "<%= moduleName %>",
"version": "0.0.0",
"description": "",
"license": "MIT",
"repository": "<%= githubUsername %>/<%= moduleName %>",
"author": {
"name": "<%= name %>",
"email": "<%= email %>",
"url": "<%= website %>"
},
"engines": {
"node": ">=6"
},
"scripts": {
"build": "del dist && tsc",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should open an issue on TypeScript for tsc to get a --cleanup flag or something so we don't need del dist.

By "we", I'm hoping you can do it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of reading through a bunch of TypeScript Issues:

They don't like to delete a folder completely (good summary microsoft/TypeScript#13722) but deleting output files when the source files are gone is an ongoing Issue (microsoft/TypeScript#16057).
Sadly this issue is not planned for one of the next releases (attached as a Milestones).

"prepare": "npm run build",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why prepare? I usually use prepublishOnly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prepare as build script in package.json. npm-scripts describes prepare, prepack and prepublishOnly. I personally like to check package content via npm pack so prepublishOnly is not helpful here. prepare also runs on a npm install without arguments as its done after a git clone. This might save some time as it hasn't to be done manually but could be annoying on WIP feature branches. The safest solution would be prepack but I think prepare is a nice to have.

Copy link
Author

@EdJoPaTo EdJoPaTo Mar 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to prepack as prepare runs into errors with a fresh start repo. As prepare is not needed anyway use prepack as it runs on npm pack and npm publish.

"pretest": "npm run build",
"test": "xo && ava"
},
"main": "dist",
"types": "dist",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer to put non-standard package.json properties at the end.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea here is that it nearly does the same as main does.

"files": [
"dist",
"!*.test.*"
],
"keywords": [
""
],
"dependencies": {},
"devDependencies": {
"@sindresorhus/tsconfig": "^0.2.1",
"@types/node": "^11.9.0",
"@typescript-eslint/eslint-plugin": "^1.3.0",
"ava": "^1.2.1",
"del-cli": "^1.1.0",
"eslint-config-xo-typescript": "^0.8.0",
"ts-node": "^8.0.2",
"typescript": "^3.3.3",
"xo": "^0.24.0"
},
"ava": {
"babel": false,
"compileEnhancements": false,
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
},
"xo": {
"extends": "xo-typescript",
"extensions": [
"ts"
],
"rules": {
"@typescript-eslint/promise-function-async": "off",
"ava/no-ignored-test-files": "off"
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A goal of mine is to get rid of a lot of the config boilerplate here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. But sadly we are not there yet. It's currently the way to go so until its possible to do it more clean I would like to keep the current state here. That way everyone can see what still has to be done.

}
47 changes: 47 additions & 0 deletions typescript/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# <%= moduleName %> [![Build Status](https://travis-ci.org/<%= githubUsername %>/<%= moduleName %>.svg?branch=master)](https://travis-ci.org/<%= githubUsername %>/<%= moduleName %>)

>


## Install

```
$ npm install <%= moduleName %>
```


## Usage

```js
const <%= camelModuleName %> = require('<%= moduleName %>');

<%= camelModuleName %>('unicorns');
//=> 'unicorns & rainbows'
```


## API

### <%= camelModuleName %>(input, [options])

#### input

Type: `string`

Lorem ipsum.

#### options

Type: `Object`

##### foo

Type: `boolean`<br>
Default: `false`

Lorem ipsum.


## License

MIT © [<%= name %>](https://github.com/<%= githubUsername %>)
9 changes: 9 additions & 0 deletions typescript/source/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

export default function(input: string) {
if (typeof input !== 'string') {
throw new TypeError(`Expected a string, got ${typeof input}`);
}

return input + ' & rainbows';
};
11 changes: 11 additions & 0 deletions typescript/test/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import test from 'ava';
import moduleName from '.';

test('title', t => {
const err = t.throws(() => {
moduleName(123);
}, TypeError);
t.is(err.message, 'Expected a string, got number');

t.is(moduleName('unicorns'), 'unicorns & rainbows');
});