|
1 | 1 | import _ from 'lodash';
|
2 | 2 | import path from 'path';
|
3 |
| -import fsp from 'fs-promise'; |
| 3 | +import fs from 'fs'; |
4 | 4 | import { srcRoot } from './constants';
|
5 | 5 | import components from './public-components';
|
6 | 6 | import { buildContent } from './buildBabel';
|
7 | 7 |
|
8 |
| -const templatePath = path.join(srcRoot, 'templates'); |
9 |
| -const factoryTemplatePath = path.join(templatePath, 'factory.js.template'); |
10 |
| -const indexTemplatePath = path.join(templatePath, 'factory.index.js.template'); |
11 |
| - |
12 | 8 | export default function generateFactories(destination, babelOptions={}) {
|
13 | 9 |
|
14 |
| - let generateCompiledFile = function (file, content) { |
15 |
| - let outpath = path.join(destination, `${file}.js`); |
| 10 | + function generateCompiledFile(file, content) { |
| 11 | + const outpath = path.join(destination, 'factories', `${file}.js`); |
16 | 12 | buildContent(content, __dirname, outpath, babelOptions);
|
17 |
| - }; |
| 13 | + } |
| 14 | + |
| 15 | + const indexTemplate = fs.readFileSync(path.join(srcRoot, 'templates', 'factory.index.js.template')); |
| 16 | + const factoryTemplate = fs.readFileSync(path.join(srcRoot, 'templates', 'factory.js.template')); |
18 | 17 |
|
19 |
| - return Promise.all([ |
20 |
| - fsp.readFile(factoryTemplatePath) |
21 |
| - .then(template => { |
22 |
| - Promise.all(components.map(name => { |
23 |
| - generateCompiledFile(name, _.template(template)({name})); |
24 |
| - })); |
25 |
| - }), |
26 |
| - fsp.readFile(indexTemplatePath) |
27 |
| - .then(template => _.template(template)({components})) |
28 |
| - .then(content => generateCompiledFile('index', content)) |
29 |
| - ]); |
| 18 | + generateCompiledFile( 'index', _.template(indexTemplate)({components}) ); |
30 | 19 |
|
| 20 | + return Promise.all( |
| 21 | + components.map( name => generateCompiledFile( name, _.template(factoryTemplate)({name}) )) |
| 22 | + ); |
31 | 23 | }
|
0 commit comments