Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,6 @@ FakesAssemblies/
# LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
ModelManifest.xml

node_modules/
3 changes: 3 additions & 0 deletions async/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib/
!src/lib/
.vscode/
27 changes: 27 additions & 0 deletions async/README.md
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") |
71 changes: 71 additions & 0 deletions async/gulpfile.js
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);
}
}
5 changes: 5 additions & 0 deletions async/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
Copy link
Contributor

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?

Copy link
Author

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.

"compilerOptions": {
"target": "ES6"
}
}
27 changes: 27 additions & 0 deletions async/package.json
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"
}
}
Loading