mirror of
https://github.com/react-webpack-generators/generator-react-webpack.git
synced 2025-12-08 18:01:59 +00:00
parent
defeaedb71
commit
abdb2adb02
3
.gitignore
vendored
3
.gitignore
vendored
@ -28,5 +28,4 @@ $RECYCLE.BIN/
|
||||
# App specific
|
||||
|
||||
node_modules/
|
||||
/test/temp-test/
|
||||
/test/temp/
|
||||
/test/*
|
||||
|
||||
@ -8,14 +8,17 @@ var Generator = module.exports = function Generator() {
|
||||
yeoman.generators.NamedBase.apply(this, arguments);
|
||||
|
||||
// Add capitalize mixin
|
||||
this._.mixin({ 'capitalize': generalUtils.capitalize });
|
||||
this._.mixin({ 'capitalize': generalUtils.capitalize });
|
||||
this._.mixin({ 'capitalizeFile': generalUtils.capitalizeFile });
|
||||
this._.mixin({ 'capitalizeClass': generalUtils.capitalizeClass });
|
||||
this._.mixin({ 'lowercase': generalUtils.lowercase });
|
||||
|
||||
this.appname = path.basename(process.cwd());
|
||||
|
||||
this.appname = this._.slugify(this._.humanize(this.appname));
|
||||
this.scriptAppName = this._.camelize(this._.capitalize(this.appname)) + generalUtils.appName(this);
|
||||
this.classedName = this._.capitalize(this.name);
|
||||
this.classedFileName = this._.capitalizeFile(this.name);
|
||||
this.classedName = this._.capitalizeClass(this.name);
|
||||
|
||||
if (typeof this.env.options.appPath === 'undefined') {
|
||||
this.env.options.appPath = this.env.options.appPath || 'src';
|
||||
@ -71,7 +74,7 @@ Generator.prototype.htmlTemplate = function (src, dest) {
|
||||
};
|
||||
|
||||
Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, stylesTemplate, targetDirectory) {
|
||||
this.appTemplate(appTemplate, path.join('scripts', targetDirectory, this._.capitalize(this.name)));
|
||||
this.testTemplate(testTemplate, path.join(targetDirectory, this._.capitalize(this.name)));
|
||||
this.stylesTemplate(stylesTemplate, path.join(this._.capitalize(this.name)));
|
||||
this.appTemplate(appTemplate, path.join('scripts', targetDirectory, this._.capitalizeFile(this.name)));
|
||||
this.testTemplate(testTemplate, path.join(targetDirectory, this._.capitalizeFile(this.name)));
|
||||
this.stylesTemplate(stylesTemplate, path.join(this._.capitalizeFile(this.name)));
|
||||
};
|
||||
|
||||
@ -4,7 +4,7 @@ describe('<%= classedName %>', function () {
|
||||
var <%= classedName %>, component;
|
||||
|
||||
beforeEach(function () {
|
||||
<%= classedName %> = require('../../../src/scripts/components/<%= classedName %>.jsx');
|
||||
<%= classedName %> = require('../../../src/scripts/components/<%= classedFileName %>.jsx');
|
||||
component = <%= classedName %>();
|
||||
});
|
||||
|
||||
|
||||
21
util.js
21
util.js
@ -7,7 +7,9 @@ module.exports = {
|
||||
rewrite: rewrite,
|
||||
rewriteFile: rewriteFile,
|
||||
appName: appName,
|
||||
capitalize: capitalize
|
||||
capitalize: capitalize,
|
||||
capitalizeClass: capitalizeClass,
|
||||
capitalizeFile: capitalizeFile
|
||||
};
|
||||
|
||||
function rewriteFile (args) {
|
||||
@ -60,8 +62,21 @@ function rewrite (args) {
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
function capitalize(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
|
||||
function capitalize(str) {
|
||||
str = String(str);
|
||||
return str[0].toUpperCase() + str.substr(1, str.length);
|
||||
}
|
||||
|
||||
function capitalizeClass(string) {
|
||||
var words = string.split('/');
|
||||
words.push(capitalize(words.pop()));
|
||||
return words.pop();
|
||||
}
|
||||
|
||||
function capitalizeFile(string) {
|
||||
var words = string.split('/');
|
||||
words.push(capitalize(words.pop()));
|
||||
return words.join('/');
|
||||
}
|
||||
|
||||
function appName(self) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user