1 | 'use strict';
|
2 |
|
3 | var debug = require('debug')('serve-spm:rules');
|
4 | var join = require('path').join;
|
5 | var relative = require('path').relative;
|
6 | var util = require('./util');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | module.exports = [
|
18 |
|
19 |
|
20 | function(url, pkg) {
|
21 | if (/\/$/.test(url.pathname)) {
|
22 | debug('matching %s -> %s', url.pathname, 'index.html');
|
23 | return {
|
24 | path: join(pkg.dest, url.pathname, 'index.html')
|
25 | };
|
26 | }
|
27 | },
|
28 |
|
29 |
|
30 | function(url, pkg) {
|
31 | if (/\/$/.test(url.pathname)) {
|
32 | debug('matching %s -> %s', url.pathname, 'index.htm');
|
33 | return {
|
34 | path: join(pkg.dest, url.pathname, 'index.htm')
|
35 | };
|
36 | }
|
37 | },
|
38 |
|
39 |
|
40 |
|
41 | function(url, pkg) {
|
42 | return {
|
43 | path: join(pkg.dest, url.pathname)
|
44 | };
|
45 | },
|
46 |
|
47 |
|
48 | function(url, pkg) {
|
49 | var pathname = url.pathname;
|
50 | var prefix = '/dist/' + pkg.name + '/' + pkg.version;
|
51 | if (pathname.indexOf(prefix) === 0) {
|
52 | pathname = pathname.replace(prefix, '');
|
53 | debug('matching %s -> %s', url.pathname, pathname);
|
54 | return {
|
55 | path: join(pkg.dest, pathname)
|
56 | };
|
57 | }
|
58 | },
|
59 |
|
60 |
|
61 | function(url, pkg, rootPkg) {
|
62 | var pathname = join('dist', url.pathname);
|
63 | debug('matching %s -> %s', url.pathname, pathname);
|
64 | return {
|
65 | wrap: false,
|
66 | path: join(rootPkg.dest, pathname)
|
67 | };
|
68 | },
|
69 |
|
70 |
|
71 | function(url, pkg) {
|
72 | var matched = util.matchNameVersion(url.pathname);
|
73 | if (matched && matched.name === pkg.name && matched.version === pkg.version) {
|
74 | debug('matching %s -> %s', url.pathname, matched.file);
|
75 | return {
|
76 | path: join(pkg.dest, matched.file)
|
77 | };
|
78 | }
|
79 | },
|
80 |
|
81 |
|
82 | function(url, pkg) {
|
83 | var matched = util.matchNameVersion(url.pathname);
|
84 | if (!matched) return;
|
85 |
|
86 | var sub = pkg.getPackage(matched.name + '@' + matched.version);
|
87 | if (sub) {
|
88 | debug('matching %s -> %s', join(relative(pkg.dest ,sub.dest), matched.file));
|
89 | return {
|
90 | path: join(sub.dest, matched.file)
|
91 | };
|
92 | }
|
93 | }
|
94 | ];
|