This repository was archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| lib/ | ||
| !src/lib/ | ||
| .vscode/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Async Functions | ||
|
|
||
| *Async Functions* are functions that can suspend their execution to wait for the completion of an | ||
| asynchronous operation. This allows complex algorithms that require asynchronous control flow to | ||
| be written sequentially. | ||
|
|
||
| This sample uses *Async Functions* to query the GitHub API to view information about recent pull | ||
| requests. | ||
|
|
||
| This sample requires a minimum of NodeJS v4.0.0. | ||
|
|
||
| **Fetch dependencies** | ||
| ``` | ||
| npm install | ||
| ``` | ||
|
|
||
| **Run** | ||
| ``` | ||
| npm test | ||
| ``` | ||
|
|
||
| **Environment variables** | ||
|
|
||
| | Name | Description | | ||
| |:------------------|:----------------------------------------------------------------------------| | ||
| | GITHUB_TOKEN | The Authentication token to use for GitHub API Requests. (Optional) | | ||
| | GITHUB_REPOSITORY | The GitHub repository to use for queries. (Default: "Microsoft/TypeScript") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| var gulp = require('gulp') | ||
| , sourcemaps = require('gulp-sourcemaps') | ||
| , ts = require('gulp-typescript') | ||
| , typescript = require('typescript') | ||
| , del = require('del') | ||
| , merge = require('merge2') | ||
| , path = require('path') | ||
| , spawn = require('child_process').spawn; | ||
|
|
||
| var lib = { | ||
| project: ts.createProject('./src/lib/tsconfig.json', { typescript: typescript }), | ||
| bin: "./bin/ts-async-github-sample", | ||
| main: "./lib/github", | ||
| base: "./src/lib/", | ||
| dest: "./lib/", | ||
| src: ["./src/lib/**/*.ts"], | ||
| out: ["./lib/**/*"] | ||
| }; | ||
|
|
||
| gulp.task("clean:lib", clean(lib)); | ||
| gulp.task("clean", ["clean:lib"]); | ||
| gulp.task("build:lib", build(lib)); | ||
| gulp.task("build", ["build:lib"]); | ||
| gulp.task("test", ["build"], test(lib)); | ||
| gulp.task("watch:lib", ["build:lib"], watch(src(lib), ["build:lib"])); | ||
| gulp.task("watch", ["build", "test"], watch(src(lib), ["test"])); | ||
| gulp.task("default", ["build"]); | ||
|
|
||
| function src() { | ||
| return Array.from(arguments).reduce(function (ar, opts) { | ||
| return ar.concat(opts.src); | ||
| }, []); | ||
| } | ||
|
|
||
| function clean(opts) { | ||
| return function (done) { | ||
| del(opts.out, done); | ||
| }; | ||
| } | ||
|
|
||
| function build(opts) { | ||
| return function () { | ||
| var tee = gulp | ||
| .src(opts.src, { base: opts.base }) | ||
| .pipe(sourcemaps.init()) | ||
| .pipe(ts(opts.project)); | ||
| return merge([ | ||
| tee.dts | ||
| .pipe(gulp.dest(opts.dest)), | ||
| tee.js | ||
| .pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: path.relative(opts.dest, opts.base) })) | ||
| .pipe(gulp.dest(opts.dest)) | ||
| ]); | ||
| }; | ||
| } | ||
|
|
||
| function test(opts) { | ||
| return function (done) { | ||
| var args = [opts.bin]; | ||
| console.log("Executing test..."); | ||
| spawn(process.argv[0], args, { stdio: "inherit" }).on("exit", function (code) { | ||
| done(code !== 0 ? "Error executing script." : undefined); | ||
| }); | ||
| }; | ||
| } | ||
|
|
||
| function watch(src, tasks) { | ||
| return function () { | ||
| return gulp.watch(src, tasks); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES6" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "name": "ts-node-github-async-sample", | ||
| "version": "1.0.0", | ||
| "description": "Sample for Async Functions in NodeJS v4.0.0", | ||
| "private": true, | ||
| "main": "lib/github.js", | ||
| "bin": { | ||
| "sample": "./bin/ts-async-github-sample" | ||
| }, | ||
| "dependencies": {}, | ||
| "devDependencies": { | ||
| "del": "^2.0.2", | ||
| "gulp": "^3.9.0", | ||
| "gulp-sourcemaps": "^1.5.2", | ||
| "gulp-typescript": "^2.9.0", | ||
| "merge2": "^0.3.6", | ||
| "typescript": "^1.7.0" | ||
| }, | ||
| "scripts": { | ||
| "test": "./node_modules/.bin/gulp test" | ||
| }, | ||
| "author": "Microsoft Corp.", | ||
| "license": "Apache-2.0", | ||
| "engines": { | ||
| "node": ">=4.0.0" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this file used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gets rid of errors when viewing the generated JavaScript in VS Code.