Skip to content

Commit

Permalink
feat: 🎸 WIP add new generators
Browse files Browse the repository at this point in the history
Adding genertaors for markdown page, test, template, react component and
open source project.
  • Loading branch information
seanWLawrence committed Aug 28, 2018
1 parent 73990be commit 85e7538
Show file tree
Hide file tree
Showing 15 changed files with 347 additions and 58 deletions.
1 change: 1 addition & 0 deletions bin/generators/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";
1 change: 1 addition & 0 deletions bin/generators/jest-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";
1 change: 1 addition & 0 deletions bin/generators/mustache-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";
1 change: 1 addition & 0 deletions bin/generators/open-source-project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";
1 change: 1 addition & 0 deletions bin/generators/react-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";
76 changes: 76 additions & 0 deletions bin/generators/vanilla-website.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = main;

var _markdownIt = _interopRequireDefault(require("markdown-it"));

var _path = require("path");

var _fs = require("fs");

var _mustache = require("mustache");

var _slugify = _interopRequireDefault(require("./utils/slugify"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
* Creates the generator that parses markdown files, runs them through the layout template
* and adds the finished HTML files to the public/ directory
* @summary Generator for markdown files
* @author Sean W. Lawrence
* @license MIT
* @module generator
*/
function getMarkdown(filename) {
var markdownFile = (0, _path.join)(markdownPath, filename);
var markdown = (0, _fs.readFileSync)(markdownFile, 'utf8');
return {
filename: filename,
markdown: markdown
};
}

function renderMarkdown(markdown) {
var md = new _markdownIt.default({
html: true
});
md.use(require('markdown-it-anchor'), {
permalink: true,
permalinkBefore: true,
permalinkSymbol: '🔗',
slugify: _slugify.default
});
return md.render(markdown);
}

function renderLayout(html) {
return (0, _mustache.render)(layout, {
title: 'Demo site',
html: html,
lozad: require('lozad').toString()
});
}

function createHTMLFile(filename, html) {
filename = "public/".concat(filename.split('.')[0], ".html");
(0, _fs.writeFileSync)(filename, html);
}

var markdownPath = (0, _path.join)(__dirname, '..', 'src', 'markdown');
var templatePath = (0, _path.join)(__dirname, '..', 'src', 'templates/layout.mustache');
var allMarkdownFiles = (0, _fs.readdirSync)(markdownPath).map(getMarkdown);
var layout = (0, _fs.readFileSync)(templatePath, 'utf8');

function main() {
allMarkdownFiles.forEach(function (md) {
var filename = md.filename,
markdown = md.markdown;
var html = renderMarkdown(markdown);
var result = renderLayout(html);
createHTMLFile(filename, result);
});
}
181 changes: 181 additions & 0 deletions bin/prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
"use strict";

var _inquirer = require("inquirer");

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

(0, _inquirer.prompt)([{
message: 'What are we creating?',
type: 'list',
name: 'type',
choices: ['React component', 'Mustache template', 'Open source project', 'Markdown page', 'Test'],
default: 'React component',
validate: function validate(answer) {
switch (answer) {
case 'React component':
case 'Mustache template':
case 'Open source project':
case 'Markdown page':
case 'Test':
return true;

default:
return false;
}
},
filter: function filter(answer) {
switch (answer) {
case 'React component':
return 'component';

case 'Mustache template':
return 'template';

case 'Open source project':
return 'project';

case 'Markdown page':
return 'markdown';

case 'Test':
return 'test';

default:
return;
}
}
}, {
message: 'What are we naming it?',
type: 'input',
name: 'name',
filter: function filter(answer) {
return answer.toLowerCase();
}
}, {
message: 'What does it do?',
type: 'input',
name: 'description',
when: function when(answers) {
switch (answers.type) {
case 'component':
case 'project':
return true;

default:
return false;
}
}
}, {
message: 'Are you using Flow.js for static type checking?',
type: 'list',
name: 'flow',
choices: ['Yes', 'No'],
filter: function filter(answer) {
switch (answer) {
case 'Yes':
return true;

case 'No':
return false;
}
},
when: function when(answers) {
return answers.type === 'component' || answers.type === 'project';
}
}, {
message: 'List your component\'s props separated by a space, i.e. prop1 prop2 prop3',
type: 'input',
name: 'props',
when: function when(answers) {
return answers.type === 'React component' && answers.flow === false;
},
filter: function filter(answer) {
return answer.split(' ');
}
}, {
message: 'List your component\'s props and types separated by a space, i.e. <prop-name>:<type> <another-prop-name>:<type>',
type: 'input',
name: 'propsWithTypes',
when: function when(answers) {
return answers.type === 'React component' && answers.flow === true;
},
filter: function filter(answer) {
return answer.split(' ').reduce(function (acc, next) {
next = next.split(':');

var _next = next,
_next2 = _slicedToArray(_next, 2),
name = _next2[0],
type = _next2[1];

return acc.concat({
name: name,
type: type
});
}, []);
}
}, {
message: 'List your Markdown page\'s frontmatter separated by a space, i.e. <prop-name>:<value> <another-prop-name>:<value>',
type: 'input',
name: 'frontmatter',
when: function when(answers) {
return answers.type === 'markdown';
},
filter: function filter(answer) {
return answer.split(' ').reduce(function (acc, next) {
next = next.split(':');

var _next3 = next,
_next4 = _slicedToArray(_next3, 2),
name = _next4[0],
value = _next4[1];

return acc.concat({
name: name,
value: value
});
}, []);
}
}, {
message: 'What are we testing?',
type: 'input',
name: 'testDescription',
when: function when(answers) {
return answers.type === 'test';
}
}, {
message: 'What type of test is this?',
name: 'testType',
type: 'list',
choices: ['Integration/browser', 'Unit/function'],
when: function when(answers) {
return answers.type === 'test';
},
filter: function filter(answer) {
switch (answer) {
case 'Integration/browser':
return 'integration';

case 'Unit/function':
return 'unit';
}
}
}, {
message: 'List the variables your template will use, separated by spaces, i.e. variable1 variable2 variable3',
name: 'variables',
type: 'input',
when: function when(answers) {
return answers.type === 'template';
},
filter: function filter(answer) {
return answer.split(' ');
}
}]).then(function (answers) {
console.log(answers);
});
Loading

0 comments on commit 85e7538

Please sign in to comment.