forked from react-fullstack/slush-react-fullstack
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcrudModule.js
More file actions
129 lines (119 loc) · 5.8 KB
/
crudModule.js
File metadata and controls
129 lines (119 loc) · 5.8 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
module.exports = function(gulp, install, conflict, template, rename, _, inflections, inquirer, mkdirp){
gulp.task('crud-module', function (done) {
if(!this.args[0])
{
console.log('****** Incorrect usage of the sub-generator!! ******');
console.log('****** Try slush meanjs:crud-module <module-name> ******');
console.log('****** Ex: slush meanjs:crud-module article ******');
return done();
}
var moduleName = this.args[0];
var prompts = [{
type: 'checkbox',
name: 'folders',
message: 'Which supplemental folders would you like to include in your angular module?',
choices: [{
value: 'addCSSFolder',
name: 'css',
checked: true
}, {
value: 'addImagesFolder',
name: 'img',
checked: true
}, {
value: 'addDirectivesFolder',
name: 'directives',
checked: true
}, {
value: 'addFiltersFolder',
name: 'filters',
checked: true
}]
}, {
type: 'confirm',
name: 'addMenuItems',
message: 'Would you like to add the CRUD module links to a menu?',
default: true
}];
//Ask
inquirer.prompt(prompts,
function (answers) {
if (!answers) {
return done();
}
answers.addCSSFolder = _.contains(answers.folders, 'addCSSFolder');
answers.addImagesFolder = _.contains(answers.folders, 'addImagesFolder');
answers.addDirectivesFolder = _.contains(answers.folders, 'addDirectivesFolder');
answers.addFiltersFolder = _.contains(answers.folders, 'addFiltersFolder');
answers.addMenuItems = answers.addMenuItems;
// modulenames
answers.slugifiedName = _.slugify(moduleName);
answers.slugifiedPluralName = inflections.pluralize(answers.slugifiedName);
answers.slugifiedSingularName = inflections.singularize(answers.slugifiedName);
answers.camelizedPluralName = _.camelize(answers.slugifiedPluralName);
answers.camelizedSingularName = _.camelize(answers.slugifiedSingularName);
answers.classifiedPluralName = _.classify(answers.slugifiedPluralName);
answers.classifiedSingularName = _.classify(answers.slugifiedSingularName);
answers.humanizedPluralName = _.humanize(answers.slugifiedPluralName);
answers.humanizedSingularName = _.humanize(answers.slugifiedSingularName);
//public folders
if (answers.addCSSFolder) mkdirp('public/modules/' + answers.slugifiedPluralName + '/css');
if (answers.addImagesFolder) mkdirp('public/modules/' + answers.slugifiedPluralName + '/img');
if (answers.addDirectivesFolder) mkdirp('public/modules/' + answers.slugifiedPluralName + '/directives');
if (answers.addFiltersFolder) mkdirp('public/modules/' + answers.slugifiedPluralName + '/filters');
// Create public folders for ng
mkdirp('public/modules/' + answers.slugifiedPluralName + '/config');
mkdirp('public/modules/' + answers.slugifiedPluralName + '/controllers');
mkdirp('public/modules/' + answers.slugifiedPluralName + '/services');
mkdirp('public/modules/' + answers.slugifiedPluralName + '/tests');
// express-modules
gulp.src(__dirname + '/../templates/crud-module/express-module/**')
.pipe(template(answers))
.pipe(rename(function(file) {
if (file.basename.indexOf('_') == 0) {
file.basename = answers.slugifiedPluralName + '.'+file.basename.slice(2);
}
}))
.pipe(conflict('./'))
.pipe(gulp.dest('./'));
// Menu configuration
if (answers.addMenuItems) {
answers.menuId = 'topbar';
gulp.src(__dirname + '/../templates/crud-module/angular-module/config/**')
.pipe(template(answers))
.pipe(rename(function(file) {
if (file.basename.indexOf('_') == 0) {
file.basename = answers.slugifiedPluralName + '.'+file.basename.slice(2);
}
}))
.pipe(conflict('public/modules/' + answers.slugifiedPluralName+'/'))
.pipe(gulp.dest('public/modules/' + answers.slugifiedPluralName+'/'));
}
gulp.src(__dirname + '/../templates/crud-module/angular-module/views/**')
.pipe(template(answers))
.pipe(rename(function(file) {
if (file.basename.indexOf('list') >= 0) {
file.basename = file.basename.replace('_', answers.slugifiedPluralName) ;
}
else {
file.basename = file.basename.replace('_', answers.slugifiedSingularName) ;
}
}))
.pipe(conflict('public/modules/' + answers.slugifiedPluralName+'/'))
.pipe(gulp.dest('public/modules/' + answers.slugifiedPluralName+'/'));
gulp.src(__dirname + '/../templates/crud-module/angular-module/public/**')
.pipe(template(answers))
.pipe(rename(function(file) {
if (file.basename.indexOf('_') == 0) {
file.basename = answers.slugifiedPluralName + '.'+file.basename.slice(2);
}
}))
.pipe(conflict('public/modules/' + answers.slugifiedPluralName+'/'))
.pipe(gulp.dest('public/modules/' + answers.slugifiedPluralName+'/'))
.on('end', function () {
done();
});
});
});
return gulp;
}