﻿const generators = require('yeoman-generator');
const spawn = require('child_process').spawn;

const util = require('../util.js');

const generator = generators.Base.extend({
	// Cannot use arrow notation due to this object not referencing the correct object.
	constructor: function () {
		generators.Base.apply(this, arguments);
		util.generatorConstructor.call(this, util.prompts.app);
	},
	initializing() {
		const done = this.async();

		util.generatorInitializing.call(this, done);
	},
	prompting() {
		return util.generatorPrompting.call(this, util.prompts.app);
	},
	gitInit() {
		if (!this.git.initialised) {
			const done = this.async();
			const gitInit = spawn('git', ['init']);

			gitInit.on('close', () => {
				this.log('Git repository initialised.');
				done();
			});
		}
	},
	gitRemote() {
		if (!this.options.gitRemoteUrl) {
			return;
		}

		if (this.git.remoteUrl !== this.options.gitRemoteUrl) {
			const done = this.async();
			const gitRemote = spawn('git', ['remote', 'add', 'origin', this.options.gitRemoteUrl]);

			gitRemote.on('close', () => {
				this.log(`Git remote url set to "${this.options.gitRemoteUrl}"`);
				done();
			});
		}
	},
	writing() {
		this.copy('.editorconfig');
		this.copy('.gitattributes');
		this.copy('.gitignore');
		this.template('LICENSE.md', 'LICENSE.md', this.options);
		this.template('README.md', 'README.md', this.options);
	}
});

module.exports = generator;

@@ -46,19 +46,19 @@
 ');%0A
+%0A
 const 
-spawn
+util
  = r
@@ -69,66 +69,62 @@
 re('
-child_process').spawn;%0A%0Aconst util = require('../util.js')
+../../util/util.js');%0Aconst prompts = util.prompts.app
 ;%0A%0Ac
@@ -336,17 +336,18 @@
 enerator
-C
+.c
 onstruct
@@ -360,32 +360,23 @@
 l(this, 
-util.
 prompts
-.app
 );%0A%09%7D,%0A%09
@@ -438,17 +438,18 @@
 enerator
-I
+.i
 nitializ
@@ -516,9 +516,10 @@
 ator
-P
+.p
 romp
@@ -534,32 +534,23 @@
 l(this, 
-util.
 prompts
-.app
 );%0A%09%7D,%0A%09
@@ -626,75 +626,28 @@
 ();%0A
+%0A
 %09%09%09
-const gitInit = spawn('git', %5B'init'%5D);%0A%0A%09%09%09gitInit.on('close', 
+util.git.create(
 () =
@@ -881,60 +881,31 @@
 ();%0A
+%0A
 %09%09%09
-const gitRemote = spawn('git', %5B'remote', 'add', 
+util.git.addRemote(
 'ori
@@ -939,36 +939,8 @@
 eUrl
-%5D);%0A%0A%09%09%09gitRemote.on('close'
 , ()

Rework app-generator to work with new util.