generator-gitbook-base
Version:
95 lines (81 loc) • 2.59 kB
JavaScript
'use strict';
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var GitbookBaseGenerator = yeoman.generators.Base.extend({
init: function () {
this.pkg = require('../package.json');
this.on('end', function () {
if (!this.options['skip-install']) {
this.installDependencies();
}
});
},
askFor: function () {
var done = this.async();
// have Yeoman greet the user
this.log(this.yeoman);
// replace it with a short and sweet description of your generator
this.log(chalk.magenta('You\'re using the fantastic GitbookBase generator.'));
var prompts = [{
type: 'confirm',
name: 'github',
message: 'Will you be hosting on github?',
default: true
},
{
name:'title',
message:'What would you like to name your gitbook',
},
{
name:'desc',
message:'Description of Book:',
},
{ name:'github_url',
message:'What is the name of your github url',
},
{ name:'github_user',
message:'What is your github username?',
}];
this.prompt(prompts, function (props) {
this.github = props.github;
this.title = props.title;
this.desc = props.desc;
if(this.github) {
this.github_url = props.github_url;
this.github_user = props.github_user;
}
this.mkdir('section1');
this.mkdir('section2');
this.mkdir('section3');
this.mkdir('assets');
this.mkdir(this.title);
this.template('_Gruntfile.js', 'Gruntfile.js');
this.copy('_package.json', 'package.json');
this.template('_README.md', 'README.md');
this.copy('_SUMMARY.md', 'SUMMARY.md');
this.copy('_page.md', 'section1/README.md');
this.copy('_page.md', 'section1/page1.md');
this.copy('_page.md', 'section1/page2.md');
this.copy('_page.md', 'section1/page3.md');
this.copy('_page.md', 'section2/README.md');
this.copy('_page.md', 'section2/page1.md');
this.copy('_page.md', 'section2/page2.md');
this.copy('_page.md', 'section3/README.md');
this.copy('_page.md', 'section3/page3.md');
done();
}.bind(this));
},
app: function () {
this.mkdir('app');
this.mkdir('app/templates');
this.copy('_package.json', 'package.json');
this.copy('_bower.json', 'bower.json');
},
projectfiles: function () {
this.copy('editorconfig', '.editorconfig');
this.copy('jshintrc', '.jshintrc');
}
});
module.exports = GitbookBaseGenerator;