Skip to content

Commit 49fa35e

Browse files
author
benholloway
committed
placed safeguards around file operations in webstorm task, ensured init task produces a buildable project
1 parent d884f4e commit 49fa35e

File tree

3 files changed

+52
-27
lines changed

3 files changed

+52
-27
lines changed

tasks/webstorm.js

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -212,31 +212,35 @@ gulp.task('webstorm:project', function () {
212212
gulp.task('webstorm:templates', function () {
213213
var srcDirectory = path.join(TEMPLATE_PATH, 'fileTemplates');
214214
var destDirectory = path.join(userPreferencesDirectory(), 'fileTemplates');
215-
var removed = [ ];
216-
var added = [ ];
217-
fs.readdirSync(destDirectory)
218-
.forEach(function eachTemplate(filename) {
219-
if (/^angularity/.test(path.basename(filename))) {
220-
removed.push(filename);
221-
fs.unlinkSync(path.join(destDirectory, filename));
222-
}
223-
});
224-
fs.readdirSync(srcDirectory)
225-
.forEach(function eachTemplate(filename) {
226-
var srcPath = path.join(srcDirectory, filename);
227-
var destPath = path.join(destDirectory, filename);
228-
added.push(filename);
229-
fs.writeFileSync(destPath, fs.readFileSync(srcPath))
230-
});
231-
removed.forEach(function (filename) {
215+
var isValid = fs.existsSync(destDirectory) && fs.statsSync(destDirectory).isDirectory();
216+
if (!isValid) {
217+
gutil.log('Failed to locate Webstorm templates. Expected directory:')
218+
gutil.log(' ' + destDirectory)
219+
} else {
220+
var removed = [ ];
221+
var added = [ ];
222+
fs.readdirSync(destDirectory).forEach(function eachTemplate(filename) {
223+
if (/^angularity/.test(path.basename(filename))) {
224+
removed.push(filename);
225+
fs.unlinkSync(path.join(destDirectory, filename));
226+
}
227+
});
228+
fs.readdirSync(srcDirectory).forEach(function eachTemplate(filename) {
229+
var srcPath = path.join(srcDirectory, filename);
230+
var destPath = path.join(destDirectory, filename);
231+
added.push(filename);
232+
fs.writeFileSync(destPath, fs.readFileSync(srcPath))
233+
});
234+
removed.forEach(function (filename) {
232235
var isRemove = (added.indexOf(filename) < 0);
233236
if (isRemove) {
234237
gutil.log('removed template ' + filename);
235238
}
236239
});
237-
added.forEach(function (filename) {
240+
added.forEach(function (filename) {
238241
gutil.log('wrote template ' + filename);
239242
});
243+
}
240244
// TODO review with @impaler
241245
// ideTemplate.webStorm.copyFileTemplates(fileTemplatePath);
242246
});
@@ -276,12 +280,19 @@ gulp.task('webstorm:tools', function () {
276280
} ]
277281
};
278282
}
279-
var destPath = path.join(userPreferencesDirectory(), 'tools', 'Angularity.xml');
280-
var content = ideTemplate.webStorm.createExternalTool({
281-
name : 'Angularity',
282-
tools: ['test', 'watch', 'watch --unminified', 'build', 'build --unminified', 'release'].map(createNode)
283-
});
284-
fs.writeFileSync(destPath, content);
283+
var destDirectory = path.join(userPreferencesDirectory(), 'tools');
284+
var isValid = fs.existsSync(destDirectory) && fs.statsSync(destDirectory).isDirectory();
285+
if (!isValid) {
286+
gutil.log('Failed to locate Webstorm tools. Expected directory:')
287+
gutil.log(' ' + destDirectory)
288+
} else {
289+
var destPath = path.join(destDirectory, 'Angularity.xml');
290+
var content = ideTemplate.webStorm.createExternalTool({
291+
name : 'Angularity',
292+
tools: ['test', 'watch', 'watch --unminified', 'build', 'build --unminified', 'release'].map(createNode)
293+
});
294+
fs.writeFileSync(destPath, content);
295+
}
285296
// TODO review with @impaler
286297
// ideTemplate.webStorm.writeExternalTool(toolContent, 'Angularity.xml');
287298
});

templates/angularity/bower.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
"description": "<%= description %>",
55
"private": true,
66
"tags": <%= tags %>,
7-
"dependencies": { },
8-
"devDependencies": { }
7+
"dependencies": {
8+
"jQuery": "latest",
9+
"angular": "latest",
10+
"angular-ui-router": "latest"
11+
},
12+
"devDependencies": {
13+
"angular-mocks": "latest"
14+
}
915
}

templates/angularity/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
/* globals angular */
22

3-
angular.module('<%= name %>', [ ])
3+
angular.module('<%= name %>', [ 'ui.router' ])
4+
.config(function deleteMe($stateProvider, $urlRouterProvider) {
5+
$urlRouterProvider.otherwise('/');
6+
$stateProvider
7+
.state('home', {
8+
url: '/',
9+
template: '<span>Hello World</span>'
10+
});
11+
});

0 commit comments

Comments
 (0)