Node-Red configuration
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. var
  2. gulp = require('gulp'),
  3. concat = require('gulp-concat'),
  4. eol = require('gulp-eol'),
  5. exec = require('child_process').exec,
  6. fs = require('fs'),
  7. ghtmlSrc = require('gulp-html-src'),
  8. gulpif = require('gulp-if'),
  9. gutil = require('gulp-util'),
  10. header = require("gulp-header"),
  11. htmlreplace = require('gulp-html-replace'),
  12. jscs = require('gulp-jscs'),
  13. jshint = require('gulp-jshint'),
  14. manifest = require('gulp-manifest'),
  15. minifyCss = require('gulp-clean-css'),
  16. minifyHTML = require('gulp-htmlmin'),
  17. path = require('path'),
  18. replace = require('gulp-replace'),
  19. streamqueue = require('streamqueue'),
  20. templateCache = require('gulp-angular-templatecache'),
  21. uglify = require('gulp-uglify'),
  22. sass = require('gulp-sass'),
  23. rename = require('gulp-rename');
  24. //gulp.task('default', ['manifest']);
  25. gulp.task('default', ['lint','jscs'], function() {
  26. gulp.start('manifest');
  27. //gulp.start('build');
  28. });
  29. gulp.task('build', ['icon', 'js', 'css', 'less', 'index', 'fonts', 'gridstack']);
  30. gulp.task('manifest', ['build'], function() {
  31. gulp.src(['dist/*','dist/css/*','dist/js/*','dist/fonts/*'], { base: 'dist/' })
  32. .pipe(manifest({
  33. hash: true,
  34. //preferOnline: true,
  35. network: ['*'],
  36. filename: 'dashboard.appcache',
  37. // exclude: 'dashboard.appcache'
  38. exclude: ['dashboard.appcache','index.html']
  39. }))
  40. .pipe(replace('tinycolor-min.js', 'tinycolor-min.js\nsocket.io/socket.io.js'))
  41. .pipe(eol('\n'))
  42. .pipe(gulp.dest('dist/'));
  43. });
  44. gulp.task('lint', function() {
  45. return gulp.src('**/*.js')
  46. .pipe(jshint('.jshintrc'))
  47. .pipe(jshint.reporter('default'))
  48. .pipe(jshint.reporter('fail'));
  49. });
  50. gulp.task('jscs', function() {
  51. return gulp.src(['*.js','nodes/*.js','src/*.js','src/*/*.js','src/*/*/*.js'])
  52. .pipe(jscs())
  53. //.pipe(jscs({fix: true}))
  54. .pipe(jscs.reporter("inline"))
  55. });
  56. gulp.task('index', function() {
  57. return gulp.src('src/index.html')
  58. .pipe(htmlreplace({
  59. 'css': 'css/app.min.css',
  60. 'js': 'js/app.min.js',
  61. 'less': '<link rel="stylesheet/less" href="css/app.min.less" />'
  62. }))
  63. .pipe(minifyHTML({collapseWhitespace:true, conservativeCollapse:true}))
  64. .pipe(eol('\n'))
  65. .pipe(gulp.dest('dist/'));
  66. });
  67. gulp.task('icon', function() {
  68. // gulp.src('src/wheel.png').pipe(gulp.dest('dist/css/'));
  69. gulp.src('src/icon192x192.png').pipe(gulp.dest('dist/'));
  70. gulp.src('src/icon120x120.png').pipe(gulp.dest('dist/'));
  71. return gulp.src('src/icon64x64.png').pipe(gulp.dest('dist/'));
  72. });
  73. gulp.task('fonts', function() {
  74. //return gulp.src('node_modules/font-awesome/fonts/*').pipe(gulp.dest('dist/fonts/'));
  75. gulp.src('node_modules/font-awesome/fonts/fontawesome-webfont.woff').pipe(gulp.dest('dist/fonts/'));
  76. gulp.src('node_modules/weather-icons-lite/fonts/weather-icons-lite.woff').pipe(gulp.dest('dist/fonts/'));
  77. gulp.src('node_modules/font-awesome/fonts/fontawesome-webfont.woff2').pipe(gulp.dest('dist/fonts/'));
  78. gulp.src('node_modules/weather-icons-lite/fonts/weather-icons-lite.woff2').pipe(gulp.dest('dist/fonts/'));
  79. return;
  80. });
  81. gulp.task('js', function () {
  82. var scripts = gulp.src('src/index.html')
  83. .pipe(ghtmlSrc({getFileName:getFileName.bind(this, 'src')}));
  84. var templates = gulp.src(['src/**/*.html', '!src/index.html'])
  85. .pipe(minifyHTML({collapseWhitespace:true, conservativeCollapse:true}))
  86. .pipe(templateCache('templates.js', {root:'', module:'ui'}));
  87. var tiny = gulp.src('node_modules/tinycolor2/dist/tinycolor-min.js')
  88. .pipe(eol('\n'))
  89. .pipe(gulp.dest('./dist/js'));
  90. var i18n = gulp.src('src/i18n.js')
  91. .pipe(eol('\n'))
  92. .pipe(gulp.dest('dist/'));
  93. return streamqueue({ objectMode:true }, scripts, templates)
  94. .pipe(gulpif(/[.]min[.]js$/, gutil.noop(), uglify()))
  95. .pipe(concat('app.min.js'))
  96. .pipe(header(fs.readFileSync('license.js')))
  97. .pipe(eol('\n'))
  98. .pipe(gulp.dest('dist/js/'));
  99. });
  100. gulp.task('css', function () {
  101. exec('node fixfa.js', function (err, stdout, stderr) {
  102. if (err) {
  103. console.log(stdout);
  104. console.log(stderr);
  105. }
  106. });
  107. return gulp.src('src/index.html')
  108. .pipe(ghtmlSrc({getFileName:getFileName.bind(this, 'href'), presets:'css'}))
  109. .pipe(minifyCss({compatibility:'ie8'}))
  110. .pipe(concat('app.min.css'))
  111. .pipe(header(fs.readFileSync('license.js')))
  112. .pipe(eol('\n'))
  113. .pipe(gulp.dest('dist/css/'));
  114. });
  115. gulp.task('less', function() {
  116. return gulp.src(['src/*.less'])
  117. .pipe(concat('app.min.less'))
  118. .pipe(header(fs.readFileSync('license.js')))
  119. .pipe(eol('\n'))
  120. .pipe(gulp.dest('./dist/css'));
  121. });
  122. gulp.task('gridstack', function() {
  123. gulp.src('node_modules/gridstack/dist/gridstack.min.css').pipe(gulp.dest('dist/css/'));
  124. gulp.src('node_modules/gridstack/dist/gridstack.jQueryUI.min.js').pipe(gulp.dest('dist/js/'));
  125. gulp.src('node_modules/gridstack/dist/gridstack.min.js').pipe(gulp.dest('dist/js/'));
  126. gulp.src('node_modules/gridstack/dist/gridstack.min.map').pipe(gulp.dest('dist/js/'));
  127. gulp.src('node_modules/lodash/lodash.min.js').pipe(gulp.dest('dist/js/'));
  128. gulp.src('node_modules/gridstack/src/gridstack-extra.scss')
  129. .pipe(replace('$gridstack-columns: 12 !default;','$gridstack-columns: 30;'))
  130. .pipe(sass({outputStyle: 'compressed'}))
  131. .pipe(rename({extname: '.min.css'}))
  132. .pipe(gulp.dest('dist/css'))
  133. return;
  134. });
  135. var vendorPrefix = "vendor/";
  136. function getFileName(attr, node) {
  137. var file = node.attr(attr);
  138. if (file.indexOf(vendorPrefix) === 0) {
  139. file = path.join("..", "node_modules", file.substr(vendorPrefix.length));
  140. }
  141. return file;
  142. }