@@ -7,28 +7,7 @@ var delPromise = Q.denodeify(del);
7
7
var Dgeni = require ( 'dgeni' ) ;
8
8
var _ = require ( 'lodash' ) ;
9
9
10
- var resolveShredOptions = function ( shredOptions ) {
11
- return _ . defaults ( { } , shredOptions , {
12
- basePath : path . resolve ( '.' ) ,
13
- // read files from any subdir under here
14
- sourceDir : "docs/_examples" ,
15
- // shredded files get copied here with same subdir structure.
16
- destDir : "docs/_fragments" ,
17
- // whether to include subdirectories when shredding.
18
- includeSubdirs : true
19
- } ) ;
20
- }
21
10
22
- var resolveMapOptions = function ( mapOptions ) {
23
- return _ . defaults ( { } , mapOptions , {
24
- basePath : path . resolve ( '.' ) ,
25
- // read files from any subdir under here
26
- sourceDir : "docs" ,
27
- destDir : "docs" ,
28
- // whether to include subdirectories when shredding.
29
- includeSubdirs : true
30
- } ) ;
31
- }
32
11
33
12
var shred = function ( shredOptions ) {
34
13
try {
@@ -42,26 +21,26 @@ var shred = function(shredOptions) {
42
21
}
43
22
44
23
var shredSingleDir = function ( shredOptions , filePath ) {
45
- shredOptions = resolveOptions ( shredOptions ) ;
46
- var root = path . resolve ( shredOptions . basePath , shredOptions . sourceDir ) ;
24
+ shredOptions = resolveShredOptions ( shredOptions ) ;
25
+ var root = path . resolve ( shredOptions . basePath , shredOptions . examplesDir ) ;
47
26
var fileDir = path . dirname ( filePath ) ;
48
27
var relativePath = path . relative ( root , fileDir ) ;
49
- var sourceDir = path . join ( shredOptions . sourceDir , relativePath ) ;
50
- var destDir = path . join ( shredOptions . destDir , relativePath ) ;
28
+ var examplesDir = path . join ( shredOptions . examplesDir , relativePath ) ;
29
+ var fragmentsDir = path . join ( shredOptions . fragmentsDir , relativePath ) ;
51
30
var options = {
52
31
basePath : shredOptions . basePath ,
53
32
includeSubdirs : false ,
54
- sourceDir : sourceDir ,
55
- destDir : destDir
33
+ examplesDir : examplesDir ,
34
+ fragmentsDir : fragmentsDir
56
35
}
57
- var cleanPath = path . join ( shredOptions . basePath , destDir , '*.*' )
36
+ var cleanPath = path . join ( shredOptions . basePath , fragmentsDir , '*.*' )
58
37
return delPromise ( [ cleanPath , '!**/*.ovr.*' ] ) . then ( function ( paths ) {
59
38
// console.log('Deleted files/folders:\n', paths.join('\n'));
60
39
return shred ( options ) ;
61
40
} ) ;
62
41
}
63
42
64
- var getShredMap = function ( shredMapOptions ) {
43
+ var buildShredMap = function ( shredMapOptions ) {
65
44
try {
66
45
var pkg = createShredMapPackage ( shredMapOptions ) ;
67
46
var dgeni = new Dgeni ( [ pkg ] ) ;
@@ -73,11 +52,11 @@ var getShredMap = function(shredMapOptions) {
73
52
}
74
53
75
54
55
+
76
56
module . exports = {
77
57
shred : shred ,
78
58
shredSingleDir : shredSingleDir ,
79
- resolveShredOptions : resolveShredOptions ,
80
- getShredMap : getShredMap
59
+ buildShredMap : buildShredMap
81
60
} ;
82
61
83
62
function createShredPackage ( shredOptions ) {
@@ -103,28 +82,28 @@ function createShredPackage(shredOptions) {
103
82
var extns = [ '*.js' , '*.html' , '*.ts' , '*.css' ] ;
104
83
var includeFiles = extns . map ( function ( extn ) {
105
84
if ( options . includeSubdirs ) {
106
- return path . join ( options . sourceDir , '**' , extn ) ;
85
+ return path . join ( options . examplesDir , '**' , extn ) ;
107
86
} else {
108
- return path . join ( options . sourceDir , extn ) ;
87
+ return path . join ( options . examplesDir , extn ) ;
109
88
}
110
89
} ) ;
111
90
readFilesProcessor . sourceFiles = [ {
112
91
// Process all candidate files in `src` and its subfolders ...
113
92
include : includeFiles ,
114
93
// When calculating the relative path to these files use this as the base path.
115
94
// So `src/foo/bar.js` will have relative path of `foo/bar.js`
116
- basePath : options . sourceDir
95
+ basePath : options . examplesDir
117
96
} ] ;
118
97
} )
119
98
. config ( function ( writeFilesProcessor ) {
120
99
// Specify where the writeFilesProcessor will write our generated doc files
121
- writeFilesProcessor . outputFolder = options . destDir ;
100
+ writeFilesProcessor . outputFolder = options . fragmentsDir ;
122
101
} ) ;
123
102
return pkg ;
124
103
}
125
104
126
105
var createShredMapPackage = function ( mapOptions ) {
127
- var pkg = new Dgeni . Package ( 'docshred -mapper' , [
106
+ var pkg = new Dgeni . Package ( 'doc-shred -mapper' , [
128
107
require ( 'dgeni-packages/base' ) ,
129
108
require ( 'dgeni-packages/nunjucks' )
130
109
] ) ;
@@ -133,7 +112,9 @@ var createShredMapPackage = function(mapOptions) {
133
112
initializePackage ( pkg )
134
113
. factory ( require ( './extractPathsReader' ) )
135
114
. processor ( require ( './shredMapProcessor' ) )
136
-
115
+ . config ( function ( shredMapProcessor ) {
116
+ shredMapProcessor . options = options ;
117
+ } )
137
118
. config ( function ( readFilesProcessor , extractPathsReader ) {
138
119
readFilesProcessor . fileReaders = [ extractPathsReader ] ;
139
120
} )
@@ -146,25 +127,25 @@ var createShredMapPackage = function(mapOptions) {
146
127
var extns = [ '*.jade' ] ;
147
128
var includeFiles = extns . map ( function ( extn ) {
148
129
if ( options . includeSubdirs ) {
149
- return path . join ( options . sourceDir , '**' , extn ) ;
130
+ return path . join ( options . jadeDir , '**' , extn ) ;
150
131
} else {
151
- return path . join ( options . sourceDir , extn ) ;
132
+ return path . join ( options . jadeDir , extn ) ;
152
133
}
153
134
} ) ;
154
135
readFilesProcessor . sourceFiles = [ {
155
136
// Process all candidate files in `src` and its subfolders ...
156
137
include : includeFiles ,
157
138
// When calculating the relative path to these files use this as the base path.
158
139
// So `src/foo/bar.js` will have relative path of `foo/bar.js`
159
- basePath : options . sourceDir
140
+ basePath : options . jadeDir
160
141
} ] ;
161
142
} )
162
143
. config ( function ( writeFilesProcessor ) {
163
144
// Specify where the writeFilesProcessor will write our generated doc files
164
- writeFilesProcessor . outputFolder = options . destDir ;
145
+ writeFilesProcessor . outputFolder = options . outputDir ;
165
146
} )
166
147
. config ( function ( templateFinder ) {
167
- // Add a folder to search for our own templates to use when rendering docs
148
+ // look for templates in this folder
168
149
templateFinder . templateFolders = [ path . resolve ( __dirname ) ] ;
169
150
170
151
// Specify how to match docs to templates.
@@ -174,6 +155,7 @@ var createShredMapPackage = function(mapOptions) {
174
155
. config ( function ( computePathsProcessor , computeIdsProcessor ) {
175
156
computePathsProcessor . $enabled = false ;
176
157
computeIdsProcessor . $enabled = false ;
158
+ // Unused for now.
177
159
//computePathsProcessor.pathTemplates.push({
178
160
// docTypes: ['foo'],
179
161
// pathTemplate: '',
@@ -192,6 +174,30 @@ var createShredMapPackage = function(mapOptions) {
192
174
return pkg ;
193
175
}
194
176
177
+ function resolveShredOptions ( shredOptions ) {
178
+ return _ . defaults ( { } , shredOptions , {
179
+ basePath : path . resolve ( '.' ) ,
180
+ // read files from any subdir under here
181
+ examplesDir : "docs/_examples" ,
182
+ // shredded files get copied here with same subdir structure.
183
+ fragmentsDir : "docs/_fragments" ,
184
+ // whether to include subdirectories when shredding.
185
+ includeSubdirs : true
186
+ } ) ;
187
+ }
188
+
189
+ function resolveMapOptions ( mapOptions ) {
190
+ return _ . defaults ( { } , mapOptions , {
191
+ basePath : path . resolve ( '.' ) ,
192
+ // read files from any subdir under here
193
+ jadeDir : "docs" ,
194
+ fragmentsDir : "docs/_fragments" ,
195
+ examplesDir : "docs/_examples" ,
196
+ // whether to include subdirectories when shredding.
197
+ includeSubdirs : true
198
+ } ) ;
199
+ }
200
+
195
201
function initializePackage ( pkg ) {
196
202
return pkg
197
203
. processor ( require ( 'dgeni-packages/base/processors/read-files' ) )
0 commit comments