@@ -31,6 +31,7 @@ main(List arguments) {
31
31
print ('output: ${options .output }' );
32
32
print ('sdk-path: ${options .sdkPath }' );
33
33
print ('package-root: ${options .packageRoots .join ("," )}' );
34
+ print ('template-root: ${options .templateRoots .join ("," )}' );
34
35
var rewrites = options.urlRewrites.keys
35
36
.map ((k) => '${k .pattern },${options .urlRewrites [k ]}' )
36
37
.join (';' );
@@ -41,8 +42,8 @@ main(List arguments) {
41
42
Map <String , String > templates = {};
42
43
43
44
var c = new SourceCrawler (options.sdkPath, options.packageRoots);
44
- var visitor =
45
- new TemplateCollectingVisitor (templates , options.skippedClasses, c );
45
+ var visitor = new TemplateCollectingVisitor (templates, options.skippedClasses,
46
+ c , options.templateRoots );
46
47
c.crawl (options.entryPoint,
47
48
(CompilationUnitElement compilationUnit, SourceFile source) =>
48
49
visitor (compilationUnit, source.canonicalPath));
@@ -64,6 +65,7 @@ class Options {
64
65
String outputLibrary;
65
66
String sdkPath;
66
67
List <String > packageRoots;
68
+ List <String > templateRoots;
67
69
String output;
68
70
Map <RegExp , String > urlRewrites;
69
71
Set <String > skippedClasses;
@@ -77,6 +79,9 @@ Options parseArgs(List arguments) {
77
79
help: 'Dart SDK Path' )
78
80
..addOption ('package-root' , abbr: 'p' , defaultsTo: Platform .packageRoot,
79
81
help: 'comma-separated list of package roots' )
82
+ ..addOption ('template-root' , abbr: 't' , defaultsTo: '.' ,
83
+ help: 'comma-separated list of paths from which templates with'
84
+ 'absolute paths can be fetched' )
80
85
..addOption ('out' , abbr: 'o' , defaultsTo: '-' ,
81
86
help: 'output file or "-" for stdout' )
82
87
..addOption ('url-rewrites' , abbr: 'u' ,
@@ -118,6 +123,7 @@ Options parseArgs(List arguments) {
118
123
var options = new Options ();
119
124
options.sdkPath = args['sdk-path' ];
120
125
options.packageRoots = args['package-root' ].split (',' );
126
+ options.templateRoots = args['template-root' ].split (',' );
121
127
options.output = args['out' ];
122
128
if (args['url-rewrites' ] != null ) {
123
129
options.urlRewrites = new LinkedHashMap .fromIterable (
@@ -174,9 +180,10 @@ class TemplateCollectingVisitor {
174
180
Map <String , String > templates;
175
181
Set <String > skippedClasses;
176
182
SourceCrawler sourceCrawler;
183
+ List <String > templateRoots;
177
184
178
185
TemplateCollectingVisitor (this .templates, this .skippedClasses,
179
- this .sourceCrawler);
186
+ this .sourceCrawler, this .templateRoots );
180
187
181
188
void call (CompilationUnitElement cue, String srcPath) {
182
189
processDeclarations (cue, srcPath);
@@ -209,7 +216,8 @@ class TemplateCollectingVisitor {
209
216
if (cache && cacheUris.isNotEmpty) {
210
217
Source currentSrcDir = sourceCrawler.context.sourceFactory
211
218
.resolveUri (null , 'file://$srcPath ' );
212
- cacheUris..sort ()..forEach ((uri) => storeUriAsset (uri, currentSrcDir));
219
+ cacheUris..sort ()..forEach (
220
+ (uri) => storeUriAsset (uri, currentSrcDir, templateRoots));
213
221
}
214
222
});
215
223
}
@@ -252,19 +260,21 @@ class TemplateCollectingVisitor {
252
260
return cache;
253
261
}
254
262
255
- void storeUriAsset (String uri, Source srcPath) {
256
- String assetFileLocation = findAssetFileLocation (uri, srcPath);
263
+ void storeUriAsset (String uri, Source srcPath, templateRoots ) {
264
+ String assetFileLocation = findAssetLocation (uri, srcPath, templateRoots );
257
265
if (assetFileLocation == null ) {
258
266
print ("Could not find asset for uri: $uri " );
259
267
} else {
260
268
templates[uri] = assetFileLocation;
261
269
}
262
270
}
263
271
264
- String findAssetFileLocation (String uri, Source srcPath) {
272
+ String findAssetLocation (String uri, Source srcPath, List <String >
273
+ templateRoots) {
265
274
if (uri.startsWith ('/' )) {
266
- // Absolute Path from working directory.
267
- return '.${uri }' ;
275
+ var paths = templateRoots.map ((r) => '$r /$uri ' );
276
+ return paths.firstWhere ((p) => new File (p).existsSync (),
277
+ orElse: () => paths.first);
268
278
}
269
279
// Otherwise let the sourceFactory resolve for packages, and relative paths.
270
280
Source source = sourceCrawler.context.sourceFactory
0 commit comments