1 | 'use strict';
|
2 |
|
3 | var handlebars = require('handlebars');
|
4 | var path = require('path');
|
5 | var fs = require('fs');
|
6 | var xtend = require('xtend');
|
7 |
|
8 | var templatePath = path.join(__dirname, 'index.hbs');
|
9 | var template = fs.readFileSync(templatePath, 'utf8');
|
10 | var index = handlebars.compile(template);
|
11 | var genPath = path.join(__dirname, '..', 'loaders');
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var genIndex = module.exports = function (fullPaths, cb) {
|
22 | if (!fullPaths.length) cb(null);
|
23 |
|
24 | var keys = fullPaths.map(function (p) {
|
25 | var extlen = path.extname(p).length;
|
26 | var filename = path.basename(p);
|
27 | return extlen ? filename.slice(0, -extlen) : filename;
|
28 | });
|
29 |
|
30 | var s = index({ keys: keys });
|
31 |
|
32 | var filePath = path.join(genPath, 'index.js');
|
33 | fs.writeFile(filePath, s, 'utf8', cb);
|
34 | };
|