Skip to content

Commit

Permalink
Merge upstream master
Browse files Browse the repository at this point in the history
  • Loading branch information
efokschaner committed Jul 19, 2017
2 parents 7936662 + fbaef58 commit 33f776a
Show file tree
Hide file tree
Showing 16 changed files with 366 additions and 581 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ This is a TypeScript implementation of the [Cap'n Proto](https://capnproto.org)
- [Usage with JavaScript](#usage-with-javascript)
- [Usage in a Web Browser](#usage-in-a-web-browser)
- [Building](#building)
- [Initial Setup](#initial-setup)
- [Build Tasks](#build-tasks)
- [Testing](#testing)
- [Team](#team)
Expand Down Expand Up @@ -81,8 +82,6 @@ npm install -g capnpc-js # For JavaScript

The schema compiler is a [Cap'n Proto plugin](https://capnproto.org/otherlang.html#how-to-write-compiler-plugins) and requires the `capnpc` binary in order to do anything useful; follow the [Cap'n Proto installation instructions](https://capnproto.org/install.html) to install it on your system.

> NOTE: At some point in the future the `capnpc-ts` package may build the `capnpc` binary as a native dependency, making this step somewhat unnecessary.
## Usage

Run the following to compile a schema file into TypeScript source code:
Expand Down Expand Up @@ -151,7 +150,9 @@ Before building the source you will need a few prerequisites:

> [nvm](https://github.com/creationix/nvm) is highly recommended for managing multiple nodejs versions.
Run `yarn install` to install the initial set of build packages before continuing.
### Initial Setup

Run `yarn install` to set up the **node_modules** directories for the monorepo and each package.

### Build Tasks

Expand Down
10 changes: 10 additions & 0 deletions configs/capnp-ts/tsconfig-lib-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"outDir": "../../packages/capnp-ts/lib-test",
"rootDir": "../../packages/capnp-ts/test"
},
"extends": "../tsconfig-base",
"include": [
"../../packages/capnp-ts/test/**/*.ts"
]
}
11 changes: 11 additions & 0 deletions configs/capnp-ts/tsconfig-lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"declaration": true,
"outDir": "../../packages/capnp-ts/lib",
"rootDir": "../../packages/capnp-ts/src"
},
"extends": "../tsconfig-base",
"include": [
"../../packages/capnp-ts/src/**/*.ts"
]
}
10 changes: 10 additions & 0 deletions configs/capnpc-js/tsconfig-lib-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"outDir": "../../packages/capnpc-js/lib-test",
"rootDir": "../../packages/capnpc-js/test"
},
"extends": "../tsconfig-base",
"include": [
"../../packages/capnpc-js/test/**/*.ts"
]
}
11 changes: 11 additions & 0 deletions configs/capnpc-js/tsconfig-lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"declaration": true,
"outDir": "../../packages/capnpc-js/lib",
"rootDir": "../../packages/capnpc-js/src"
},
"extends": "../tsconfig-base",
"include": [
"../../packages/capnpc-js/src/**/*.ts"
]
}
10 changes: 10 additions & 0 deletions configs/capnpc-ts/tsconfig-lib-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"outDir": "../../packages/capnpc-ts/lib-test",
"rootDir": "../../packages/capnpc-ts/test"
},
"extends": "../tsconfig-base",
"include": [
"../../packages/capnpc-ts/test/**/*.ts"
]
}
11 changes: 11 additions & 0 deletions configs/capnpc-ts/tsconfig-lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"declaration": true,
"outDir": "../../packages/capnpc-ts/lib",
"rootDir": "../../packages/capnpc-ts/src"
},
"extends": "../tsconfig-base",
"include": [
"../../packages/capnpc-ts/src/**/*.ts"
]
}
1 change: 1 addition & 0 deletions configs/tsconfig-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"pretty": true,
"sourceMap": true,
"strict": true,
"stripInternal": true,
"target": "es5"
Expand Down
159 changes: 63 additions & 96 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,134 +3,101 @@
*/

var gulp = require('gulp');
var gutil = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var ts = require('gulp-typescript');
var tslint = require('gulp-tslint');
var glob = require('glob');
var realTslint = require('tslint');
var spawnSync = require('child_process').spawnSync;

