forked from react-webpack-generators/generator-react-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script-base.js
79 lines (63 loc) · 2.65 KB
/
script-base.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict';
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var generalUtils = require('./util.js');
var Generator = module.exports = function Generator() {
yeoman.generators.NamedBase.apply(this, arguments);
// Add capitalize mixin
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.classedFileName = this._.capitalizeFile(this.name);
this.classedName = this._.capitalizeClass(this.name);
if (typeof this.options.appPath === 'undefined') {
this.options.appPath = this.options.appPath || 'src/js';
}
if (typeof this.options.testPath === 'undefined') {
this.options.testPath = this.options.testPath || 'src/js';
}
if (typeof this.options.stylesPath === 'undefined') {
this.options.stylesPath = this.options.stylesPath || 'src/styles';
}
var sourceRoot = '/templates/';
this.scriptSuffix = '.js';
this.reactSuffix = '.jsx';
this.stylesSuffix = '.css';
this.sourceRoot(path.join(__dirname, sourceRoot));
};
util.inherits(Generator, yeoman.generators.NamedBase);
Generator.prototype.appTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
path.join('javascript', src + this.reactSuffix),
path.join(this.options.appPath, dest) + this.reactSuffix
]);
};
Generator.prototype.testTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
src + this.scriptSuffix,
path.join(this.options.testPath, dest) + '.spec.js'
]);
};
Generator.prototype.stylesTemplate = function (src, dest) {
console.log(src);
yeoman.generators.Base.prototype.template.apply(this, [
src + this.stylesSuffix,
path.join(this.options.stylesPath, dest) + this.stylesSuffix
]);
};
Generator.prototype.htmlTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
src,
path.join(this.options.appPath, dest.toLowerCase())
]);
};
Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, stylesTemplate, targetDirectory) {
this.appTemplate(appTemplate, 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)));
};