|
|
@@ -11,8 +11,11 @@ const uglify = require('gulp-uglify');
|
|
|
const gutil = require('gulp-util');
|
|
|
const zip = require('gulp-zip');
|
|
|
const fs = require('fs');
|
|
|
+const path = require('path');
|
|
|
const es = require('event-stream');
|
|
|
+const Promise = require('bluebird');
|
|
|
|
|
|
+Promise.promisifyAll(fs);
|
|
|
// const archiveFiles = [
|
|
|
// 'style.css',
|
|
|
// 'screenshot.png',
|
|
|
@@ -21,12 +24,9 @@ const es = require('event-stream');
|
|
|
// const builtFiles = [
|
|
|
// 'js/*'
|
|
|
// ];
|
|
|
-// const watchedFiles = [
|
|
|
-// 'style.css',
|
|
|
-// 'screenshot.png',
|
|
|
-// '*.php',
|
|
|
-// 'js/*'
|
|
|
-// ];
|
|
|
+const watchedFiles = [
|
|
|
+ 'src/markdown/**/*'
|
|
|
+];
|
|
|
|
|
|
// const themeName = 'reago';
|
|
|
|
|
|
@@ -52,18 +52,27 @@ function buildClient(watch, done) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-// function extractThemeVersion() {
|
|
|
-// return new Promise((resolve, reject) => {
|
|
|
-// fs.readFile(__dirname + '/style.css', (err, buf) => {
|
|
|
-// if(err) return reject(err);
|
|
|
-// const stylesheet = buf.toString();
|
|
|
-// const versionRegex = /Version\: ([0-9\.]+)/g;
|
|
|
-// const matches = versionRegex.exec(stylesheet);
|
|
|
-// themeVersion = matches[1];
|
|
|
-// resolve(themeVersion);
|
|
|
-// });
|
|
|
-// });
|
|
|
-// }
|
|
|
+function extractMarkdown() {
|
|
|
+ // return new Promise(function (resolve, reject) {
|
|
|
+ return fs.readdirAsync('src/markdown')
|
|
|
+ .then(subdirs => Promise.reduce(
|
|
|
+ subdirs,
|
|
|
+ (carry, dir) =>
|
|
|
+ fs.readdirAsync('src/markdown/' + dir)
|
|
|
+ .then(files => Promise.reduce(
|
|
|
+ files,
|
|
|
+ (carry, f) => fs.readFileAsync('src/markdown/' + dir + '/' + f)
|
|
|
+ .then(buf => buf.toString())
|
|
|
+ .then(content => Object.assign(carry, { [path.basename(f, '.md')]: content })),
|
|
|
+ {}
|
|
|
+ ))
|
|
|
+ .then(content => Object.assign(carry, { [dir]: content })),
|
|
|
+ {}
|
|
|
+ ))
|
|
|
+ .then(JSON.stringify)
|
|
|
+ .then(markdownJson => fs.writeFileAsync('src/markdown.json', markdownJson))
|
|
|
+ // });
|
|
|
+}
|
|
|
|
|
|
// function makeZip(cb) {
|
|
|
// return extractThemeVersion()
|
|
|
@@ -85,13 +94,17 @@ function buildClient(watch, done) {
|
|
|
|
|
|
gulp.task('watch', function() {
|
|
|
gulp.watch(['src'], buildClient);
|
|
|
- // gulp.watch(watchedFiles, makeZip);
|
|
|
+ gulp.watch(watchedFiles, extractMarkdown);
|
|
|
});
|
|
|
|
|
|
gulp.task('buildClient', function() {
|
|
|
return buildClient();
|
|
|
});
|
|
|
|
|
|
+gulp.task('extractMarkdown', function() {
|
|
|
+ return extractMarkdown();
|
|
|
+});
|
|
|
+
|
|
|
// gulp.task('makeZip', makeZip);
|
|
|
|
|
|
-gulp.task('default', gulp.series('buildClient', 'watch'));
|
|
|
+gulp.task('default', gulp.series('buildClient', 'extractMarkdown', 'watch'));
|