Skip to content

Commit 1bc3253

Browse files
committed
Merge pull request react-bootstrap#852 from AlexKVal/factories
Simplify factories generation.
2 parents 7f65599 + c8a8194 commit 1bc3253

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

tools/amd/build.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const babelOptions = {
2020
};
2121

2222
const libDestination = path.join(bowerRoot, 'lib');
23-
const factoriesDestination = path.join(libDestination, 'factories');
2423

2524
function bowerConfig() {
2625
return Promise.all([
@@ -37,10 +36,10 @@ export default function BuildBower() {
3736
console.log('Building: '.cyan + 'bower module'.green);
3837

3938
return exec(`rimraf ${bowerRoot}`)
40-
.then(() => fsp.mkdirs(factoriesDestination))
39+
.then(() => fsp.mkdirs(libDestination))
4140
.then(() => Promise.all([
4241
bowerConfig(),
43-
generateFactories(factoriesDestination, babelOptions),
42+
generateFactories(libDestination, babelOptions),
4443
buildFolder(srcRoot, libDestination, babelOptions),
4544
copy(readme, bowerRoot),
4645
copy(license, bowerRoot)

tools/generateFactories.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
import _ from 'lodash';
22
import path from 'path';
3-
import fsp from 'fs-promise';
3+
import fs from 'fs';
44
import { srcRoot } from './constants';
55
import components from './public-components';
66
import { buildContent } from './buildBabel';
77

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-
128
export default function generateFactories(destination, babelOptions={}) {
139

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`);
1612
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'));
1817

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}) );
3019

20+
return Promise.all(
21+
components.map( name => generateCompiledFile( name, _.template(factoryTemplate)({name}) ))
22+
);
3123
}

tools/lib/build.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import 'colors';
22
import { exec } from '../exec';
3-
import path from 'path';
43
import fsp from 'fs-promise';
54
import { srcRoot, libRoot } from '../constants';
65
import generateFactories from '../generateFactories';
76
import { buildFolder } from '../buildBabel';
87

9-
const factoryDestination = path.join(libRoot, 'factories');
10-
118
export default function BuildCommonJs() {
129
console.log('Building: '.cyan + 'npm module'.green);
1310

1411
return exec(`rimraf ${libRoot}`)
15-
.then(() => fsp.mkdirs(factoryDestination))
12+
.then(() => fsp.mkdirs(libRoot))
1613
.then(() => Promise.all([
17-
generateFactories(factoryDestination),
14+
generateFactories(libRoot),
1815
buildFolder(srcRoot, libRoot)
1916
]))
2017
.then(() => console.log('Built: '.cyan + 'npm module'.green));

0 commit comments

Comments
 (0)