forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request react-bootstrap#852 from AlexKVal/factories
Simplify factories generation.
- Loading branch information
Showing
3 changed files
with
15 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,23 @@ | ||
import _ from 'lodash'; | ||
import path from 'path'; | ||
import fsp from 'fs-promise'; | ||
import fs from 'fs'; | ||
import { srcRoot } from './constants'; | ||
import components from './public-components'; | ||
import { buildContent } from './buildBabel'; | ||
|
||
const templatePath = path.join(srcRoot, 'templates'); | ||
const factoryTemplatePath = path.join(templatePath, 'factory.js.template'); | ||
const indexTemplatePath = path.join(templatePath, 'factory.index.js.template'); | ||
|
||
export default function generateFactories(destination, babelOptions={}) { | ||
|
||
let generateCompiledFile = function (file, content) { | ||
let outpath = path.join(destination, `${file}.js`); | ||
function generateCompiledFile(file, content) { | ||
const outpath = path.join(destination, 'factories', `${file}.js`); | ||
buildContent(content, __dirname, outpath, babelOptions); | ||
}; | ||
} | ||
|
||
const indexTemplate = fs.readFileSync(path.join(srcRoot, 'templates', 'factory.index.js.template')); | ||
const factoryTemplate = fs.readFileSync(path.join(srcRoot, 'templates', 'factory.js.template')); | ||
|
||
return Promise.all([ | ||
fsp.readFile(factoryTemplatePath) | ||
.then(template => { | ||
Promise.all(components.map(name => { | ||
generateCompiledFile(name, _.template(template)({name})); | ||
})); | ||
}), | ||
fsp.readFile(indexTemplatePath) | ||
.then(template => _.template(template)({components})) | ||
.then(content => generateCompiledFile('index', content)) | ||
]); | ||
generateCompiledFile( 'index', _.template(indexTemplate)({components}) ); | ||
|
||
return Promise.all( | ||
components.map( name => generateCompiledFile( name, _.template(factoryTemplate)({name}) )) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters