Skip to content

Commit ead662f

Browse files
authored
Merge pull request #190 from cartant/issue-151
Added a JS/TS example
2 parents 1a4e218 + 1533f18 commit ead662f

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
lines changed

examples/greeter/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"private": true,
1212
"dependencies": {
1313
"browserify": "^12.0.1",
14-
"tsify": "*"
14+
"tsify": "*",
15+
"typescript": "~1.8.7"
1516
}
1617
}

examples/js/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# tsify Sample: JS
2+
3+
A trivial TypeScript project building with tsify.
4+
5+
Based on the [TypeScript sample](https://github.com/Microsoft/TypeScriptSamples/tree/master/greeter).
6+
7+
## Building
8+
9+
Check out the scripts in `package.json` for examples on how to run a build with either the CLI or the API.
10+
11+
```sh
12+
npm run build-cli
13+
npm run build-script
14+
```

examples/js/build.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const browserify = require('browserify');
2+
const tsify = require('tsify');
3+
4+
browserify()
5+
.add('src/main.js')
6+
.plugin(tsify, { allowJs: true })
7+
.bundle()
8+
.on('error', function (error) { console.error(error.toString()); })
9+
.pipe(process.stdout);

examples/js/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "tsify-js",
3+
"version": "0.0.0",
4+
"description": "tsify Sample: JS",
5+
"scripts": {
6+
"build-cli": "browserify -p [ tsify --allowJs ] src/main.js",
7+
"build-script": "node ./build.js"
8+
},
9+
"author": "Greg Smith <[email protected]> (http://github.com/smrq)",
10+
"license": "MIT",
11+
"private": true,
12+
"dependencies": {
13+
"browserify": "^12.0.1",
14+
"tsify": "*",
15+
"typescript": "~1.8.7"
16+
}
17+
}

examples/js/src/Greeter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default class Greeter {
2+
constructor(public greeting: string) { }
3+
greet() {
4+
return "<h1>" + this.greeting + "</h1>";
5+
}
6+
};

examples/js/src/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Greeter from './Greeter';
2+
3+
const greeter = new Greeter("Hello, world!");
4+
document.body.innerHTML = greeter.greet();

examples/jsx/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"devDependencies": {
1414
"browserify": "^12.0.1",
1515
"http-server": "^0.8.5",
16-
"tsify": "*"
16+
"tsify": "*",
17+
"typescript": "~1.8.7"
1718
},
1819
"dependencies": {
1920
"react": "^0.14.3",

0 commit comments

Comments
 (0)