| 
									
										
										
										
											2018-10-05 12:20:51 +01:00
										 |  |  | const fs = require('fs-extra'); | 
					
						
							|  |  |  | const gulp = require('gulp'); | 
					
						
							| 
									
										
										
										
											2019-04-12 16:44:14 +02:00
										 |  |  | const through2 = require('through2'); | 
					
						
							| 
									
										
										
										
											2018-10-05 12:20:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 19:32:49 +00:00
										 |  |  | const { locale } = require('../config/env.json'); | 
					
						
							|  |  |  | const { getChallengesForLang } = require('./getChallenges'); | 
					
						
							| 
									
										
										
										
											2019-04-12 16:44:14 +02:00
										 |  |  | const { testedLangs } = require('./utils'); | 
					
						
							| 
									
										
										
										
											2019-07-26 00:45:31 +05:30
										 |  |  | const lintMarkdown = require('../tools/scripts/lint'); | 
					
						
							| 
									
										
										
										
											2019-04-12 16:44:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Tasks | 
					
						
							|  |  |  |  **/ | 
					
						
							| 
									
										
										
										
											2018-10-05 12:20:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 20:26:37 +01:00
										 |  |  | function generateCurriculum(done) { | 
					
						
							|  |  |  |   return getChallengesForLang(locale) | 
					
						
							| 
									
										
										
										
											2018-10-10 16:20:40 -04:00
										 |  |  |     .then(curriculum => { | 
					
						
							|  |  |  |       fs.ensureFileSync(`./build/curriculum-${locale}.json`); | 
					
						
							| 
									
										
										
										
											2018-10-09 20:26:37 +01:00
										 |  |  |       fs.writeFile( | 
					
						
							|  |  |  |         `./build/curriculum-${locale}.json`, | 
					
						
							|  |  |  |         JSON.stringify(curriculum) | 
					
						
							| 
									
										
										
										
											2019-02-16 08:37:36 +00:00
										 |  |  |       ); | 
					
						
							| 
									
										
										
										
											2018-10-10 16:20:40 -04:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2018-10-05 12:20:51 +01:00
										 |  |  |     .then(done); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function watchFiles() { | 
					
						
							| 
									
										
										
										
											2018-10-09 20:26:37 +01:00
										 |  |  |   return gulp.watch('./challenges/**/*.md', generateCurriculum); | 
					
						
							| 
									
										
										
										
											2018-10-05 12:20:51 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-12 16:44:14 +02:00
										 |  |  | function lint() { | 
					
						
							|  |  |  |   return gulp.src(globLangs(testedLangs()), { read: false }).pipe( | 
					
						
							|  |  |  |     through2.obj(function obj(file, enc, next) { | 
					
						
							| 
									
										
										
										
											2019-06-13 11:26:08 +02:00
										 |  |  |       lintMarkdown(file, next); | 
					
						
							| 
									
										
										
										
											2019-04-12 16:44:14 +02:00
										 |  |  |     }) | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 20:26:37 +01:00
										 |  |  | const defaultTask = gulp.series(generateCurriculum, watchFiles); | 
					
						
							| 
									
										
										
										
											2018-10-05 12:20:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-12 16:44:14 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Helper functions | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function globLangs(langs) { | 
					
						
							|  |  |  |   return langs.map(lang => `./challenges/${lang}/**/*.md`); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-05 12:20:51 +01:00
										 |  |  | gulp.task('default', defaultTask); | 
					
						
							| 
									
										
										
										
											2018-10-09 20:26:37 +01:00
										 |  |  | gulp.task('build', generateCurriculum); | 
					
						
							| 
									
										
										
										
											2019-04-12 16:44:14 +02:00
										 |  |  | gulp.task('lint', lint); |