Skip to content

Instantly share code, notes, and snippets.

@aaronpowell
Created December 4, 2012 12:16
Show Gist options
  • Select an option

  • Save aaronpowell/4203212 to your computer and use it in GitHub Desktop.

Select an option

Save aaronpowell/4203212 to your computer and use it in GitHub Desktop.
Convert WinJS APIs into CommonJS modules
define('my-app', function (require) {
var app = require('WinJS/Application');
app.onactivated = function (args) {
//activation stuff
};
app.start();
});
(function (global) {
var walker = function (k, t, o) {
if(!t) {
t = k;
} else {
t = t + k + '/';
}
if(typeof o !== 'object') {
if(t) {
require.define(t.substring(0, t.length - 1), function (r, m, e) {
m.exports = o;
});
}
return;
}
var keys = Object.keys(o).filter(function (x) {
return /[A-Z]/.test(x.charAt(0));
});
for(var i = 0; i < keys.length; i += 1) {
walker(keys[i], t, o[keys[i]]);
}
require.define(t.substring(0, t.length - 1), function (r, m, e) {
m.exports = o;
});
};
walker('', 'WinJS', global.WinJS);
walker('', 'Windows', global.Windows);
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment