1 | var _ = require('lodash');
|
2 | var babel = require('gulp-babel');
|
3 | var cleanCSS = require('gulp-clean-css');
|
4 | var concat = require('gulp-concat');
|
5 | var ghpages = require('gh-pages');
|
6 | var gulp = require('@momsfriendlydevco/gulpy');
|
7 | var gutil = require('gulp-util');
|
8 | var nodemon = require('gulp-nodemon');
|
9 | var path = require('path');
|
10 | var plumber = require('gulp-plumber');
|
11 | var preprocess = require('gulp-preprocess');
|
12 | var rename = require('gulp-rename');
|
13 | var replace = require('gulp-replace');
|
14 | var rimraf = require('rimraf');
|
15 | var uglify = require('gulp-uglify');
|
16 | var vm = require('vm');
|
17 | var watch = require('gulp-watch');
|
18 |
|
19 | gulp.task('default', ['serve']);
|
20 | gulp.task('build', ['js', 'css', 'spec']);
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | gulp.task('serve', ['build'], function() {
|
27 | var monitor = nodemon({
|
28 | script: './demo/server.js',
|
29 | ext: 'js css',
|
30 | ignore: ['**/*.js', '**/.css'],
|
31 | })
|
32 | .on('start', function() {
|
33 | console.log('Server started');
|
34 | })
|
35 | .on('restart', function() {
|
36 | console.log('Server restarted');
|
37 | });
|
38 |
|
39 | watch(['./index.js', './demo/**/*.js', './src/**/*.js', './src/**/*.html'], function() {
|
40 | console.log('Rebuild client-side JS files...');
|
41 | gulp.start('js');
|
42 | });
|
43 |
|
44 | watch(['./demo/**/*.css', './src/**/*.css'], function() {
|
45 | console.log('Rebuild client-side CSS files...');
|
46 | gulp.start('css');
|
47 | });
|
48 | });
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | gulp.task('js', ()=>
|
55 | gulp.src([
|
56 | './src/macgyver.js',
|
57 | './src/components/**/*.js',
|
58 | ])
|
59 | .pipe(plumber({
|
60 | errorHandler: function(err) {
|
61 | gutil.log(gutil.colors.red('ERROR DURING JS BUILD'));
|
62 | process.stdout.write(err.stack);
|
63 | this.emit('end');
|
64 | },
|
65 | }))
|
66 | .pipe(concat('macgyver.js'))
|
67 | .pipe(preprocess({
|
68 | context: {
|
69 | angular: true,
|
70 | },
|
71 | includeBase: `${__dirname}/src`,
|
72 | }))
|
73 | .pipe(babel({
|
74 | presets: ['@babel/env'],
|
75 | plugins: ['angularjs-annotate'],
|
76 | }))
|
77 | .pipe(gulp.dest('./dist'))
|
78 | .pipe(rename('macgyver.min.js'))
|
79 | .pipe(uglify({mangle: false}))
|
80 | .pipe(gulp.dest('./dist'))
|
81 | );
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | gulp.task('css', ()=>
|
88 | gulp.src('./src/**/*.css')
|
89 | .pipe(concat('macgyver.css'))
|
90 | .pipe(gulp.dest('./dist'))
|
91 | .pipe(rename('macgyver.min.css'))
|
92 | .pipe(cleanCSS())
|
93 | .pipe(gulp.dest('./dist'))
|
94 | );
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | gulp.task('spec', ()=> {
|
102 | var widgets = {};
|
103 |
|
104 | return gulp.src('./src/components/**/*.js')
|
105 | .pipe(plumber({
|
106 | errorHandler: function(err) {
|
107 | gutil.log(gutil.colors.red('ERROR DURING SPEC BUILD'));
|
108 | process.stdout.write(err.stack);
|
109 | this.emit('end');
|
110 | },
|
111 | }))
|
112 |
|
113 | .pipe(replace(/\$macgyverProvider\.register\((.+?),\s*((.|[\n\r])+?)\t\}\)\)/gm, (all, id, spec) => {
|
114 | var sandbox = {widget: {}};
|
115 | vm.runInContext('widget = ' + spec + '};', vm.createContext(sandbox));
|
116 |
|
117 |
|
118 | widgets[_.trim(id, "'")] = _(sandbox.widget)
|
119 | .mapValues((v, k) => {
|
120 | if (_.isString(v) || _.isNumber(v) || _.isBoolean(v) || _.isObject(v)) {
|
121 | return v;
|
122 | } else if (k == 'toString' && _.isFunction(k)) {
|
123 | return true;
|
124 | } else {
|
125 | throw new Error(`Unrecognised property type in MacGyver config for key "${k}" type "${typeof v}". All values should be scalars or a translation should be specified in gulpfile.js`);
|
126 | }
|
127 | })
|
128 | .value();
|
129 | }))
|
130 |
|
131 | .pipe(concat('widgets.json'))
|
132 | .pipe(replace(/^(.|[\n\r])+$/m, ()=> JSON.stringify(widgets)))
|
133 | .pipe(gulp.dest('./dist'))
|
134 | });
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | gulp.task('gh-pages', ['build'], function() {
|
141 | rimraf.sync('./gh-pages');
|
142 |
|
143 | return gulp.src([
|
144 | './LICENSE',
|
145 | './demo/_config.yml',
|
146 | './demo/app.js',
|
147 | './demo/app.css',
|
148 | './demo/editor.html',
|
149 | './demo/index.html',
|
150 | './demo/style.css',
|
151 | './dist/**/*',
|
152 | './examples/**/*',
|
153 | './node_modules/angular/angular.min.js',
|
154 | './node_modules/@momsfriendlydevco/angular-bs-tooltip/dist/angular-bs-tooltip.min.js',
|
155 | './node_modules/angular-gravatar/build/angular-gravatar.min.js',
|
156 | './node_modules/angular-relative-date/dist/angular-relative-date.min.js',
|
157 | './node_modules/angular-sanitize/angular-sanitize.js',
|
158 | './node_modules/angular-sanitize/angular-sanitize.js',
|
159 | './node_modules/@momsfriendlydevco/angular-ui-scribble/dist/angular-ui-scribble.css',
|
160 | './node_modules/@momsfriendlydevco/angular-ui-scribble/dist/angular-ui-scribble.js',
|
161 | './node_modules/popper.js/dist/popper.min.js',
|
162 | './node_modules/bootstrap/dist/css/bootstrap.min.css',
|
163 | './node_modules/bootstrap/dist/js/bootstrap.min.js',
|
164 | './node_modules/dragular/dist/dragular.min.js',
|
165 | './node_modules/filesize/lib/filesize.js',
|
166 | './node_modules/font-awesome/css/font-awesome.min.css',
|
167 | './node_modules/font-awesome/fonts/fontawesome-webfont.ttf',
|
168 | './node_modules/font-awesome/fonts/fontawesome-webfont.woff',
|
169 | './node_modules/font-awesome/fonts/fontawesome-webfont.woff2',
|
170 | './node_modules/jquery/dist/jquery.min.js',
|
171 | './node_modules/lodash/lodash.min.js',
|
172 | './node_modules/signature_pad/dist/signature_pad.min.js',
|
173 | './node_modules/tree-tools/dist/ngTreeTools.js',
|
174 | './node_modules/ui-select/dist/select.css',
|
175 | './node_modules/ui-select/dist/select.js',
|
176 | ], {base: __dirname})
|
177 | .pipe(rename(function(path) {
|
178 | if (path.dirname == 'demo') {
|
179 | path.dirname = '.';
|
180 | }
|
181 | return path;
|
182 | }))
|
183 | .pipe(gulp.dest('gh-pages/'))
|
184 | .on('end', function(done) {
|
185 | ghpages.publish(path.join(process.cwd(), 'gh-pages'), done);
|
186 | })
|
187 | });
|