Created
July 7, 2015 12:34
-
-
Save Munter/9ac0b8a29252fc290604 to your computer and use it in GitHub Desktop.
Small script to automatically verify that a jspm package has been correctly installed and configured
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jspm = require('../package.json').jspm; | |
var jsdom = require('jsdom'); | |
var async = require('async'); | |
var chalk = require('chalk'); | |
var express = require('express'); | |
var app = express(); | |
app | |
.get('*.html', function (req, res) { | |
res.end(''); | |
}) | |
.use(express.static(process.cwd())); | |
app.listen(9001, function () { | |
async.each(Object.keys(jspm.dependencies), function (moduleName, done) { | |
var dom = jsdom.env({ | |
url: 'http://localhost:9001/' + moduleName + '.html', | |
features: { | |
FetchExternalResources: ['script', 'img', 'css', 'frame', 'iframe', 'link'], | |
ProcessExternalResources: ['script'] | |
}, | |
scripts: [ | |
jspm.directories.packages + '/system.js' | |
], | |
done: function (errs, window) { | |
if (errs) { | |
console.error(window.location.href, errs); | |
} | |
setTimeout(function () { | |
var System = window.System; | |
System.import(jspm.configFile.replace('.js', '')) | |
.then(function () { | |
return System.import(moduleName) | |
}) | |
.then(function (module) { | |
console.log(chalk.green('LOADED'), moduleName); | |
}) | |
.catch(function (err) { | |
console.error(chalk.red('FAILED'), moduleName, err); | |
}) | |
.then(done); | |
}, 300); | |
} | |
}); | |
}, process.exit); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment