diff --git a/umd/.gitignore b/umd/.gitignore new file mode 100644 index 0000000..d751509 --- /dev/null +++ b/umd/.gitignore @@ -0,0 +1,4 @@ +node_modules +shared/timeReporter.js +browser/app.js +node/app.js \ No newline at end of file diff --git a/umd/README.md b/umd/README.md new file mode 100644 index 0000000..76ab775 --- /dev/null +++ b/umd/README.md @@ -0,0 +1,36 @@ +**Fetch dependencies:** +``` +npm install +``` + +**Compile TypeScript source code** + +``` +node node_modules/typescript/bin/tsc.js +``` + +**Start browser version of the sample using http-server on custom port (code should be compiled prior to this step)** +``` +node node_modules/http-server/bin/http-server -p 8080 -o +``` +'-p' sets the port to use, default port is 8080. If it is taken pick any port that is free. +After server is started open 'localhost:8080' in a browser. + + +**Run example using Node (code should be compiled prior to this step)** + +``` +node node/app.js +``` + +Shortcuts for doing compile\run steps from above: + +*Browser* +``` +npm run browser +``` + +*Node* +``` +npm run node +``` \ No newline at end of file diff --git a/umd/browser/app.css b/umd/browser/app.css new file mode 100644 index 0000000..eb24fc6 --- /dev/null +++ b/umd/browser/app.css @@ -0,0 +1,8 @@ +body +{ + font-family: 'Segoe UI', sans-serif +} + +span { + font-style: italic +} \ No newline at end of file diff --git a/umd/browser/app.ts b/umd/browser/app.ts new file mode 100644 index 0000000..a2445f7 --- /dev/null +++ b/umd/browser/app.ts @@ -0,0 +1,13 @@ +import { TimeReporter } from '../shared/timeReporter' + +let element = document.getElementById("content"); +element.innerText += "The time is: "; +let span = document.createElement("span"); +element.appendChild(span); + +function printer(s: string): void { + span.innerText = s; +} + +let timeReporter = new TimeReporter(printer); +timeReporter.start(); diff --git a/umd/index.html b/umd/index.html new file mode 100644 index 0000000..b0f2761 --- /dev/null +++ b/umd/index.html @@ -0,0 +1,15 @@ + + + + + + TypeScript HTML App + + + + +

UMD/TypeScript sample

+ +
+ + \ No newline at end of file diff --git a/umd/node/app.ts b/umd/node/app.ts new file mode 100644 index 0000000..2dd78fe --- /dev/null +++ b/umd/node/app.ts @@ -0,0 +1,8 @@ +import { TimeReporter } from '../shared/timeReporter' +import { EOL } from 'os'; +function printer(s): void { + console.log("The time is: " + s + EOL); +} + +let timeReporter = new TimeReporter(printer); +timeReporter.start(); \ No newline at end of file diff --git a/umd/node/os.d.ts b/umd/node/os.d.ts new file mode 100644 index 0000000..e817365 --- /dev/null +++ b/umd/node/os.d.ts @@ -0,0 +1,3 @@ +declare module "os" { + export var EOL: string; +} \ No newline at end of file diff --git a/umd/package.json b/umd/package.json new file mode 100644 index 0000000..c04ab60 --- /dev/null +++ b/umd/package.json @@ -0,0 +1,19 @@ +{ + "name": "typescript-umd", + "version": "1.0.0", + "description": "UMD/TypeScript demo", + "repository": { + "type": "git", + "url": "https://github.com/Microsoft/TypeScriptSamples.git" + }, + "dependencies": { + "http-server": "0.8.0" + }, + "devDependencies": { + "typescript": "^1.5.3" + }, + "scripts": { + "browser": "node node_modules/typescript/bin/tsc.js && node node_modules/http-server/bin/http-server -o", + "node": "node node_modules/typescript/bin/tsc.js && node node/app.js" + } +} \ No newline at end of file diff --git a/umd/shared/timeReporter.ts b/umd/shared/timeReporter.ts new file mode 100644 index 0000000..2832cc4 --- /dev/null +++ b/umd/shared/timeReporter.ts @@ -0,0 +1,23 @@ +export type Printer = (s: string) => void; + +export class TimeReporter +{ + printer: Printer + timerToken: number; + + constructor (printer: Printer) + { + this.printer = printer; + this.printer(new Date().toUTCString()); + } + + start() + { + this.timerToken = setInterval(() => this.printer(new Date().toUTCString()), 500); + } + + stop() + { + clearTimeout(this.timerToken); + } +} diff --git a/umd/tsconfig.json b/umd/tsconfig.json new file mode 100644 index 0000000..31e412e --- /dev/null +++ b/umd/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "UMD", + "target": "es5" + }, + "files": [ + "shared/timeReporter.ts", + "browser/app.ts", + "node/os.d.ts", + "node/app.ts" + ] +} \ No newline at end of file