You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.6 KiB

  1. /*******************************
  2. Install Tasks
  3. *******************************/
  4. var
  5. // install dependencies
  6. jeditor = require('gulp-json-editor'),
  7. prompt = require('gulp-prompt'),
  8. wrench = require('wrench'),
  9. questions = require('./tasks/questions')
  10. ;
  11. gulp.task('install', 'Set-up project for first time', function () {
  12. console.clear();
  13. gulp
  14. .src('gulpfile.js')
  15. .pipe(prompt.prompt(questions.setup, function(answers) {
  16. var
  17. siteVariable = /@siteFolder .*\'(.*)/mg,
  18. siteDestination = answers.site || config.folders.site,
  19. pathToSite = path.relative(path.resolve(config.folders.theme), path.resolve(siteDestination)).replace(/\\/g,'/'),
  20. sitePathReplace = "@siteFolder : '" + pathToSite + "/';",
  21. configExists = fs.existsSync(config.files.config),
  22. themeConfigExists = fs.existsSync(config.files.theme),
  23. siteExists = fs.existsSync(siteDestination),
  24. jsonSource = (configExists)
  25. ? config.files.config
  26. : config.templates.config,
  27. json = {
  28. paths: {
  29. source: {},
  30. output: {}
  31. }
  32. }
  33. ;
  34. // exit if config exists and user specifies no overwrite
  35. if(answers.overwrite !== undefined && answers.overwrite == 'no') {
  36. return;
  37. }
  38. console.clear();
  39. console.log('Installing');
  40. console.log('------------------------------');
  41. // create site files
  42. if(siteExists) {
  43. console.info('Site folder exists, merging files (no overwrite)', siteDestination);
  44. }
  45. else {
  46. console.info('Creating site theme folder', siteDestination);
  47. }
  48. // copy recursively without overwrite
  49. wrench.copyDirSyncRecursive(config.templates.site, siteDestination, settings.wrench.recursive);
  50. // adjust less variable for site folder location
  51. console.info('Adjusting @siteFolder', sitePathReplace);
  52. if(themeConfigExists) {
  53. gulp.src(config.files.site)
  54. .pipe(plumber())
  55. .pipe(replace(siteVariable, sitePathReplace))
  56. .pipe(chmod(config.permission))
  57. .pipe(gulp.dest(config.folders.theme))
  58. ;
  59. }
  60. else {
  61. console.info('Creating src/theme.config (LESS config)');
  62. gulp.src(config.templates.theme)
  63. .pipe(plumber())
  64. .pipe(rename({ extname : '' }))
  65. .pipe(replace(siteVariable, sitePathReplace))
  66. .pipe(chmod(config.permission))
  67. .pipe(gulp.dest(config.folders.theme))
  68. ;
  69. }
  70. // determine semantic.json config
  71. if(answers.components) {
  72. json.components = answers.components;
  73. }
  74. if(answers.permission) {
  75. json.permission = +answers.permission;
  76. }
  77. if(answers.dist) {
  78. answers.dist = answers.dist;
  79. json.paths.output = {
  80. packaged : answers.dist + '/',
  81. uncompressed : answers.dist + '/components/',
  82. compressed : answers.dist + '/components/',
  83. themes : answers.dist + '/themes/'
  84. };
  85. }
  86. if(answers.rtl) {
  87. json.rtl = (answers.rtl == 'yes')
  88. ? true
  89. : false
  90. ;
  91. }
  92. if(answers.site) {
  93. json.paths.source.site = answers.site + '/';
  94. }
  95. if(answers.packaged) {
  96. json.paths.output.packaged = answers.packaged + '/';
  97. }
  98. if(answers.compressed) {
  99. json.paths.output.compressed = answers.compressed + '/';
  100. }
  101. if(answers.uncompressed) {
  102. json.paths.output.uncompressed = answers.uncompressed + '/';
  103. }
  104. // write semantic.json
  105. if(configExists) {
  106. console.info('Extending semantic.json (Gulp config)');
  107. gulp.src(jsonSource)
  108. .pipe(plumber())
  109. .pipe(rename(settings.rename.json)) // preserve file extension
  110. .pipe(jeditor(json))
  111. .pipe(chmod(config.permission))
  112. .pipe(gulp.dest('./'))
  113. ;
  114. }
  115. else {
  116. console.info('Creating semantic.json (Gulp config)');
  117. gulp.src(jsonSource)
  118. .pipe(plumber())
  119. .pipe(rename({ extname : '' })) // remove .template from ext
  120. .pipe(jeditor(json))
  121. .pipe(chmod(config.permission))
  122. .pipe(gulp.dest('./'))
  123. ;
  124. }
  125. console.log('');
  126. console.log('');
  127. }))
  128. .pipe(prompt.prompt(questions.cleanup, function(answers) {
  129. if(answers.cleanup == 'yes') {
  130. del(config.setupFiles);
  131. }
  132. if(answers.build == 'yes') {
  133. config = require(config.files.config);
  134. getConfigValues();
  135. gulp.start('build');
  136. }
  137. }))
  138. ;
  139. });