Merge pull request #18 from maksimr/master

Fix passing options and remove hardcoded scripts directory
This commit is contained in:
Simon Bailey 2014-07-21 09:48:21 +01:00
commit 0b60bca8cd
3 changed files with 15 additions and 16 deletions

View File

@ -14,11 +14,11 @@ var ReactWebpackGenerator = module.exports = function ReactWebpackGenerator(args
args = ['main']; args = ['main'];
if (typeof this.env.options.appPath === 'undefined') { if (typeof this.options.appPath === 'undefined') {
this.env.options.appPath = this.env.options.appPath || 'src'; this.options.appPath = this.options.appPath || 'src';
} }
this.appPath = this.env.options.appPath; this.appPath = this.options.appPath;
this.hookFor('react-webpack:common', { this.hookFor('react-webpack:common', {
args: args args: args

View File

@ -10,6 +10,6 @@ var MainGenerator = module.exports = function MainGenerator(args, options, confi
util.inherits(MainGenerator, ScriptBase); util.inherits(MainGenerator, ScriptBase);
MainGenerator.prototype.createAppFile = function createAppFile() { MainGenerator.prototype.createAppFile = function createAppFile() {
this.appTemplate('App', 'scripts/components/' + this.scriptAppName); this.appTemplate('App', 'components/' + this.scriptAppName);
this.testTemplate('spec/App', 'components/' + this.scriptAppName); this.testTemplate('spec/App', 'components/' + this.scriptAppName);
}; };

View File

@ -20,23 +20,22 @@ var Generator = module.exports = function Generator() {
this.classedFileName = this._.capitalizeFile(this.name); this.classedFileName = this._.capitalizeFile(this.name);
this.classedName = this._.capitalizeClass(this.name); this.classedName = this._.capitalizeClass(this.name);
if (typeof this.env.options.appPath === 'undefined') { if (typeof this.options.appPath === 'undefined') {
this.env.options.appPath = this.env.options.appPath || 'src'; this.options.appPath = this.options.appPath || 'src/scripts';
} }
if (typeof this.env.options.testPath === 'undefined') { if (typeof this.options.testPath === 'undefined') {
this.env.options.testPath = this.env.options.testPath || 'test/spec'; this.options.testPath = this.options.testPath || 'test/spec';
} }
if (typeof this.env.options.stylesPath === 'undefined') { if (typeof this.options.stylesPath === 'undefined') {
this.env.options.stylesPath = this.env.options.stylesPath || 'src/styles'; this.options.stylesPath = this.options.stylesPath || 'src/styles';
} }
var sourceRoot = '/templates/'; var sourceRoot = '/templates/';
this.scriptSuffix = '.js'; this.scriptSuffix = '.js';
this.reactSuffix = '.jsx'; this.reactSuffix = '.jsx';
var stylesRoot = '/templates/styles';
this.stylesSuffix = '.css'; this.stylesSuffix = '.css';
this.sourceRoot(path.join(__dirname, sourceRoot)); this.sourceRoot(path.join(__dirname, sourceRoot));
@ -47,14 +46,14 @@ util.inherits(Generator, yeoman.generators.NamedBase);
Generator.prototype.appTemplate = function (src, dest) { Generator.prototype.appTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [ yeoman.generators.Base.prototype.template.apply(this, [
path.join('javascript', src + this.reactSuffix), path.join('javascript', src + this.reactSuffix),
path.join(this.env.options.appPath, dest) + this.reactSuffix path.join(this.options.appPath, dest) + this.reactSuffix
]); ]);
}; };
Generator.prototype.testTemplate = function (src, dest) { Generator.prototype.testTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [ yeoman.generators.Base.prototype.template.apply(this, [
src + this.scriptSuffix, src + this.scriptSuffix,
path.join(this.env.options.testPath, dest) + this.scriptSuffix path.join(this.options.testPath, dest) + this.scriptSuffix
]); ]);
}; };
@ -62,19 +61,19 @@ Generator.prototype.stylesTemplate = function (src, dest) {
console.log(src); console.log(src);
yeoman.generators.Base.prototype.template.apply(this, [ yeoman.generators.Base.prototype.template.apply(this, [
src + this.stylesSuffix, src + this.stylesSuffix,
path.join(this.env.options.stylesPath, dest) + this.stylesSuffix path.join(this.options.stylesPath, dest) + this.stylesSuffix
]); ]);
}; };
Generator.prototype.htmlTemplate = function (src, dest) { Generator.prototype.htmlTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [ yeoman.generators.Base.prototype.template.apply(this, [
src, src,
path.join(this.env.options.appPath, dest.toLowerCase()) path.join(this.options.appPath, dest.toLowerCase())
]); ]);
}; };
Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, stylesTemplate, targetDirectory) { Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, stylesTemplate, targetDirectory) {
this.appTemplate(appTemplate, path.join('scripts', targetDirectory, this._.capitalizeFile(this.name))); this.appTemplate(appTemplate, path.join(targetDirectory, this._.capitalizeFile(this.name)));
this.testTemplate(testTemplate, path.join(targetDirectory, this._.capitalizeFile(this.name))); this.testTemplate(testTemplate, path.join(targetDirectory, this._.capitalizeFile(this.name)));
this.stylesTemplate(stylesTemplate, path.join(this._.capitalizeFile(this.name))); this.stylesTemplate(stylesTemplate, path.join(this._.capitalizeFile(this.name)));
}; };