Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

Factoring out of proto-Baretta project.
  • Loading branch information...
commit 0b4758e1bc7a941dab76aed9b02309316f2ede2f 0 parents
@domenic domenic authored
2  .gitignore
@@ -0,0 +1,2 @@
+node_modules/
+npm-debug.log
4 README.md
@@ -0,0 +1,4 @@
+This is just the beginning. Lots more to come.
+
+How would you use a CommonJS-style module with Windows 8 and WinJS? I'm glad you asked. There's another project for
+that.
12 git_hooks/commit-msg
@@ -0,0 +1,12 @@
+#!/usr/bin/env node
+
+var fs = require("fs");
+
+var fileContents = fs.readFileSync(process.argv[2]).toString();
+
+var lines = fileContents.split("\n");
+
+if (lines[0].length > 65) {
+ console.error("First line of commit message should be at most 50 characters in length.");
+ process.exit(1);
+}
17 git_hooks/link.js
@@ -0,0 +1,17 @@
+var fs = require("fs");
+var path = require("path");
+
+["applypatch-msg", "commit-msg", "post-commit", "post-receive", "post-update", "pre-applypatch", "pre-commit",
+ "prepare-commit-msg", "pre-rebase", "update"].forEach(function (hook) {
+ var hookInSourceControl = path.resolve(__dirname, hook);
+
+ if (path.existsSync(hookInSourceControl)) {
+ var hookInHiddenDirectory = path.resolve(__dirname, "..", ".git", "hooks", hook);
+
+ if (path.existsSync(hookInHiddenDirectory)) {
+ fs.unlinkSync(hookInHiddenDirectory);
+ }
+
+ fs.linkSync(hookInSourceControl, hookInHiddenDirectory);
+ }
+});
21 git_hooks/pre-commit
@@ -0,0 +1,21 @@
+#!/usr/bin/env node
+
+var npm = require("npm");
+
+npm.load(function (err) {
+ if (err) {
+ throw err;
+ }
+
+ npm.commands.test(function (err) {
+ if (err) {
+ process.exit(1);
+ }
+
+ npm.commands["run-script"](["lint"], function (err) {
+ if (err) {
+ process.exit(1);
+ }
+ });
+ });
+});
24 lib/app.js
@@ -0,0 +1,24 @@
+"use strict";
+
+var makeEmitter = require("pubit").makeEmitter;
+
+var publish = makeEmitter(exports, { events: ["launch", "reactivate", "beforeSuspend"] });
+
+WinJS.Application.onactivated = function (eventObject) {
+ if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
+ if (eventObject.detail.previousExecutionState !==
+ Windows.ApplicationModel.Activation.ApplicationExecutionState.terminated) {
+ publish("launch", eventObject);
+ } else {
+ publish("reactivate", eventObject);
+ }
+
+ WinJS.UI.processAll();
+ }
+};
+
+WinJS.Application.oncheckpoint = function (eventObject) {
+ publish("beforeSuspend", eventObject);
+};
+
+WinJS.Application.start();
40 package.json
@@ -0,0 +1,40 @@
+{
+ "name": "WinningJS",
+ "description": "A set of modules for Windows 8 development, built on top of WinJS.",
+ "private": true,
+ "version": "0.0.0",
+ "author": "NobleJS",
+ "contributors": [
+ "Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com)"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/NobleJS/WinningJS"
+ },
+ "bugs": {
+ "url": "http://github.com/NobleJS/WinningJS/issues"
+ },
+ "directories": {
+ "lib": "./lib"
+ },
+ "scripts": {
+ "test": "mocha",
+ "lint": "jshint lib --show-non-errors"
+ },
+ "dependencies": {
+ "pubit": "*"
+ },
+ "devDependencies": {
+ "mocha": ">= 1.0.3",
+ "chai": ">= 1.0.1",
+ "sinon": ">= 1.3.3",
+ "sinon-chai": ">= 2.0.1",
+ "sandboxed-module": ">= 0.1.3",
+ "jshint": "*",
+ "npm": "*",
+ "coffee-script": ">= 1.3.3"
+ },
+ "engines": {
+ "node": "*"
+ }
+}
77 test/app.coffee
@@ -0,0 +1,77 @@
+"use strict"
+
+sandboxedModule = require("sandboxed-module")
+
+Windows =
+ ApplicationModel: Activation:
+ ActivationKind: launch: {}
+ ApplicationExecutionState: terminated: {}
+
+requireApp = (winJS = {}) ->
+ winJS.Application ?= { start: -> }
+ winJS.UI ?= { processAll: -> }
+
+ sandboxedModule.require("../lib/app", globals: { WinJS: winJS, Windows: Windows })
+
+describe "app", ->
+ it "should call `WinJS.Application.start()`", ->
+ stubWinJS = Application: start: sinon.spy()
+ requireApp(stubWinJS)
+
+ stubWinJS.Application.start.should.have.been.calledOnce
+
+ describe "when an 'activated' event is triggered with kind 'launch'", ->
+ beforeEach ->
+ @eventObject = detail: kind: Windows.ApplicationModel.Activation.ActivationKind.launch
+
+ it "should call `WinJS.UI.processAll()`", ->
+ stubWinJS = UI: processAll: sinon.spy()
+ app = requireApp(stubWinJS)
+
+ stubWinJS.Application.onactivated(@eventObject)
+
+ stubWinJS.UI.processAll.should.have.been.calledOnce
+
+ describe "when the previous execution state is not 'terminated'", ->
+ beforeEach ->
+ @eventObject.detail.previousExecutionState = {}
+
+ it "should publish a 'launch' event", ->
+ stubWinJS = {}
+ app = requireApp(stubWinJS)
+
+ spy = sinon.spy()
+ app.on("launch", spy)
+
+ stubWinJS.Application.onactivated(@eventObject)
+
+ spy.should.have.been.calledWith(@eventObject)
+
+ describe "when the previous execution state is 'terminated'", ->
+ beforeEach ->
+ @eventObject.detail.previousExecutionState =
+ Windows.ApplicationModel.Activation.ApplicationExecutionState.terminated
+
+ it "should publish a 'reactivate' event", ->
+ stubWinJS = {}
+ app = requireApp(stubWinJS)
+
+ spy = sinon.spy()
+ app.on("reactivate", spy)
+
+ stubWinJS.Application.onactivated(@eventObject)
+
+ spy.should.have.been.calledWith(@eventObject)
+
+ describe "when the 'checkpoint' event is triggered", ->
+ it "should publish a 'beforeSuspend' event", ->
+ stubWinJS = {}
+ app = requireApp(stubWinJS)
+
+ spy = sinon.spy()
+ app.on("beforeSuspend", spy)
+
+ eventObject = {}
+ stubWinJS.Application.oncheckpoint(eventObject)
+
+ spy.should.have.been.calledWith(eventObject)
3  test/mocha.opts
@@ -0,0 +1,3 @@
+--reporter dot
+--require test/support/setup
+--compilers coffee:coffee-script
7 test/support/setup.js
@@ -0,0 +1,7 @@
+var chai = require("chai");
+var sinonChai = require("sinon-chai");
+
+chai.use(sinonChai);
+chai.should();
+
+global.sinon = require("sinon");
Please sign in to comment.
Something went wrong with that request. Please try again.