1 | 'use strict';
|
2 |
|
3 | var async = require('async');
|
4 | var chalk = require('chalk');
|
5 | var latest = require('github-latest');
|
6 | var path = require('path');
|
7 | var util = require('util');
|
8 | var yeoman = require('yeoman-generator');
|
9 |
|
10 |
|
11 | var WordpressGenerator = function(args, options, config) {
|
12 | yeoman.generators.Base.apply(this, arguments);
|
13 | };
|
14 |
|
15 | util.inherits(WordpressGenerator, yeoman.generators.Base);
|
16 |
|
17 | WordpressGenerator.prototype.getGenesisVersion = function() {
|
18 | if (this.options['genesis-version']) {
|
19 | this.log.info('Defaulting Genesis version to ' + chalk.yellow(this.options['genesis-version']));
|
20 |
|
21 | return false;
|
22 | }
|
23 |
|
24 | var done = this.async();
|
25 |
|
26 | latest('genesis', 'wordpress', function(err, tag) {
|
27 | if (err) {
|
28 | throw err;
|
29 | }
|
30 |
|
31 | this.options['genesis-version'] = tag;
|
32 |
|
33 | done();
|
34 | }.bind(this));
|
35 | };
|
36 |
|
37 | WordpressGenerator.prototype.downloadLatest = function() {
|
38 | if (this.options['genesis-path']) {
|
39 | return false;
|
40 | }
|
41 |
|
42 | var done = this.async();
|
43 |
|
44 | this.log.info('Downloading Genesis WordPress (' + chalk.yellow(this.options['genesis-version']) + ')...');
|
45 |
|
46 | this.remote('genesis', 'wordpress', this.options['genesis-version'], function(err, remote) {
|
47 | if (err) {
|
48 | throw err;
|
49 | }
|
50 |
|
51 | this.options['genesis-path'] = remote.cachePath;
|
52 |
|
53 | done();
|
54 | }.bind(this));
|
55 | };
|
56 |
|
57 | WordpressGenerator.prototype.normalizeCachePath = function() {
|
58 | this.options['genesis-path'] = path.normalize(this.options['genesis-path']);
|
59 |
|
60 | this.log.info('Using Genesis WordPress at ' + chalk.yellow(this.options['genesis-path']) + '...');
|
61 | };
|
62 |
|
63 | WordpressGenerator.prototype.installLatest = function() {
|
64 | var done = this.async();
|
65 | var cwd = process.cwd();
|
66 |
|
67 | this.log.info('Installing dependencies...');
|
68 |
|
69 | process.chdir(this.options['genesis-path']);
|
70 |
|
71 | this.npmInstall(this.options['genesis-path'], ['--quiet'], function() {
|
72 | process.chdir(cwd);
|
73 | done();
|
74 | });
|
75 | };
|
76 |
|
77 | WordpressGenerator.prototype.runLatest = function() {
|
78 | var Genesis = require(this.options['genesis-path']);
|
79 | var options = this.options;
|
80 |
|
81 | options.resolved = require.resolve(this.options['genesis-path']);
|
82 |
|
83 | this.log.info('Running generator...');
|
84 |
|
85 | new Genesis(this.args, this.options, this.config).run();
|
86 | };
|
87 |
|
88 | module.exports = WordpressGenerator;
|