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.
[added] convenience factories for non-JSX users in lib/factories
- Loading branch information
1 parent
f151f11
commit 8da11b4
Showing
9 changed files
with
105 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<% _.forEach(components, function (component) { %> | ||
import <%= component %> from './<%= component %>'; | ||
<% }); %> | ||
|
||
export default { | ||
<% _.forEach(components, function (component) { %> | ||
<%= component %>, | ||
<% }); %> | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import React from 'react'; | ||
import <%= name %> from '../<%= name %>'; | ||
|
||
export default React.createFactory(<%= 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import components from '../tools/public-components'; | ||
|
||
let props = { | ||
Glyphicon: {glyph: 'star'}, | ||
Modal: {onRequestHide: function() {}}, | ||
ModalTrigger: {modal: React.DOM.div(null)}, | ||
OverlayTrigger: {overlay: React.DOM.div(null)} | ||
}; | ||
|
||
function createTest(component) { | ||
let factory = require(`../lib/factories/${component}`); | ||
describe('factories', function () { | ||
it(`Should have a ${component} factory`, function () { | ||
assert.ok(React.isValidElement(factory(props[component]))); | ||
}); | ||
}); | ||
} | ||
|
||
components.map(component => createTest(component)); |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import _ from 'lodash'; | ||
import path from 'path'; | ||
import fsp from 'fs-promise'; | ||
import { exec } from './exec'; | ||
import { srcRoot } from './constants'; | ||
import components from './public-components'; | ||
|
||
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(babelOptions, destination) { | ||
|
||
let generateCompiledFile = function (file, content) { | ||
let outpath = path.join(destination, `${file}.js`); | ||
return exec(`babel ${babelOptions} --out-file ${outpath} <<EOF\n ${content}`); | ||
}; | ||
|
||
return Promise.all([ | ||
fsp.readFile(factoryTemplatePath) | ||
.then(template => { | ||
Promise.all(components.map(name => { | ||
generateCompiledFile(name, _.template(template)({name: name})); | ||
})); | ||
}), | ||
fsp.readFile(indexTemplatePath) | ||
.then(template => _.template(template)({components: components})) | ||
.then(content => generateCompiledFile('index', content)) | ||
]); | ||
|
||
} |
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,11 +1,21 @@ | ||
import 'colors'; | ||
import { exec } from '../exec'; | ||
import path from 'path'; | ||
import fsp from 'fs-promise'; | ||
import { srcRoot, libRoot } from '../constants'; | ||
import generateFactories from '../generateFactories'; | ||
|
||
const factoryDestination = path.join(libRoot, 'factories'); | ||
const babelOptions = '--optional es7.objectRestSpread'; | ||
|
||
export default function BuildCommonJs() { | ||
console.log('Building: '.cyan + 'npm module'.green); | ||
|
||
return exec(`rimraf ${libRoot}`) | ||
.then(() => exec(`babel --optional es7.objectRestSpread ${srcRoot} --out-dir ${libRoot}`)) | ||
.then(() => fsp.mkdirs(factoryDestination)) | ||
.then(() => Promise.all([ | ||
generateFactories(babelOptions, factoryDestination), | ||
exec(`babel ${babelOptions} ${srcRoot} --out-dir ${libRoot}`) | ||
])) | ||
.then(() => console.log('Built: '.cyan + 'npm module'.green)); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import index from '../src/index'; | ||
|
||
let components = []; | ||
Object.keys(index).forEach(function (item) { | ||
if (index[item] instanceof React.Component.constructor) { | ||
components.push(item); | ||
} | ||
}); | ||
|
||
export default components; |