gulp-tasks.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. var config = require('../config.json');
  2. module.exports = function(gulp, flags) {
  3. gulp.task('docs', [], function() {
  4. var Dgeni = require('dgeni');
  5. var semver = require('semver');
  6. var docVersion = flags['doc-version'] || 'nightly';
  7. var initialVersionBuild = flags['initial-build'] || false;
  8. if (docVersion != 'nightly' && !semver.valid(docVersion)) {
  9. console.log('Usage: gulp docs --doc-version=(nightly|versionName)\nversionName must be a valid semver version.');
  10. return process.exit(1);
  11. }
  12. try {
  13. var ionicPackage = require('./dgeni-config')(docVersion, initialVersionBuild);
  14. var dgeni = new Dgeni([ionicPackage]);
  15. return dgeni.generate();
  16. } catch (err) {
  17. console.log(err.stack);
  18. }
  19. });
  20. gulp.task('docs.demos', ['demos', 'src', 'temp.hack'], function(){
  21. return gulp.src([
  22. 'dist/**',
  23. '!dist/e2e',
  24. '!dist/e2e/**/*',
  25. '!dist/ionic-site',
  26. '!dist/ionic-site/**/*',
  27. '!dist/src',
  28. '!dist/src/**/*'
  29. ])
  30. .pipe(gulp.dest(config.docsDest + '/dist'));
  31. });
  32. gulp.task('docs.sass-variables', function() {
  33. var fs = require('fs');
  34. var gutil = require('gulp-util');
  35. var es = require('event-stream');
  36. var mkdirp = require('mkdirp');
  37. var path = require('path');
  38. var Entities = require('html-entities').AllHtmlEntities;
  39. entities = new Entities();
  40. var variables = [];
  41. var outputFile = 'tmp/sass.json';
  42. // Add the variable to the array, encode the html and remove !default from the value
  43. function addVariable(variableName, defaultValue, file) {
  44. defaultValue = entities.encode(defaultValue);
  45. defaultValue = defaultValue.replace("!default;", "");
  46. variables.push({
  47. "name": variableName,
  48. "defaultValue": defaultValue.trim(),
  49. "file": path.relative('./', file.path)
  50. });
  51. }
  52. return gulp.src('src/**/*.scss')
  53. .pipe(es.map(function(file, callback) {
  54. var contents = file.contents.toString();
  55. var variableLine, variableName, defaultValue, multiline;
  56. fs.createReadStream(file.path, {flags: 'r'})
  57. .pipe(es.split())
  58. .pipe(es.map(function (line, callback) {
  59. if (line.charAt(0) == '$') {
  60. variableLine = line.split(/:(.+)/);
  61. variableName = variableLine[0];
  62. defaultValue = variableLine[1];
  63. // If there is a semicolon then it isn't a multiline value
  64. multiline = line.indexOf(';') > -1 ? false : true;
  65. if (!multiline && line.indexOf('!default') > -1)
  66. addVariable(variableName, defaultValue, file);
  67. } else if (multiline == true) {
  68. defaultValue += '\n' + line;
  69. // If the line has a semicolon then we've found the end of the value
  70. if (line.indexOf(';') > -1 && line.indexOf('!default') > -1) {
  71. addVariable(variableName, defaultValue, file);
  72. multiline = false;
  73. }
  74. }
  75. callback();
  76. }));
  77. callback();
  78. }).on('end', function() {
  79. gutil.log("Writing to file at", gutil.colors.cyan("/ionic-team/ionic/" + outputFile));
  80. gutil.log("Place this file in", gutil.colors.cyan("/ionic-team/ionic-site/" + config.v2DocsDir + "/theming/overriding-ionic-variables/"), "in order to update the docs");
  81. mkdirp.sync('tmp');
  82. fs.writeFileSync(outputFile, JSON.stringify(variables));
  83. }));
  84. });
  85. }