generator-mupal
Version:
Download Drupal and some recommended modules
100 lines (71 loc) • 3.04 kB
JavaScript
;
var path = require('path'),
fs = require('fs'),
yeoman = require('yeoman-generator'),
yosay = require('yosay');
var MupalGenerator = 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(yosay('Welcome to the marvelous Mupal generator!'));
var prompts = [{
type: 'input',
name: 'projectName',
message: 'Name this project'
}];
this.prompt(prompts, function (props) {
this.projectName = props.projectName;
done();
}.bind(this));
},
app: function () {
this.copy('_drush.make', 'drush.make', {force: true});
},
drush: function() {
var _this = this,
done = this.async();
var spawn = require('child_process').spawn,
drush = spawn('drush', ['make', 'drush.make', '-y']);
drush.stdout.pipe(process.stdout);
drush.stderr.pipe(process.stderr);
drush.on('close', function() {
done();
});
},
files: function() {
var _this = this,
packageJson = _this.src.readJSON('_package.json'),
packageThemeName = _this.projectName.replace(' ', '_').toLowerCase();
packageJson.name = _this.projectName.replace(' ', '-');
packageJson.theme = packageJson.theme.replace(/<%=project_theme_name %>/g, packageThemeName);
_this.dest.write('package.json', JSON.stringify(packageJson, null, 4));
_this.dest.delete('.gitignore');
_this.dest.delete('.htaccess');
_this.copy('gitignore', '.gitignore', {force: true});
_this.copy('htaccess', '.htaccess', {force: true});
_this.copy('_Gruntfile.js', 'Gruntfile.js', {force: true});
_this.directory('theme', 'sites/default/themes/' + packageThemeName);
},
theme: function() {
var _this = this,
done = this.async();
var packageJson = _this.src.readJSON('_package.json'),
packageThemeName = _this.projectName.replace(' ', '_').toLowerCase();
var templatePHP = _this.dest.read('sites/default/themes/' + packageThemeName + '/template.php');
templatePHP = templatePHP.replace(/<%=project_theme_name %>/g, packageThemeName);
_this.dest.delete('sites/default/themes/' + packageThemeName + '/template.php');
_this.dest.delete('sites/default/themes/' + packageThemeName + '/theme.info');
_this.dest.write('sites/default/themes/' + packageThemeName + '/template.php', templatePHP);
_this.copy('theme/theme.info', 'sites/default/themes/' + packageThemeName + '/' + packageThemeName + '.info');
done();
}
});
module.exports = MupalGenerator;