1 | var cwd = process.cwd();
|
2 | var glob = require("glob");
|
3 | var path = require("path");
|
4 |
|
5 |
|
6 | function flatten(structure) {
|
7 | return [].concat.apply([], structure);
|
8 | }
|
9 |
|
10 | function expandGlob(file) {
|
11 | return glob.sync(file.pattern || file).map(function (filePath) {
|
12 | return filePath.replace(/\//g, path.sep);
|
13 | });
|
14 | };
|
15 |
|
16 | var createPattern = function(path) {
|
17 | return {pattern: path, included: true, served: true, watched: false};
|
18 | };
|
19 |
|
20 | var createServedPattern = function(path){
|
21 | return {pattern: path, included: false, served: true, watched: true};
|
22 | };
|
23 |
|
24 | var initJspm = function(files, basePath, jspm, client) {
|
25 |
|
26 |
|
27 | files.unshift(createServedPattern(basePath + '/jspm_packages/**/*'));
|
28 |
|
29 |
|
30 | files.unshift(createPattern(__dirname + '/src/adapter.js'));
|
31 | files.unshift(createPattern(cwd + '/config.js'));
|
32 | files.unshift(createPattern(cwd + '/jspm_packages/system@0.8.js'));
|
33 | files.unshift(createPattern(cwd + '/jspm_packages/es6-module-loader@0.8.js'));
|
34 |
|
35 |
|
36 |
|
37 | if(!jspm)
|
38 | jspm = {};
|
39 | if(!jspm.files)
|
40 | jspm.files = [];
|
41 | if(!client.jspm)
|
42 | client.jspm = {};
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | client.jspm.expandedFiles = flatten(jspm.files.map(function(file){
|
49 | files.push(createServedPattern(cwd + "/" + (file.pattern || file)));
|
50 | return expandGlob(file);
|
51 | }));
|
52 | };
|
53 |
|
54 | initJspm.$inject = ['config.files', 'config.basePath', 'config.jspm', 'config.client'];
|
55 |
|
56 | module.exports = {
|
57 | 'framework:jspm': ['factory', initJspm]
|
58 | };
|