Skip to content

Commit

Permalink
Base files with Typescript
Browse files Browse the repository at this point in the history
Base files with Typescript
  • Loading branch information
CarreraPHP committed Dec 24, 2016
0 parents commit 8ad0163
Show file tree
Hide file tree
Showing 16 changed files with 199 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/
node_modules/
npm-debug.log
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib/"
}
23 changes: 23 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"args": ["run"],
"showOutput": "always",
"tasks": [
{
"taskName": "build",
"isBuildCommand": true
},
{
"taskName": "clean"
},
{
"taskName": "lint"
},
{
"taskName": "test",
"isTestCommand": true
}
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016

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.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Using this module in other modules

Here is a quick example of how this module can be used in other modules. The [TypeScript Module Resolution Logic](https://www.typescriptlang.org/docs/handbook/module-resolution.html) makes it quite easy. The file `src/index.ts` acts as an aggregator of all the functionality in this module. It imports from other files and re-exports to provide a unified interface for this module. The _package.json_ file contains `main` attribute that points to the generated `lib/index.js` file and `typings` attribute that points to the generated `lib/index.d.ts` file.

> If you are planning to have code in multiple files (which is quite natural for a NodeJS module) that users can import, make sure you update `src/index.ts` file appropriately.
Now assuming you have published this amazing module to _npm_ with the name `my-amazing-lib`, and installed it in the module in which you need it -

- To use the `Greeter` class in a TypeScript file -

```ts
import { Greeter } from "my-amazing-lib";

const greeter = new Greeter("World!");
greeter.greet();
```

- To use the `Greeter` class in a JavaScript file -

```js
const Greeter = require('my-amazing-lib').Greeter;

const greeter = new Greeter('World!');
greeter.greet();
```
5 changes: 5 additions & 0 deletions lib/greeter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare class Greeter {
private greeting;
constructor(message: string);
greet(): string;
}
12 changes: 12 additions & 0 deletions lib/greeter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";
var Greeter = (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Bonjour, " + this.greeting + "!";
};
return Greeter;
}());
exports.Greeter = Greeter;
;
2 changes: 2 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { Greeter } from "./greeter";
export { Greeter };
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
var greeter_1 = require("./greeter");
exports.Greeter = greeter_1.Greeter;
42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "scaffolding-all",
"version": "0.0.0",
"description": "Scaffold your application based on an documentation",
"license": "MIT",
"repository": "",
"files": [
"lib"
],
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"scripts": {
"clean": "rimraf lib",
"lint": "tslint --force --format verbose \"src/**/*.ts\"",
"build": "npm run clean && npm run lint && echo Using TypeScript && tsc --version && tsc --pretty",
"test": "npm run build && mocha --compilers ts:ts-node/register --recursive test/**/*-spec.ts",
"watch": "npm run build -- --watch",
"watch:test": "npm run test -- --watch"
},
"keywords": [
"scaffold",
"yeoman-generator"
],
"author": "[email protected]",
"dependencies": {},
"devDependencies": {
"@types/chai": "^3.0.0",
"@types/json5": "0.0.29",
"@types/mocha": "^2.0.0",
"@types/node": "6.0.31",
"chai": "^3.0.0",
"json5": "^0.5.1",
"mocha": "^3.0.0",
"rimraf": "^2.0.0",
"ts-node": "^1.0.0",
"tslint": "^4.0.0",
"typescript": "^2.0.0"
},
"engines": {
"node": ">=4.0.0"
}
}
11 changes: 11 additions & 0 deletions src/greeter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class Greeter {
private greeting: string;

constructor(message: string) {
this.greeting = message;
}

public greet() {
return "Bonjour, " + this.greeting + "!";
}
};
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { json5 } from "json5";
import { Greeter } from "./greeter";

export { Greeter };
12 changes: 12 additions & 0 deletions test/greeter-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

import { Greeter } from "../src/greeter";
import * as chai from "chai";

const expect = chai.expect;

describe("greeter", () => {
it("should greet with message", () => {
const greeter = new Greeter("friend");
expect(greeter.greet()).to.equal("Bonjour, friend!");
});
});
18 changes: 18 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"declaration": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"outDir": "./lib",
"preserveConstEnums": true,
"removeComments": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*-spec.ts"
]
}
3 changes: 3 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "tslint:latest"
}

0 comments on commit 8ad0163

Please sign in to comment.