Coverage

18%
49
9
40

/home/ubuntu/src/github.com/dalekjs/generator-dalek/app/index.js

18%
49
9
40
LineHitsSource
1/**
2 * A generator for Yeoman.
3 *
4 * ## Getting started
5 * - Make sure you have [yo](https://github.com/yeoman/yo) installed:
6 * `npm install -g yo`
7 * - Install the generator: `npm install -g generator-dalekjs`
8 * - Run: `yo dalekjs`
9 *
10 * @part Yeoman
11 * @api
12 */
13
141'use strict';
15
161var util = require('util');
171var path = require('path');
181var fs = require('fs');
191var yeoman = require('yeoman-generator');
20
21
221var DalekjsGenerator = module.exports = function DalekjsGenerator(args, options) {
230 yeoman.generators.Base.apply(this, arguments);
24
250 this.on('end', function () {
260 this.installDependencies({ skipInstall: options['skip-install'], bower: false });
27 });
28
290 this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
30};
31
321util.inherits(DalekjsGenerator, yeoman.generators.Base);
33
341DalekjsGenerator.prototype.askFor = function askFor() {
350 var cb = this.async();
36
370 var prompts = [];
38
39 // Test setup
40 // ----------
41
420 prompts.push({
43 name: 'testfolder',
44 message: 'In which folder should I generate your DalekJS tests?',
45 default: 'test'
46 });
47
480 prompts.push({
49 type: 'confirm',
50 name: 'grunt',
51 message: 'Would you like to run your tests with the help of grunt?',
52 default: true
53 });
54
55 // Browser plugins
56 // ---------------
57
580 prompts.push({
59 type: 'confirm',
60 name: 'browser',
61 message: 'Would you like to run other browsers than PhantomJS?',
62 default: false
63 });
64
650 var browsers = {
66 type: 'checkbox',
67 name: 'browsers',
68 message: 'Please select a browser',
69 choices: [],
70 when: function (props) {
710 return props.browser;
72 }
73 };
74
750 browsers.choices.push({
76 value: 'chrome',
77 name: 'Google Chrome',
78 checked: false
79 });
80
810 browsers.choices.push({
82 value: 'firefox',
83 name: 'Mozilla Firefox & Firefox OS',
84 checked: false
85 });
86
870 if (process.platform === 'darwin') {
880 browsers.choices.push({
89 value: 'ios',
90 name: 'Safari on iOS',
91 checked: false
92 });
93 }
94
950 if (process.platform === 'win32') {
960 browsers.choices.push({
97 value: 'ie',
98 name: 'Microsoft Internet Explorer',
99 checked: false
100 });
101 }
102
1030 prompts.push(browsers);
104
105 // Reporter plugins
106 // ----------------
107
1080 prompts.push({
109 type: 'confirm',
110 name: 'reporter',
111 message: 'Would you like to install some additional reporters (HTML, jUnitXML, etc.)?',
112 default: false
113 });
114
1150 prompts.push({
116 type: 'checkbox',
117 name: 'reporters',
118 message: 'What more would you like?',
119 choices: [{
120 name: 'HTML',
121 value: 'reporterHtml',
122 checked: true
123 }, {
124 name: 'jUnit',
125 value: 'reporterjUnit',
126 checked: false
127 }],
128 when: function (props) {
1290 return props.reporter;
130 }
131 });
132
133 // Suite scaffolding
134 // -----------------
135
136 // should I add a basic test for you
1370 prompts.push({
138 type: 'confirm',
139 name: 'generateDummySuite',
140 message: 'Would you like me to add a basic test for you?',
141 default: true
142 });
143
144 // testsuite name
1450 prompts.push({
146 name: 'suitname',
147 message: 'What is the name of your first testsuite?',
148 default: 'First test',
149 when: function (props) {
1500 return props.generateDummySuite;
151 }
152 });
153
154 // javascript or coffeescript
1550 prompts.push({
156 type: 'confirm',
157 name: 'isCoffee',
158 message: 'Would you like to write your tests in CoffeeScript?',
159 default: false,
160 when: function (props) {
1610 return props.generateDummySuite;
162 }
163 });
164
1650 this.prompt(prompts, function (props) {
1660 this.testfolder = props.testfolder;
1670 this.grunt = props.grunt;
1680 this.browser = props.browser;
1690 this.browsers = props.browsers;
1700 this.reporter = props.reporter;
1710 this.reporters = props.reporters;
1720 this.generateDummySuite = props.generateDummySuite;
1730 this.isCoffee = props.isCoffee;
174
1750 cb();
176 }.bind(this));
177};
178
1791DalekjsGenerator.prototype.app = function app() {
180 // generate the folder where the dalekjs tests should be put
181 //this.mkdir(this.testfolder);
182
183 // check if a package json exists, if not, copy over a basic one
1840 if (!fs.existsSync(process.cwd() + '/package.json')) {
185 //this.copy('_package.json', 'package.json');
186 } else {
187 // modify package.json
188 }
189
190 // check if we should add grunt to the mix
1910 if (this.grunt) {
192 // check if a package json exists, if not, copy over a basic one
1930 if (!fs.existsSync(process.cwd() + '/Gruntfile.js')) {
194 //this.copy('_Gruntfile.json', 'Gruntfile.js');
195 } else {
196 // Give hints on how to add dalek to the gruntfile
197 }
198 }
199 // generate a dummy testsuite & testcase
2000 if (this.generateDummySuite) {
201 //this.copy('_dummyTest.js', this.testfolder + '/' + this.testname + '.js');
202 }
203
204};
205