Skip to content

Commit 3735f89

Browse files
committed
Merge pull request #41 from angularity/fix-defaults
Fix defaults
2 parents 505bc68 + da64ff0 commit 3735f89

File tree

2 files changed

+55
-52
lines changed

2 files changed

+55
-52
lines changed

tasks/init.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ function setUpInitTask(context) {
3434
{
3535
key: 'defaults',
3636
value: {
37-
describe: 'Set defaults',
38-
alias : 'z',
39-
boolean : true,
40-
isOptional: true
37+
describe : 'Set defaults',
38+
alias : 'z',
39+
isOptional: true,
40+
default : false
4141
}
4242
},
4343
{
@@ -151,7 +151,7 @@ function setUpInitTask(context) {
151151
if (tyRun.checkFlagMissing(opt, key, value)) {
152152
return;
153153
}
154-
if (key !== 'port') {
154+
if ((key !== 'port') && (key !== 'defaults')) {
155155
// skip the valid types test for port, as will be done later
156156
// ensure options correspond to the types that they were defined as belonging to
157157
tyRun.checkFlagType(opt, key, value);
@@ -174,6 +174,11 @@ function setUpInitTask(context) {
174174
throw new Error('Port must be an integer, or "random"');
175175
}
176176
}
177+
else if (key === 'defaults') {
178+
if (!(/^(true|false|reset)$/.test(String(argv.defaults)))) {
179+
throw new Error('Unrecognised value for defaults flag, expected true|false|reset.');
180+
}
181+
}
177182
});
178183
return true;
179184
}
@@ -226,8 +231,8 @@ function setUpInitTask(context) {
226231
template = require('lodash.template'),
227232
merge = require('lodash.merge');
228233

229-
var hr = require('../lib/util/hr'),
230-
streams = require('../lib/config/streams');
234+
var hr = require('../lib/util/hr'),
235+
streams = require('../lib/config/streams');
231236

232237
var TEMPLATE_PATH = path.join(__dirname, '..', 'templates', 'angularity');
233238

tasks/webstorm.js

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ function setUpWebStormTask(context) {
88
throw new Error('Context must specify run-sequence instance');
99
}
1010

11-
var fs = require('fs'),
12-
path = require('path'),
13-
ideTemplate = require('ide-template'),
14-
defaults = require('../lib/config/defaults'),
15-
platform = require('../lib/config/platform');
11+
var fs = require('fs'),
12+
path = require('path'),
13+
ideTemplate = require('ide-template'),
14+
defaults = require('../lib/config/defaults'),
15+
platform = require('../lib/config/platform');
1616

1717
var config = defaults
1818
.getInstance('webstorm')
@@ -30,20 +30,20 @@ function setUpWebStormTask(context) {
3030
{
3131
key: 'defaults',
3232
value: {
33-
describe: 'Set defaults',
34-
alias : 'z',
35-
boolean : true,
36-
isOptional: true
33+
describe : 'Set defaults',
34+
alias : 'z',
35+
isOptional: true,
36+
default : false
3737
}
3838
},
3939
{
4040
key: 'subdir',
4141
value: {
42-
describe: 'Navigate to the sub-directory specified',
43-
alias : 's',
44-
string : true,
42+
describe : 'Navigate to the sub-directory specified',
43+
alias : 's',
44+
string : true,
4545
isOptional: true,
46-
default : config.get('subdir')
46+
default : config.get('subdir')
4747
}
4848
},
4949
{
@@ -87,10 +87,9 @@ function setUpWebStormTask(context) {
8787
value: {
8888
describe: 'Launch the IDE following setup',
8989
alias : 'l',
90-
boolean : true,
9190
default : config.get('launch')
9291
}
93-
},
92+
}
9493
];
9594

9695
function checkWebstormFlags(argv) {
@@ -108,7 +107,9 @@ function setUpWebStormTask(context) {
108107
}
109108

110109
// ensure options correspond to the types that they were defined as belonging to
111-
tyRun.checkFlagType(opt, key, value);
110+
if ((key !== 'defaults') && (key !== 'launch')) {
111+
tyRun.checkFlagType(opt, key, value);
112+
}
112113

113114
if (key === 'subdir') {
114115
var subdir = path.resolve(value);
@@ -117,6 +118,29 @@ function setUpWebStormTask(context) {
117118
throw new Error('The specified subdirectory does not exist.');
118119
}
119120
}
121+
else if (key === 'defaults') {
122+
if (!(/^(true|false|reset)$/.test(String(argv.defaults)))) {
123+
throw new Error('Unrecognised value for defaults flag, expected true|false|reset.');
124+
}
125+
}
126+
else if (key === 'launch') {
127+
switch (argv.launch) {
128+
case 'false':
129+
break;
130+
case 'true':
131+
if (!ideTemplate.webStorm.validateExecutable()) {
132+
throw new Error('Cannot find Webstorm executable, you will have to specify it explicitly.');
133+
}
134+
break;
135+
default:
136+
var customPath = path.normalize(argv.launch);
137+
if (fs.existsSync(customPath)) {
138+
ideTemplate.webStorm.customExecutable = customPath;
139+
} else {
140+
throw new Error('Launch path is not valid or does not exist.');
141+
}
142+
}
143+
}
120144
});
121145
if (!argv.defaults) {
122146
// when defaults are not present, check whether angularity project is present
@@ -129,33 +153,6 @@ function setUpWebStormTask(context) {
129153
return true;
130154
}
131155

132-
/**
133-
* yargs check for a valid --launch parameter
134-
* Additionally parses true|false strings to boolean literals
135-
* @param argv
136-
*/
137-
function validateLaunchPath(argv) {
138-
switch (argv.launch) {
139-
case false:
140-
case 'false':
141-
argv.launch = false;
142-
break;
143-
case true:
144-
case 'true':
145-
if (ideTemplate.webStorm.validateExecutable()) {
146-
argv.launch = true;
147-
} else {
148-
return 'Cannot find Webstorm executable, you will have to specify it explicitly.';
149-
}
150-
break;
151-
default:
152-
if (!fs.existsSync(path.normalize(argv.launch))) {
153-
return 'Launch path is not valid or does not exist.';
154-
}
155-
}
156-
return argv;
157-
}
158-
159156
var taskDefinition = {
160157
name: 'webstorm',
161158
description: [
@@ -180,7 +177,7 @@ function setUpWebStormTask(context) {
180177
'angularity webstorm --defaults reset Reset defaults'
181178
].join('\n'),
182179
prerequisiteTasks: ['help'],
183-
checks: [validateLaunchPath, checkWebstormFlags],
180+
checks: [checkWebstormFlags],
184181
options: webstormOptionDefinitions,
185182
onInit: function onInitWebstormTask(yargsInstance) {
186183
var gulp = context.gulp,
@@ -212,13 +209,14 @@ function setUpWebStormTask(context) {
212209
}
213210
// else run the selected items
214211
else {
212+
var launch = (cliArgs.launch !== 'false');
215213
var taskList = [
216214
cliArgs.subdir && 'webstorm:subdir',
217215
cliArgs.project && 'webstorm:project',
218216
cliArgs.external && 'webstorm:externaltools',
219217
cliArgs.codestyle && 'webstorm:codestyle',
220218
cliArgs.templates && 'webstorm:templates',
221-
cliArgs.launch && 'webstorm:launch'
219+
launch && 'webstorm:launch'
222220
].filter(Boolean);
223221
if (taskList.length > 0) {
224222
runSequence.apply(runSequence, taskList.concat(done));

0 commit comments

Comments
 (0)