Skip to content

Commit

Permalink
Trivial skeleton for TypeScript Express server project. (Polymer#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
aomarks committed May 5, 2017
1 parent 6b89d69 commit 1000354
Show file tree
Hide file tree
Showing 11 changed files with 1,644 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BasedOnStyle: Google
AlignAfterOpenBracket: AlwaysBreak
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BinPackArguments: false
BinPackParameters: false
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- "6"
- "node"
script:
- npm test
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
[![Build Status](https://travis-ci.org/Polymer/prpl-server-node.svg?branch=master)](https://travis-ci.org/Polymer/prpl-server-node)

# prpl-server-node

A Node implementation of the [PRPL](https://developers.google.com/web/fundamentals/performance/prpl-pattern/) pattern for serving Progressive Web Apps.

## Installation

```sh
$ yarn install prpl-server -g
```

## Usage

### From the command line

```sh
$ cd my-project/
$ prpl-server
```

### As a library

```js
const server = require('prpl-server').server()
server.listen(8080);
```

## Compiling from source

```sh
$ yarn run build # once
$ yarn run build:test # continuous
```

## Run tests

```sh
$ yarn run test # once
$ yarn run test:watch # continuous
```
3 changes: 3 additions & 0 deletions bin/prpl-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
'use strict';
require('../lib/cli.js')
30 changes: 28 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
{
"name": "prpl-server-node",
"name": "prpl-server",
"version": "0.1.0",
"description": "A Node implementation of the PRPL pattern for serving Progressive Web Apps",
"repository": "git+https://github.com/Polymer/prpl-server-node.git",
"main": "lib/server.js",
"bin": "bin/prpl-server",
"engines": {
"node": ">=6.0"
},
"author": "The Polymer Project Authors",
"license": "BSD-3-Clause"
"license": "BSD-3-Clause",
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"format": "find src -name '*.ts' | xargs clang-format --style=file -i",
"test": "npm run build && mocha",
"test:watch": "watchy -w src -- npm run test"
},
"devDependencies": {
"@types/chai": "^3.5.2",
"@types/mocha": "^2.2.41",
"chai": "^3.5.0",
"clang-format": "^1.0.50",
"mocha": "^3.3.0",
"source-map-support": "^0.4.15",
"typescript": "^2.3.2",
"watchy": "^0.6.7"
},
"dependencies": {
"@types/express": "^4.0.35",
"express": "^4.15.2"
}
}
17 changes: 17 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/

import {server} from './server';

server().listen(8080);
23 changes: 23 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/

import * as express from 'express';

export function server(): express.Express {
const app = express();
app.get('*', function(_req, res, _next) {
res.send('hello world');
});
return app;
}
23 changes: 23 additions & 0 deletions src/test/server_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/

import {assert} from 'chai';
import {server} from '../server';

suite('prpl server', function() {
test('is created', () => {
const app = server();
assert.isOk(app);
});
});
3 changes: 3 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--ui tdd
--require source-map-support/register
lib/test/**/*_test.js
21 changes: 21 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "es6",
"lib": [
"es2016"
],
"outDir": "lib",
"module": "commonjs",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"preserveConstEnums": true,
"sourceMap": true,
"pretty": true,
"declaration": true,
"skipLibCheck": true
},
"include": [
"src/**/*.ts"
]
}
Loading

0 comments on commit 1000354

Please sign in to comment.