Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Build with TypeScript #1657

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ jspm_packages
# pump.io stuff

public/template/*.jade.js
dist/
3 changes: 3 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ Some quick documentation for hackery of pump.io.
* 4-character indent, spaces only (no tabs).
* double-quotes for strings.
* No internal space for parentheses; so "if (foo)", not "if ( foo )".
* Use [TypeScript](http://www.typescriptlang.org/).
* Use [Step](https://github.com/creationix/step).
* Use [Lodash](https://lodash.com/).
* Use [databank](https://github.com/evanp/databank). Don't write to some storage engine's API.
* Use [vows](http://vowsjs.org/).

TypeScript is built with `npm run build`.

You can check for (most) style violations with `npm run lint:jscs`, and you can check for JSHint errors with `npm run lint:jshint`.

## TEMPLATES
Expand Down
10 changes: 5 additions & 5 deletions bin/pump
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ var cluster = require("cluster"),
Logger = require("bunyan"),
_ = require("lodash"),
importFresh = require("import-fresh"),
configUtil = require("../lib/config"),
restartEpoch = require("../lib/zerodowntime"),
configUtil = require("../dist/lib/config"),
restartEpoch = require("../dist/lib/zerodowntime"),
restartInflight = false,
abortedRestart = false,
restartedWorker = null,
Expand Down Expand Up @@ -84,8 +84,8 @@ var cluster = require("cluster"),
.alias("version", "v")
.version()
.argv,
Dispatch = require("../lib/dispatch"),
makeApp = require("../lib/app").makeApp;
Dispatch = require("../dist/lib/dispatch"),
makeApp = require("../dist/lib/app").makeApp;

// We first get config files and launch some cluster apps

Expand Down Expand Up @@ -171,7 +171,7 @@ var launchApps = function(configBase) {

clusterLog.debug("Determining zero-downtime restart eligibility...");

var newEpoch = importFresh("../lib/zerodowntime");
var newEpoch = importFresh("../dist/lib/zerodowntime");
if (newEpoch !== restartEpoch) {
clusterLog.warn("Refusing zero-downtime restart because the new version says it's incompatible with us.");
return;
Expand Down
2 changes: 1 addition & 1 deletion bin/pump-authorize
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
var urlfmt = require("url").format,
_ = require("lodash"),
Step = require("step"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
clientCred = common.clientCred,
setUserCred = common.setUserCred,
OAuth = require("oauth-evanp").OAuth,
Expand Down
2 changes: 1 addition & 1 deletion bin/pump-create-group
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var _ = require("lodash"),
Step = require("step"),
url = require("url"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
userCred = common.userCred,
postJSON = common.postJSON,
argv = require("optimist")
Expand Down
2 changes: 1 addition & 1 deletion bin/pump-delete
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var _ = require("lodash"),
Step = require("step"),
url = require("url"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
userCred = common.userCred,
postJSON = common.postJSON,
delJSON = common.delJSON,
Expand Down
2 changes: 1 addition & 1 deletion bin/pump-follow
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var _ = require("lodash"),
Step = require("step"),
url = require("url"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
userCred = common.userCred,
postJSON = common.postJSON,
argv = require("optimist")
Expand Down
24 changes: 12 additions & 12 deletions bin/pump-import-collection
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ var fs = require("fs"),
databank = require("databank"),
Databank = databank.Databank,
DatabankObject = databank.DatabankObject,
randomString = require("../lib/randomstring").randomString,
IDMaker = require("../lib/idmaker").IDMaker,
Distributor = require("../lib/distributor").Distributor,
schema = require("../lib/schema").schema,
Activity = require("../lib/model/activity").Activity,
Stream = require("../lib/model/stream").Stream,
Person = require("../lib/model/person").Person,
Group = require("../lib/model/group").Group,
Collection = require("../lib/model/collection").Collection,
ActivityObject = require("../lib/model/activityobject").ActivityObject,
URLMaker = require("../lib/urlmaker").URLMaker,
User = require("../lib/model/user").User,
randomString = require("../dist/lib/randomstring").randomString,
IDMaker = require("../dist/lib/idmaker").IDMaker,
Distributor = require("../dist/lib/distributor").Distributor,
schema = require("../dist/lib/schema").schema,
Activity = require("../dist/lib/model/activity").Activity,
Stream = require("../dist/lib/model/stream").Stream,
Person = require("../dist/lib/model/person").Person,
Group = require("../dist/lib/model/group").Group,
Collection = require("../dist/lib/model/collection").Collection,
ActivityObject = require("../dist/lib/model/activityobject").ActivityObject,
URLMaker = require("../dist/lib/urlmaker").URLMaker,
User = require("../dist/lib/model/user").User,
argv = require("optimist")
.usage("Usage: $0 -f <collection file> or $0 -d <divided directory>")
.alias("f", "file")
Expand Down
16 changes: 8 additions & 8 deletions bin/pump-import-email
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ var fs = require("fs"),
databank = require("databank"),
Databank = databank.Databank,
DatabankObject = databank.DatabankObject,
randomString = require("../lib/randomstring").randomString,
Distributor = require("../lib/distributor").Distributor,
schema = require("../lib/schema").schema,
Activity = require("../lib/model/activity").Activity,
Stream = require("../lib/model/stream").Stream,
ActivityObject = require("../lib/model/activityobject").ActivityObject,
URLMaker = require("../lib/urlmaker").URLMaker,
User = require("../lib/model/user").User,
randomString = require("../dist/lib/randomstring").randomString,
Distributor = require("../dist/lib/distributor").Distributor,
schema = require("../dist/lib/schema").schema,
Activity = require("../dist/lib/model/activity").Activity,
Stream = require("../dist/lib/model/stream").Stream,
ActivityObject = require("../dist/lib/model/activityobject").ActivityObject,
URLMaker = require("../dist/lib/urlmaker").URLMaker,
User = require("../dist/lib/model/user").User,
argv = require("optimist")
.usage("Usage: $0 -f <email file>")
.demand(["f"])
Expand Down
2 changes: 1 addition & 1 deletion bin/pump-post-file
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var fs = require("fs"),
_ = require("lodash"),
Step = require("step"),
url = require("url"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
userCred = common.userCred,
postJSON = common.postJSON,
postData = common.postData,
Expand Down
2 changes: 1 addition & 1 deletion bin/pump-post-note
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var _ = require("lodash"),
Step = require("step"),
url = require("url"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
userCred = common.userCred,
postJSON = common.postJSON,
argv = require("optimist")
Expand Down
2 changes: 1 addition & 1 deletion bin/pump-register-app
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var _ = require("lodash"),
Step = require("step"),
url = require("url"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
postArgs = common.postArgs,
setClientCred = common.setClientCred;

Expand Down
2 changes: 1 addition & 1 deletion bin/pump-register-user
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
var _ = require("lodash"),
url = require("url"),
Step = require("step"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
clientCred = common.clientCred,
setUserCred = common.setUserCred,
postJSON = common.postJSON,
Expand Down
6 changes: 3 additions & 3 deletions bin/pump-set-password
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ var fs = require("fs"),
databank = require("databank"),
Databank = databank.Databank,
DatabankObject = databank.DatabankObject,
schema = require("../lib/schema").schema,
URLMaker = require("../lib/urlmaker").URLMaker,
User = require("../lib/model/user").User,
schema = require("../dist/lib/schema").schema,
URLMaker = require("../dist/lib/urlmaker").URLMaker,
User = require("../dist/lib/model/user").User,
argv = require("optimist")
.usage("Usage: $0 -u <user> -p <password>")
.demand(["u", "p"])
Expand Down
2 changes: 1 addition & 1 deletion bin/pump-show-group-inbox
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var fs = require("fs"),
_ = require("lodash"),
Step = require("step"),
url = require("url"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
userCred = common.userCred,
getJSON = common.getJSON,
argv = require("optimist")
Expand Down
2 changes: 1 addition & 1 deletion bin/pump-show-inbox
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var fs = require("fs"),
_ = require("lodash"),
Step = require("step"),
url = require("url"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
userCred = common.userCred,
getJSON = common.getJSON,
argv = require("optimist")
Expand Down
2 changes: 1 addition & 1 deletion bin/pump-show-outbox
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var fs = require("fs"),
_ = require("lodash"),
Step = require("step"),
url = require("url"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
userCred = common.userCred,
getJSON = common.getJSON,
argv = require("optimist")
Expand Down
2 changes: 1 addition & 1 deletion bin/pump-stop-following
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var _ = require("lodash"),
Step = require("step"),
url = require("url"),
common = require("../lib/pumpclient"),
common = require("../dist/lib/pumpclient"),
userCred = common.userCred,
postJSON = common.postJSON,
argv = require("optimist")
Expand Down
19 changes: 10 additions & 9 deletions lib/scrubber.js → lib/scrubber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@

"use strict";

var _ = require("lodash"),
jsdom = require("jsdom/lib/old-api.js"),
window = jsdom.jsdom("", {
import _ = require("lodash");
import jsdom = require("jsdom/lib/old-api.js");

var window = jsdom.jsdom("", {
features: {
FetchExternalResources: false,
ProcessExternalResources: false
}
}).defaultView,
DOMPurify = require("dompurify")(window);
}).defaultView;

import DOMPurifyInit = require("dompurify")

var DOMPurify = DOMPurifyInit(window);

var Scrubber = {
scrub: DOMPurify.sanitize,
Expand Down Expand Up @@ -124,8 +128,5 @@ var Scrubber = {
}
};

// So you can require("scrubber").Scrubber or just require("scrubber")

Scrubber.Scrubber = Scrubber;
export = Scrubber;

module.exports = Scrubber;
4 changes: 3 additions & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

"use strict";

module.exports.version = require("../package.json").version;
// Weird path because this ends up in dist/

module.exports.version = require("../../package.json").version;
5 changes: 5 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"sockjs": "0.3.x",
"ssl-config": "^1.0.0",
"step": "^1.0.0",
"typescript": "2.9.1",
"ua-parser-js": "^0.7.10",
"uuid": "^3.0.0",
"validator": "^10.0.0",
Expand All @@ -77,7 +78,7 @@
"./doc/pump.1"
],
"scripts": {
"build": "jade --client --extension jade.js --no-debug public/template/*.jade",
"build": "tsc && jade --client --extension jade.js --no-debug public/template/*.jade",
"fullbuild": "npm run build && echo 'use `npm run build` instead next time' 1>&2",
"test": "npm run lint && nyc -r lcov npm run test:vows",
"test:oauth2": "vows test/authenticationcode-test.js test/bearertoken-test.js test/oauth2-authorization-test.js test/schema-test.js test/authc-oauth2-test.js",
Expand Down
4 changes: 2 additions & 2 deletions test/accesstoken-unit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
var assert = require("assert"),
vows = require("vows"),
databank = require("databank"),
URLMaker = require("../lib/urlmaker").URLMaker,
URLMaker = require("../dist/lib/urlmaker").URLMaker,
modelBatch = require("./lib/model").modelBatch,
AccessToken = require("../lib/model/accesstoken").AccessToken,
AccessToken = require("../dist/lib/model/accesstoken").AccessToken,
Databank = databank.Databank,
DatabankObject = databank.DatabankObject;

Expand Down
2 changes: 1 addition & 1 deletion test/activity-api-e2e-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var assert = require("assert"),
Step = require("step"),
_ = require("lodash"),
http = require("http"),
version = require("../lib/version").version,
version = require("../dist/lib/version").version,
urlparse = require("url").parse,
httputil = require("./lib/http"),
oauthutil = require("./lib/oauth"),
Expand Down
14 changes: 7 additions & 7 deletions test/activity-content-unit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ var assert = require("assert"),
_ = require("lodash"),
fs = require("fs"),
path = require("path"),
URLMaker = require("../lib/urlmaker").URLMaker,
schema = require("../lib/schema").schema,
URLMaker = require("../dist/lib/urlmaker").URLMaker,
schema = require("../dist/lib/schema").schema,
modelBatch = require("./lib/model").modelBatch,
Databank = databank.Databank,
DatabankObject = databank.DatabankObject;
Expand All @@ -39,7 +39,7 @@ var contentCheck = function(actor, verb, object, expected) {
return {
topic: function(Activity) {
var callback = this.callback,
Collection = require("../lib/model/collection").Collection,
Collection = require("../dist/lib/model/collection").Collection,
thePublic = {
objectType: "collection",
id: Collection.PUBLIC
Expand Down Expand Up @@ -110,7 +110,7 @@ suite.addBatch({

DatabankObject.bank = db;

mod = require("../lib/model/activity");
mod = require("../dist/lib/model/activity");

if (!mod) {
cb(new Error("No module"), null);
Expand Down Expand Up @@ -180,7 +180,7 @@ suite.addBatch({
"Lorrie Tynan posted a comment in reply to an image"),
"and we create a person": {
topic: function(Activity) {
var Person = require("../lib/model/person").Person,
var Person = require("../dist/lib/model/person").Person,
callback = this.callback;
Person.create({id: "urn:uuid:3e2273f4-fec7-11e2-9db1-32b36b1a1850",
displayName: "Endicott Pettibone"},
Expand All @@ -202,7 +202,7 @@ suite.addBatch({
},
"and we create an image": {
topic: function(Activity) {
var Image = require("../lib/model/image").Image,
var Image = require("../dist/lib/model/image").Image,
callback = this.callback;
Image.create({id: "urn:uuid:1731d374-fec8-11e2-87ba-32b36b1a1850",
displayName: "John the Baptist"},
Expand All @@ -224,7 +224,7 @@ suite.addBatch({
},
"and we create an article": {
topic: function(Activity) {
var Article = require("../lib/model/article").Article,
var Article = require("../dist/lib/model/article").Article,
callback = this.callback;
Article.create({id: "urn:uuid:af6ecc82-fec8-11e2-ac18-32b36b1a1850",
displayName: "The End of History"},
Expand Down
Loading