function build(src, dest) {
var tsProject = ts.createProject('configs/tsconfig-base.json', { declaration: true });
return gulp.src(src)
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dest));
function build(projectConfig) {
var result = spawnSync('./node_modules/.bin/tsc', ['-p', projectConfig], { stdio: 'inherit' });
if (result.status !== 0) {
throw new Error('Process exited with non-zero status: ' + result.status);
}
}

gulp.task('build:capnp-ts', function () {
return build('./packages/capnp-ts/src/**/*.ts', 'packages/capnp-ts/lib');
/** Build the main capnp-ts library. */
gulp.task('build:capnp-ts:lib', function () {
return build('configs/capnp-ts/tsconfig-lib.json');
});

gulp.task('build:capnpc-ts', ['build:capnp-ts'], function () {
return build('./packages/capnpc-ts/src/**/*.ts', 'packages/capnpc-ts/lib');
/** Build the capnpc-ts schema compiler. */
gulp.task('build:capnpc-ts:lib', ['build:capnp-ts:lib'], function () {
return build('configs/capnpc-ts/tsconfig-lib.json');
});

gulp.task('build:capnpc-js', ['build:capnpc-ts'], function () {
return build('./packages/capnpc-js/src/**/*.ts', 'packages/capnpc-js/lib');
/** Build the capnpc-js schema compiler. */
gulp.task('build:capnpc-js:lib', ['build:capnp-ts:lib', 'build:capnpc-ts:lib'], function () {
return build('configs/capnpc-js/tsconfig-lib.json');
});

gulp.task('build', ['build:capnp-ts', 'build:capnpc-ts', 'build:capnpc-js']);

function test(src, dest, coverage) {
var tsProject = ts.createProject('configs/tsconfig-base.json');
return gulp.src(src)
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dest))
.pipe(gutil.buffer(function (err, files) {
var options = ['-J'];
if (coverage) {
options.push('--cov', '--nyc-arg=-x=**/lib-test/**/*');
}
var result = spawnSync('./node_modules/.bin/tap', options.concat(files.map(function (file) {
return file.path;
}).filter(function (path) {
// This filters not only unrelated files, but also sourcemaps
return path.endsWith('.spec.js');
})), { stdio: 'inherit' });
if (result.status != 0) {
throw new Error('Process exited with non-zero status: ' + result.status);
}
}));
}

gulp.task('test:capnp-ts', ['build:capnp-ts'], function () {
return test(
'./packages/capnp-ts/test/**/*.ts',
'packages/capnp-ts/lib-test',
false
);
/** Build tests for capnp-ts. */
gulp.task('build:capnp-ts:test', ['build:capnp-ts:lib'], function () {
return build('configs/capnp-ts/tsconfig-lib-test.json');
});

gulp.task('test:capnpc-ts', ['build:capnpc-ts'], function () {
return test(
'./packages/capnpc-ts/test/**/*.ts',
'packages/capnpc-ts/lib-test',
false
);
/** Build tests for capnpc-ts. */
gulp.task('build:capnpc-ts:test', ['build:capnpc-ts:lib'], function () {
return build('configs/capnpc-ts/tsconfig-lib-test.json');
});

gulp.task('test:capnpc-js', ['build:capnpc-js'], function () {
return test(
'./packages/capnpc-js/test/**/*.ts',
'packages/capnpc-js/lib-test',
false
);
/** Build tests for capnpc-js. */
gulp.task('build:capnpc-js:test', ['build:capnpc-js:lib'], function () {
return build('configs/capnpc-js/tsconfig-lib-test.json');
});

gulp.task('test', ['test:capnp-ts', 'test:capnpc-ts', 'test:capnpc-js']);
/** Main build task (does not build tests). */
gulp.task('build', ['build:capnp-ts:lib', 'build:capnpc-ts:lib', 'build:capnpc-js:lib']);

/** Build all tests. */
gulp.task('build-test', ['build:capnp-ts:test', 'build:capnpc-ts:test', 'build:capnpc-js:test']);

function test(src, coverage) {
var options = glob.sync(src).concat('-J');
if (coverage) {
options.push('--cov', '--nyc-arg=-x=**/lib-test/**/*');
}
var result = spawnSync('./node_modules/.bin/tap', options, { stdio: 'inherit' });
if (result.status !== 0) {
throw new Error('Process exited with non-zero status: ' + result.status);
}
}

gulp.task('test-cov:capnp-ts', ['build:capnp-ts'], function () {
return test(
'./packages/capnp-ts/test/**/*.ts',
'packages/capnp-ts/lib-test',
true
);
/** Run tests for the main capnp-ts library. */
gulp.task('test:capnp-ts', ['build:capnp-ts:test'], function () {
return test('packages/capnp-ts/lib-test/**/*.spec.js', false);
});

gulp.task('test-cov:capnpc-ts', ['build:capnpc-ts'], function () {
return test(
'./packages/capnpc-ts/test/**/*.ts',
'packages/capnpc-ts/lib-test',
true
);
/** Run tests for the capnpc-ts schema compiler. */
gulp.task('test:capnpc-ts', ['build:capnpc-ts:test'], function () {
return test('packages/capnpc-ts/lib-test/**/*.spec.js', false);
});

gulp.task('test-cov:capnpc-js', ['build:capnpc-js'], function () {
return test(
'./packages/capnpc-js/test/**/*.ts',
'packages/capnpc-js/lib-test',
true
);
/** Run tests for the capnpc-js schema compiler. */
gulp.task('test:capnpc-js', ['build:capnpc-js:test'], function () {
return test('packages/capnpc-js/lib-test/**/*.spec.js', false);
});

gulp.task('test-cov', ['test-cov:capnp-ts', 'test-cov:capnpc-ts', 'test-cov:capnpc-js']);
/** Run all tests. */
gulp.task('test', ['test:capnp-ts', 'test:capnpc-ts', 'test:capnpc-ts']);

/** Run all tests with test coverage. */
gulp.task('test-cov', ['build:capnp-ts:test', 'build:capnpc-ts:test', 'build:capnpc-js:test'], function () {
return test('packages/*/lib-test/**/*.spec.js', true);
});

/** Run all tests and generate a coverage report. */
gulp.task('coverage', ['test-cov'], function () {
var result = spawnSync('./node_modules/.bin/tap', ['--coverage-report=lcov'], { stdio: 'inherit' });
if (result.status != 0) {
if (result.status !== 0) {
throw new Error('Process exited with non-zero status: ' + result.status);
}
});

gulp.task('benchmark:capnp-ts', function () {
var tsProject = ts.createProject('configs/tsconfig-base.json');
return gulp.src('./packages/capnp-ts/test/benchmark/**/*.ts')
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('packages/capnp-ts/lib-test'))
.on('finish', function () {
var result = spawnSync(process.execPath,
['packages/capnp-ts/lib-test/benchmark/index.js'],
{ stdio: 'inherit' });
if (result.status != 0) {
throw new Error('Process exited with non-zero status: ' + result.status);
}
});
gulp.task('benchmark:capnp-ts', ['build:capnp-ts:test'], function () {
var result = spawnSync(process.execPath, ['packages/capnp-ts/lib-test/benchmark/index.js'], { stdio: 'inherit' });
if (result.status != 0) {
throw new Error('Process exited with non-zero status: ' + result.status);
}
});

gulp.task('benchmark', ['benchmark:capnp-ts']);
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
"description": "Strongly typed Cap'n Proto implementation for the browser and Node.js using TypeScript",
"devDependencies": {
"codecov": "^2.2.0",
"glob": "^7.1.2",
"gulp": "^3.9.1",
"gulp-sourcemap": "^1.0.1",
"gulp-sourcemaps": "^2.6.0",
"gulp-tslint": "^8.1.1",
"gulp-typescript": "^3.2.0",
"gulp-util": "^3.0.8",
"lerna": "^2.0.0",
"tap": "^10.7.0",
"ts-node": "^3.2.0",
Expand Down Expand Up @@ -48,5 +45,6 @@
},
"typings": "lib/index",
"version": "0.0.1",
"dependencies": {}
"dependencies": {
}
}
Loading

0 comments on commit 33f776a

Please sign in to comment.