-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpFile.js
149 lines (123 loc) · 6.12 KB
/
GulpFile.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var gulp = require('gulp');
var bowerFiles = require('main-bower-files');
var minifyjs = require('gulp-uglify');
var minifycss = require('gulp-minify-css');
var less = require('gulp-less');
var concat = require('gulp-concat');
var ngAnnotate = require('gulp-ng-annotate');
gulp.task('bower', function () {
gulp.src(bowerFiles('**/*.js'))
.pipe(concat('vendor.min.js'))
.pipe(ngAnnotate())
.pipe(gulp.dest('compiled/js/'));
gulp.src(bowerFiles('**/*.css'))
.pipe(concat('vendor.min.css'))
.pipe(gulp.dest('compiled/css/'));
return true;
});
gulp.task('js', function () {
gulp.src([
'compiled/js/vendor.min.js',
'src/app/restful-herc.js',
'src/app/config.js',
'src/app/directives/**/*.js',
'src/app/filters/**/*.js',
'src/app/services/**/*.js',
'src/components/**/*.js'
])
.pipe(concat('main.min.js'))
.pipe(minifyjs({mangle: false, output: {ascii_only: true}}))
.pipe(gulp.dest('www/assets/js/'));
return true;
});
gulp.task('css', function () {
gulp.src([
'src/components/**/*.less'
])
.pipe(less({
strictMath: true
}))
.pipe(concat('compiled-less.css'))
.pipe(gulp.dest('compiled/css'));
gulp.src([
'compiled/css/vendor.min.css',
'bower/bootstrap/dist/css/bootstrap.min.css',
'src/app/**/*.css',
'src/components/**/*.css',
'compiled/css/compiled-less.css'
])
.pipe(concat('main.min.css'))
.pipe(minifycss({processImport: false}))
.pipe(gulp.dest('www/assets/css/'));
return true;
});
gulp.task('templates', function () {
return gulp.src('src/components/**/*.html')
.pipe(gulp.dest('www/templates'));
});
gulp.task('watch', function () {
gulp.watch('src/**/*.js', ['js']);
gulp.watch('src/**/*.css', ['css']);
gulp.watch('src/**/*.less', ['css']);
gulp.watch('src/**/*.html', ['templates']);
gulp.watch('bower/**/*', ['bower', 'css', 'js']);
});
gulp.task('add', function () {
var name = process.argv.slice(3)[1];
var fs = require('fs');
var abs_path = name.split('.').join('/');
var dir = 'src/components/' + abs_path;
var url = name.split(".").pop();
var controllerName = '';
var page_title = '';
var name_bits = name.split('.');
for (key in name_bits) {
controllerName += name_bits[key].charAt(0).toUpperCase() + name_bits[key].slice(1);
page_title += name_bits[key].charAt(0).toUpperCase() + name_bits[key].slice(1) + ' ';
}
;
var className = name.split(".").join('-');
fs.mkdirSync(dir);
fs.writeFileSync(dir + "/" + url + ".js", 'var app = angular.module("app");\n\napp.config(function($stateProvider){\n\t$stateProvider\n\t\t.state("' + name + '",{\n\t\t\turl: "/' + url + '",\n\t\t\tdata: { pageTitle: \'' + page_title + '\' },\n\t\t\ttemplateUrl: "/templates/' + abs_path + '/' + url + '.html",\n\t\t\tcontroller: "' + controllerName + 'Controller"\n\t\t})\n}); \n\napp.controller("' + controllerName + 'Controller", function ($scope, $rootScope, $state, $stateParams, Herc) {\n\t\/\/All your code goes here\n});');
fs.writeFileSync(dir + "/" + url + ".html", '<div class="' + className + '">\n\t<!-- put all the view stuff in here-->\n\t<ui-view></ui-view>\n</div>');
fs.writeFileSync(dir + "/" + url + ".less", '.' + className + ' {\n\n\/*less/css stuff can go in here*\/\n\n}');
});
gulp.task('section', function () {
var template = process.argv.slice(3)[1]
var name = process.argv.slice(3)[3];
var fs = require('fs');
var dir = 'src/components/site/templates/' + template + '/section/' + name;
var url = name.split(".").pop();
var controllerName = 'SiteTemplates';
var name_bits = [template, 'section', name]
for (key in name_bits) {
controllerName += name_bits[key].charAt(0).toUpperCase() + name_bits[key].slice(1);
}
var className = name.split(".").join('-');
fs.mkdirSync(dir);
fs.writeFileSync(dir + "/" + url + ".js", 'var app = angular.module("app"); \n\napp.controller("' + controllerName + 'Controller", function ($scope, $rootScope, $state, $stateParams, Herc) {\n\t\/\/All your code goes here\n});');
fs.writeFileSync(dir + "/configure.html", '<div class="' + className + '" ng-controller="' + controllerName + 'Controller">\n\t<!-- put all the view stuff in here-->\n\t<ui-view></ui-view>\n</div>');
fs.writeFileSync(dir + "/public.html", '<div class="' + className + '" ng-controller="' + controllerName + 'Controller">\n\t<!-- put all the view stuff in here-->\n\t<ui-view></ui-view>\n</div>');
fs.writeFileSync(dir + "/" + url + ".less", '.' + className + ' {\n\n\/*less/css stuff can go in here*\/\n\n}');
});
gulp.task('addnoroute', function () {
var name = process.argv.slice(3)[1];
var fs = require('fs');
var abs_path = name.split('.').join('/');
var dir = 'src/components/' + abs_path;
var url = name.split(".").pop();
var controllerName = '';
var page_title = '';
var name_bits = name.split('.');
for (key in name_bits) {
controllerName += name_bits[key].charAt(0).toUpperCase() + name_bits[key].slice(1);
page_title += name_bits[key].charAt(0).toUpperCase() + name_bits[key].slice(1) + ' ';
};
var className = name.split(".").join('-');
fs.mkdirSync(dir);
fs.writeFileSync(dir + "/" + url + ".js", 'var app = angular.module("app"); \n\napp.controller("' + controllerName + 'Controller", function ($scope, $rootScope, $state, $stateParams, Herc) {\n\t\/\/All your code goes here\n});');
fs.writeFileSync(dir + "/" + url + ".html", '<div class="' + className + '" ng-controller="' + controllerName + '">\n\t<!-- put all the view stuff in here-->\n\t<ui-view></ui-view>\n</div>');
fs.writeFileSync(dir + "/" + url + ".less", '.' + className + ' {\n\n\/*less/css stuff can go in here*\/\n\n}');
});
gulp.task('compile', ['bower', 'templates', 'css', 'js']);
gulp.task('default', ['bower', 'templates', 'css', 'js', 'watch']);