generator-f6html
Version:
Paquete básico para proyectos Fullsix en HTML5, responsive, bootstrap y con SASS
466 lines (413 loc) • 11.5 kB
JavaScript
'use strict';
var generators = require('yeoman-generator');
var yosay = require('yosay');
var chalk = require('chalk');
var wiredep = require('wiredep');
var mkdirp = require('mkdirp');
var _s = require('underscore.string');
module.exports = generators.Base.extend({
constructor: function () {
var testLocal;
generators.Base.apply(this, arguments);
this.option('skip-welcome-message', {
desc: 'Skips the welcome message',
type: Boolean
});
this.option('skip-install-message', {
desc: 'Skips the message after the installation of dependencies',
type: Boolean
});
},
initializing: function () {
this.pkg = require('../package.json');
},
askFor: function () {
var done = this.async();
if (!this.options['skip-welcome-message']) {
this.log(yosay('¡Fullsix Yeoman para crear proyectos molones y optimizados!'));
}
var prompts = [{
type: 'input',
name: 'name',
message: '¿Nombre del proyecto?',
store : true,
default : this.appname
}, {
type: 'checkbox',
name: 'features',
message: '¿De esto qué es lo que tu quieres?',
choices: [{
name: 'Sass',
value: 'includeSass',
checked: false
}, {
name: 'Bootstrap',
value: 'includeBootstrap',
checked: false
}, {
name: 'Materialize',
value: 'includeMaterialize',
checked: false
}, {
name: 'Modernizr',
value: 'includeModernizr',
checked: true
}]
}, {
type: 'confirm',
name: 'includeJQuery',
message: '¿Le metemos también jQuery o ke ase?',
default: true,
when: function (answers) {
return answers.features.indexOf('includeBootstrap') === -1;
}
}];
this.prompt(prompts, function (answers) {
var features = answers.features;
function hasFeature(feat) {
return features && features.indexOf(feat) !== -1;
}
this.includeSass = hasFeature('includeSass');
this.includeBootstrap = hasFeature('includeBootstrap');
this.includeMaterialize = hasFeature('includeMaterialize');
this.includeModernizr = hasFeature('includeModernizr');
this.includeJQuery = answers.includeJQuery;
//this.includeGSAP = answers.includeGSAP;
this.name = answers.name;
done();
}.bind(this));
},
writing: {
gruntfile: function () {
this.fs.copyTpl(
this.templatePath('Gruntfile.js'),
this.destinationPath('Gruntfile.js'),
{
pkg: this.pkg,
includeSass: this.includeSass,
includeBootstrap: this.includeBootstrap,
includeMaterialize: this.includeMaterialize,
includeModernizr: this.includeModernizr,
//includeGSAP: this.includeGSAP,
//useBabel: this.options['babel']
}
);
},
/*
gsap: function() {
if (this.includeGSAP) {
this.directory('lib','src/script');
}
},
*/
packageJSON: function () {
this.fs.copyTpl(
this.templatePath('_package.json'),
this.destinationPath('package.json'),
{
includeSass: this.includeSass,
includeModernizr: this.includeModernizr,
includeMaterialize: this.includeMaterialize,
includeJQuery: this.includeBootstrap || this.includeJQuery,
//useBabel: this.options['babel']
}
)
},
git: function () {
this.fs.copy(
this.templatePath('gitignore'),
this.destinationPath('.gitignore')
);
this.fs.copy(
this.templatePath('gitattributes'),
this.destinationPath('.gitattributes')
);
},
bower: function () {
var bowerJson = {
name: _s.slugify(this.appname),
private: true,
dependencies: {}
};
if (this.includeBootstrap) {
if (this.includeSass) {
bowerJson.dependencies['bootstrap-sass'] = '~3.3.5';
bowerJson.overrides = {
'bootstrap-sass': {
'main': [
'assets/stylesheets/_bootstrap.scss',
'assets/fonts/bootstrap/*',
'assets/javascripts/bootstrap.js'
]
}
};
} else {
bowerJson.dependencies['bootstrap'] = '~3.3.5';
bowerJson.overrides = {
'bootstrap': {
'main': [
'less/bootstrap.less',
'dist/css/bootstrap.css',
'dist/js/bootstrap.js',
'dist/fonts/*'
]
}
};
}
} else if (this.includeJQuery) {
bowerJson.dependencies['jquery'] = '~2.1.4';
}
if (this.includeModernizr) {
bowerJson.dependencies['modernizr'] = '~2.8.3';
}
if (this.includeMaterialize) {
bowerJson.dependencies['materialize'] = '^0.97.5';
}
this.fs.writeJSON('bower.json', bowerJson);
this.fs.copy(
this.templatePath('bowerrc'),
this.destinationPath('.bowerrc')
);
},
editorConfig: function () {
this.fs.copy(
this.templatePath('editorconfig'),
this.destinationPath('.editorconfig')
);
},
scripts: function () {
this.fs.copy(
this.templatePath('main.js'),
this.destinationPath('src/script/main.js')
);
this.fs.copy(
this.templatePath('f6.cookies.js'),
this.destinationPath('src/script/ui/f6.cookies.js')
);
},
styles: function () {
var stylesheet;
if (this.includeSass) {
stylesheet = 'main.scss';
} else {
stylesheet = 'main.css';
}
this.fs.copyTpl(
this.templatePath(stylesheet),
this.destinationPath('src/styles/' + stylesheet),
{
includeBootstrap: this.includeBootstrap
}
)
},
baseStyles: function () {
var bases;
if (this.includeSass) {
bases = '_base.scss';
} else {
bases = 'base.css';
}
this.fs.copyTpl(
this.templatePath(bases),
this.destinationPath('src/styles/base/' + bases),
{
includeBootstrap: this.includeBootstrap
}
)
},
resetStyle: function () {
var reset;
if (this.includeSass) {
reset = '_reset.scss';
} else {
reset = 'reset.css';
}
this.fs.copyTpl(
this.templatePath(reset),
this.destinationPath('src/styles/base/' + reset),
{
includeBootstrap: this.includeBootstrap
}
)
},
menuStyle: function () {
var menu;
if (this.includeSass) {
menu = '_menu.scss';
} else {
menu = 'menu.css';
}
this.fs.copyTpl(
this.templatePath(menu),
this.destinationPath('src/styles/base/' + menu)
)
},
cookieStyle: function () {
var cookie;
if (this.includeSass) {
cookie = '_layer-cookies.scss';
} else {
cookie = 'layer-cookies.css';
}
this.fs.copyTpl(
this.templatePath(cookie),
this.destinationPath('src/styles/base/' + cookie)
)
},
html: function () {
var bsPath;
// path prefix for Bootstrap JS files
if (this.includeBootstrap) {
if (this.includeSass) {
bsPath = '../bower_components/bootstrap-sass/assets/javascripts/bootstrap/';
} else {
bsPath = '../bower_components/bootstrap/js/';
}
}
this.fs.copyTpl(
this.templatePath('_footer.html'),
this.destinationPath('src/_footer.html'),
{
appname: this.name,
includeSass: this.includeSass,
includeBootstrap: this.includeBootstrap,
includeModernizr: this.includeModernizr,
bsPath: bsPath,
bsPlugins: [
'affix',
'alert',
'dropdown',
'tooltip',
'modal',
'transition',
'button',
'popover',
'carousel',
'scrollspy',
'collapse',
'tab'
]
}
);
this.fs.copyTpl(
this.templatePath('_header.html'),
this.destinationPath('src/_header.html'),
{
appname: this.name,
includeSass: this.includeSass,
includeBootstrap: this.includeBootstrap,
includeModernizr: this.includeModernizr,
bsPath: bsPath,
bsPlugins: [
'affix',
'alert',
'dropdown',
'tooltip',
'modal',
'transition',
'button',
'popover',
'carousel',
'scrollspy',
'collapse',
'tab'
]
}
);
this.fs.copyTpl(
this.templatePath('index.shtml'),
this.destinationPath('src/index.shtml'),
{
appname: this.name,
includeSass: this.includeSass,
includeBootstrap: this.includeBootstrap,
includeModernizr: this.includeModernizr,
bsPath: bsPath,
bsPlugins: [
'affix',
'alert',
'dropdown',
'tooltip',
'modal',
'transition',
'button',
'popover',
'carousel',
'scrollspy',
'collapse',
'tab'
]
}
);
this.fs.copyTpl(
this.templatePath('_nav.html'),
this.destinationPath('src/_nav.html')
);
},
icons: function () {
this.fs.copy(
this.templatePath('favicon.ico'),
this.destinationPath('src/favicon.ico')
);
this.fs.copy(
this.templatePath('apple-touch-icon.png'),
this.destinationPath('src/apple-touch-icon.png')
);
},
robots: function () {
this.fs.copy(
this.templatePath('robots.txt'),
this.destinationPath('src/robots.txt')
);
},
/*
components: function() {
this.directory('components','src/components');
},*/
misc: function () {
mkdirp('src/styles/layout');
mkdirp('src/styles/ui');
mkdirp('src/styles/base');
mkdirp('src/styles/base/fonts');
mkdirp('src/script/ui');
mkdirp('src/imgs');
mkdirp('mat');
mkdirp('backups');
}
},
install: function () {
this.installDependencies({
skipInstall: this.options['skip-install'],
skipMessage: this.options['skip-install-message']
});
},
end: function () {
var bowerJson = this.fs.readJSON(this.destinationPath('bower.json'));
var howToInstall =
'\nAfter running ' +
chalk.yellow.bold('npm install & bower install') +
', inject your' +
'\nfront end dependencies by running ' +
chalk.yellow.bold('grunt wiredep') +
'.';
if (this.options['skip-install']) {
this.log(howToInstall);
return;
}
// wire Bower packages to .html
wiredep({
bowerJson: bowerJson,
src: 'pre/index.html',
exclude: ['bootstrap.js'],
ignorePath: /^(\.\.\/)*\.\./
});
if (this.includeSass) {
// wire Bower packages to .scss
wiredep({
bowerJson: bowerJson,
src: 'src/styles/*.scss',
ignorePath: /^(\.\.\/)+/
});
}
}
});