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 | | |
14 | 1 | 'use strict'; |
15 | | |
16 | 1 | var util = require('util'); |
17 | 1 | var path = require('path'); |
18 | 1 | var fs = require('fs'); |
19 | 1 | var yeoman = require('yeoman-generator'); |
20 | | |
21 | | |
22 | 1 | var DalekjsGenerator = module.exports = function DalekjsGenerator(args, options) { |
23 | 0 | yeoman.generators.Base.apply(this, arguments); |
24 | | |
25 | 0 | this.on('end', function () { |
26 | 0 | this.installDependencies({ skipInstall: options['skip-install'], bower: false }); |
27 | | }); |
28 | | |
29 | 0 | this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json'))); |
30 | | }; |
31 | | |
32 | 1 | util.inherits(DalekjsGenerator, yeoman.generators.Base); |
33 | | |
34 | 1 | DalekjsGenerator.prototype.askFor = function askFor() { |
35 | 0 | var cb = this.async(); |
36 | | |
37 | 0 | var prompts = []; |
38 | | |
39 | | // Test setup |
40 | | // ---------- |
41 | | |
42 | 0 | prompts.push({ |
43 | | name: 'testfolder', |
44 | | message: 'In which folder should I generate your DalekJS tests?', |
45 | | default: 'test' |
46 | | }); |
47 | | |
48 | 0 | 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 | | |
58 | 0 | prompts.push({ |
59 | | type: 'confirm', |
60 | | name: 'browser', |
61 | | message: 'Would you like to run other browsers than PhantomJS?', |
62 | | default: false |
63 | | }); |
64 | | |
65 | 0 | var browsers = { |
66 | | type: 'checkbox', |
67 | | name: 'browsers', |
68 | | message: 'Please select a browser', |
69 | | choices: [], |
70 | | when: function (props) { |
71 | 0 | return props.browser; |
72 | | } |
73 | | }; |
74 | | |
75 | 0 | browsers.choices.push({ |
76 | | value: 'chrome', |
77 | | name: 'Google Chrome', |
78 | | checked: false |
79 | | }); |
80 | | |
81 | 0 | browsers.choices.push({ |
82 | | value: 'firefox', |
83 | | name: 'Mozilla Firefox & Firefox OS', |
84 | | checked: false |
85 | | }); |
86 | | |
87 | 0 | if (process.platform === 'darwin') { |
88 | 0 | browsers.choices.push({ |
89 | | value: 'ios', |
90 | | name: 'Safari on iOS', |
91 | | checked: false |
92 | | }); |
93 | | } |
94 | | |
95 | 0 | if (process.platform === 'win32') { |
96 | 0 | browsers.choices.push({ |
97 | | value: 'ie', |
98 | | name: 'Microsoft Internet Explorer', |
99 | | checked: false |
100 | | }); |
101 | | } |
102 | | |
103 | 0 | prompts.push(browsers); |
104 | | |
105 | | // Reporter plugins |
106 | | // ---------------- |
107 | | |
108 | 0 | 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 | | |
115 | 0 | 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) { |
129 | 0 | return props.reporter; |
130 | | } |
131 | | }); |
132 | | |
133 | | // Suite scaffolding |
134 | | // ----------------- |
135 | | |
136 | | // should I add a basic test for you |
137 | 0 | 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 |
145 | 0 | prompts.push({ |
146 | | name: 'suitname', |
147 | | message: 'What is the name of your first testsuite?', |
148 | | default: 'First test', |
149 | | when: function (props) { |
150 | 0 | return props.generateDummySuite; |
151 | | } |
152 | | }); |
153 | | |
154 | | // javascript or coffeescript |
155 | 0 | 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) { |
161 | 0 | return props.generateDummySuite; |
162 | | } |
163 | | }); |
164 | | |
165 | 0 | this.prompt(prompts, function (props) { |
166 | 0 | this.testfolder = props.testfolder; |
167 | 0 | this.grunt = props.grunt; |
168 | 0 | this.browser = props.browser; |
169 | 0 | this.browsers = props.browsers; |
170 | 0 | this.reporter = props.reporter; |
171 | 0 | this.reporters = props.reporters; |
172 | 0 | this.generateDummySuite = props.generateDummySuite; |
173 | 0 | this.isCoffee = props.isCoffee; |
174 | | |
175 | 0 | cb(); |
176 | | }.bind(this)); |
177 | | }; |
178 | | |
179 | 1 | DalekjsGenerator.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 |
184 | 0 | 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 |
191 | 0 | if (this.grunt) { |
192 | | // check if a package json exists, if not, copy over a basic one |
193 | 0 | 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 |
200 | 0 | if (this.generateDummySuite) { |
201 | | //this.copy('_dummyTest.js', this.testfolder + '/' + this.testname + '.js'); |
202 | | } |
203 | | |
204 | | }; |
205 | | |