Skip to content

Commit

Permalink
fix #8
Browse files Browse the repository at this point in the history
  • Loading branch information
pheyvaer committed May 29, 2019
1 parent 4efb559 commit a4c27c9
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.0.5] - 2019-05-29

### Added
- Support important dates ([#8](https://github.com/kgb-workshop/sad-generator-init/issues/8))

## [0.0.4] - 2019-05-29

### Fixed
Expand All @@ -18,5 +23,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Event location is written to CSV.

[0.0.5]: https://github.com/kgb-workshop/sad-generator-init/compare/v0.0.4...v0.0.5
[0.0.4]: https://github.com/kgb-workshop/sad-generator-init/compare/v0.0.3...v0.0.4
[0.0.3]: https://github.com/kgb-workshop/sad-generator-init/compare/v0.0.2...v0.0.3
30 changes: 29 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const inquirer = require('inquirer');
const fs = require('fs-extra');
const path = require('path');
const validator = require('validator');
const parseTemplate = require('parse-author');
const generate = require('../index');

if (process.argv.length > 2 && (process.argv[2] === '-h' || process.argv[2] === '--help')) {
Expand Down Expand Up @@ -73,6 +74,21 @@ async function start() {
message: 'End date',
default: answers.startdate === '' ? undefined : answers.startdate
},
{
type: 'input',
name: 'importantdates',
message: 'Important dates (date <label> (description))',
validate: (data) => {
const dates = data.split(',');
let i = 0;

while (i < dates.length && validateImportantDateString(dates[i])) {
i ++;
}

return i === dates.length ? true : 'Date and label are required.';
}
},
{
type: 'input',
name: 'location',
Expand All @@ -87,7 +103,19 @@ async function start() {
generate(extend(answers, answers2), process.cwd());
}

function validateImportantDateString(str) {
if (str !== '') {
const date = parseTemplate(str);

return date.name && date.email;
} else {
return true;
}
}

function extend(obj, src) {
Object.keys(src).forEach(function(key) { obj[key] = src[key]; });
Object.keys(src).forEach(function (key) {
obj[key] = src[key];
});
return obj;
}
1 change: 1 addition & 0 deletions help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ It asks for the following:
- Email: main email address of the event.
- Start date: start date of the event.
- Stop date: stop date of the event.
- Important dates: important dates of the event. An important date is described according to the template "date <label> (description)", and multiple important dates are comma-separated. Date and label are required.
- Location: location of the event.
- Super event: super event with which the event is co-located.
33 changes: 30 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const fs = require('fs-extra');
const path = require('path');
const downloadGithub = require('download-git-repo');
const parseAuthor = require('parse-author');
const parseTemplate = require('parse-author');
const replaceInFile = require('replace');
const yarrrml2rml = require('@rmlio/yarrrml-parser/lib/yarrrml2rml');
const N3 = require('n3');
Expand Down Expand Up @@ -38,9 +38,9 @@ function generate(answers, directory) {
writeGeneralInfo(answers);
writeTopics(answers);
writeOrganizers(answers);
writeImportantDates(answers);

// create empty CSV files
fs.writeFileSync(path.resolve(csvPath, 'important-dates.csv'), 'event,date,description');
fs.writeFileSync(path.resolve(csvPath, 'pc.csv'), 'id,name,organization');
fs.writeFileSync(path.resolve(csvPath, 'subtopics.csv'), 'id,subtopic');

Expand Down Expand Up @@ -76,7 +76,7 @@ function writeOrganizers(answers) {

organizers.forEach(organizer => {
if (organizer !== '') {
organizer = parseAuthor(organizer);
organizer = parseTemplate(organizer);

if (organizer.name) {
csv += organizer.name.replace(/ /g, '-').toLowerCase() + ',';
Expand All @@ -99,6 +99,33 @@ function writeOrganizers(answers) {
fs.writeFileSync(path.resolve(csvPath, 'organizers.csv'), csv);
}

function writeImportantDates(answers) {
const importantDates = answers.importantdates.split(',');
let csv = 'event,date,description\n';

importantDates.forEach(importantDate => {
if (importantDate !== '') {
importantDate = parseTemplate(importantDate);

if (importantDate.name && importantDate.email) {
const date = importantDate.name;
const label = importantDate.email;
let description = '';

if (importantDate.url) {
description = importantDate.url;
}

csv += `${label},${date},${description}\n`;
} else {
console.error('An important date should at least have a date and label.');
}
}
});

fs.writeFileSync(path.resolve(csvPath, 'important-dates.csv'), csv);
}

function writeTopics(answers) {
const topics = answers.topics.split(',');
let csv = 'id,name\n';
Expand Down
4 changes: 3 additions & 1 deletion test/expectedoutput/important-dates.csv
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
event,date,description
event,date,description
Submission deadline,2019-04-10,
Notifications,2019-05-15,
1 change: 1 addition & 0 deletions test/generate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ it('Basic test', async function() {
enddate: '2019-05-29',
twitter: 'uni_corn',
location: 'London',
importantdates: '2019-04-10 <Submission deadline>, 2019-05-15 <Notifications>',
superevent: ''
}, actualPath);

Expand Down

0 comments on commit a4c27c9

Please sign in to comment.