forked from rancher/ui-driver-rackhd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
88 lines (76 loc) · 2.41 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
/* jshint node: true */
const gulp = require('gulp');
const clean = require('gulp-clean');
const gulpConcat = require('gulp-concat');
const gulpConnect = require('gulp-connect');
const emCompiler = require('./bower_components/ember/ember-template-compiler');
const htmlbars = require('gulp-htmlbars-compiler');
const wrapAmd = require('gulp-wrap-amd');
const replace = require('gulp-replace');
const argv = require('yargs').argv;
const pkg = require('./package.json');
const NAME_TOKEN = '%%DRIVERNAME%%';
const NAME_LOWER_TOKEN = '%%DRIVERLOWERNAME%%';
const BASE = 'component/';
const DIST = 'dist/';
const TMP = 'tmp/';
const ASSETS = 'assets/';
const DRIVER_NAME = argv.name || pkg.name.replace(/^ui-driver-/,'');
console.log('Driver Name:', DRIVER_NAME);
if (!DRIVER_NAME) {
console.log('Please include a driver name with the --name flag');
process.exit(1);
}
gulp.task('default', ['build']);
gulp.task('server', ['build'], function() {
return gulpConnect.server({
root: [DIST],
port: process.env.PORT || 3000,
https: true
});
});
gulp.task('clean', function() {
return gulp.src([DIST, TMP], {read: false})
.pipe(clean());
});
gulp.task('js', function() {
return gulp.src([
BASE + '*.js'
])
.pipe(replace(NAME_TOKEN, DRIVER_NAME))
.pipe(gulpConcat('component.js',{newLine: ';\n'}))
.pipe(gulp.dest(TMP));
});
gulp.task('css', function() {
return gulp.src([
BASE + '**.css'
])
.pipe(replace(NAME_TOKEN, DRIVER_NAME))
.pipe(gulpConcat('component.css',{newLine: ';\n'}))
.pipe(gulp.dest(DIST));
});
gulp.task('assets', function() {
return gulp.src(ASSETS+'*')
.pipe(gulp.dest(DIST));
});
gulp.task('compiled', ['js'], function() {
return gulp.src(BASE +'**/*.hbs')
.pipe(replace(NAME_TOKEN, DRIVER_NAME))
.pipe(htmlbars({compiler: emCompiler}))
.pipe(wrapAmd({
deps: ['exports', 'ember', 'ui/mixins/driver'],
params: ['exports', '_ember', '_uiMixinsDriver'],
moduleRoot: 'component/',
modulePrefix: 'ui/components/machine/driver-' + DRIVER_NAME + '/'
}))
.pipe(replace(
"return Ember.TEMPLATES['template']", 'exports["default"]'
))
.pipe(gulpConcat('template.js'), {newLine: ';\n'})
.pipe(gulp.dest(TMP));
});
gulp.task('build', ['compiled','css','assets'], function() {
return gulp.src([`${TMP}/*.js`])
.pipe(gulpConcat('component.js',{newLine: ';\n'}))
.pipe(gulp.dest(DIST));
});