Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/schedule #139

Merged
merged 10 commits into from
Oct 22, 2018
Merged
85 changes: 73 additions & 12 deletions 2018/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const fs = require('fs');
const fse = require('fse');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is fse ? I would like to be simple, fs is better, if you need promise, use fs.promises or bluebird instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs.promises seems less well maintained than fse ?!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, fs.promises is a new feature for node.js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gulp 3.9.1 is broken for Node.js 10 nodejs/node#19786 (comment)

I would need to update Gulp to the 4 beta to use fs.promises

const gulp = require('gulp');
const util = require('gulp-util');
const plumber = require('gulp-plumber');
Expand All @@ -12,12 +12,14 @@ const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const uglify = require('gulp-uglify');
const del = require('del');
const confCal = require('conf-cal');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conf-cal is a csv parser?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conf-cal is a parser for the conf-cal textformat parser.

I made the conf-cal concept to make it easy for us to maintain: Here is the raw-data used:

conference.confcal
interactive.confcal


const srcDirs = {
html: './src/html',
json: './src/json',
js: './src/js',
css: './src/scss',
confcal: './src/confcal',
};
const srcPaths = {
html: `${srcDirs.html}/*.ejs`,
Expand All @@ -26,30 +28,88 @@ const srcPaths = {
};
const destPath = './';

const json = fs.readdirSync('./src/json')
.map(fName => fName.split('.json')[0])
.reduce((cur, acc) => {
return Object.assign(cur, { [acc]: require(`./src/json/${acc}.json`) });
}, {});
function readSchedule () {
const calendar = {};
return fse.readdir(`${__dirname}/src/confcal`)
.then(fNames =>
fNames.map(fName => {
const parts = /^([^.]*).confcal$/.exec(fName);
if (parts) {
return parts[1];
}
}).filter(Boolean)
)
.then(days => Promise.all(days.map(day => {
const filePath = `${__dirname}/src/confcal/${day}.confcal`;
return fse.readFile(filePath, 'utf8')
.then(data => confCal({
apiKey: process.env.GOOGLE_API_KEY,
cache: `${__dirname}/src/confcal/geo.cache`
}, data))
.then(data => {
data.day = day;
return data;
})
.catch(error => {
error.message = `Error reading ${filePath}: ${error.message}`;
return Promise.reject(error);
})
})))
.then(cals => {
for (const cal of cals.sort((a, b) => a.date > b.date)) {
calendar[cal.day] = cal;
}
})
.then(() => calendar)
}

function readJsonsTo (allData) {
return fse.readdir(`${__dirname}/src/json`)
.then(fNames => fNames.map(fName => fName.split('.json')[0]))
.then(names => Promise.all(
names.map(name => {
const filePath = `${__dirname}/src/json/${name}.json`;
return fse.readFile(filePath, 'utf8')
.then(data => JSON.parse(data))
.then(data => allData[name] = data)
.catch(err => Promise.reject(new Error(`Error reading ${filePath}: ${err.message}`)));
})
))
}

gulp.task('html', () => {
return gulp
function readData () {
const allData = {
momentTz: require('moment-timezone'),
isSpeakerForEntry (entry, speaker) {
return entry.person === speaker.name || entry.person === speaker['氏名'] || entry.person === speaker.nickName
}

};
return Promise.all([
readSchedule().then(calendar => allData.calendar = calendar),
readJsonsTo(allData)
])
.then(() => allData);
}

gulp.task('html', () => readData().then(data => new Promise((resolve, reject) => {
const stream = gulp
.src(srcPaths.html)
.pipe(plumber((error) => {
util.log(util.colors.red(error.message));
gulp.task('html').emit('end');
resolve();
}))
.pipe(ejs(json, {}, { ext: '.html' }))
.pipe(ejs(data, {}, { ext: '.html' }))
.pipe(gulp.dest(destPath));
});
stream.on('end', () => resolve());
})));

gulp.task('css', () => {
return gulp
.src(srcPaths.css)
.pipe(plumber((error) => {
util.log(util.colors.red(error.message));
gulp.task('css').emit('end');
// gulp.task('css').emit('end');
}))
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer())
Expand All @@ -75,6 +135,7 @@ gulp.task('js', () => {
gulp.task('watch', () => {
gulp.watch(`${srcDirs.html}/**/*.ejs`, ['html']);
gulp.watch(`${srcDirs.json}/**/*.json`, ['html']);
gulp.watch(`${srcDirs.confcal}/**/*.confcal`, ['html']);
gulp.watch(`${srcDirs.css}/**/*.scss`, ['css']);
gulp.watch(`${srcDirs.js}/**/*.js`, ['js']);
});
Expand Down
Loading