Skip to content

Commit 6ff919a

Browse files
committed
Merge pull request #23 from bholloway/master
init task should create a buildable project
2 parents 8911f12 + 1c7dabe commit 6ff919a

File tree

5 files changed

+101
-60
lines changed

5 files changed

+101
-60
lines changed

lib/util/jshint-reporter.js

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ var yargs = require('./yargs');
88

99
var defaultReporterName = 'angularity-jshint-reporter';
1010

11+
/**
12+
* Cache resolved reporter object or stream
13+
* @type {function}
14+
*/
15+
var resolvedReporter;
16+
1117
/**
1218
* Dynamically load a JsHint reporter
1319
*
@@ -22,46 +28,57 @@ var defaultReporterName = 'angularity-jshint-reporter';
2228
* - The absolute path to a node package
2329
* @return {function} The `required`ed jshint report, ready to be piped a gulp stream
2430
*/
25-
var jsHintReporter;
2631
function getJsHintReporter(reporterName) {
27-
if (typeof reporterName !== 'string') {
28-
throw 'Get JsHint Reporter: Reporter name is unspecified';
29-
}
30-
if (jsHintReporter) {
31-
return jsHintReporter; //cached copy
32-
}
3332

34-
if (reporterName === defaultReporterName) {
35-
jsHintReporter = require(defaultReporterName);
36-
}
37-
else {
38-
var reporterPath = (path.dirname(reporterName) === '.') ?
39-
path.resolve('node_modules', reporterName) :
40-
reporterName;
41-
try {
42-
jsHintReporter = require(reporterPath);
43-
if (typeof jsHintReporter === 'string') {
44-
//In JsHint convention, the `index.js` file exports a string which jshint itself should require
45-
//e.g. `module.exports = require('path').join(__dirname, 'reporter.js');`
46-
jsHintReporter = gulpJshint.reporter(require(jsHintReporter));
47-
}
33+
// establish a cached copy
34+
if (!resolvedReporter) {
35+
if (typeof reporterName !== 'string') {
36+
throw 'Get JsHint Reporter: Reporter name is unspecified';
4837
}
49-
catch (ex) {
50-
throw 'Get JsHint Reporter: Attempt to require reporter from path '+reporterPath+' with no success.';
38+
else {
39+
// first check angularity installed modules, then check project locally installed modules
40+
[ path.resolve('node_modules'), null ].forEach(function (base) {
41+
var reporterPath = base ? path.join(base, reporterName) : reporterName;
42+
try {
43+
// In JsHint convention, the `index.js` file exports a string which jshint itself should require
44+
// e.g. `module.exports = require('path').join(__dirname, 'reporter.js');`
45+
// this is the indirect case.
46+
// However in some cases it may be the reporter itself
47+
var indirect = require(reporterPath);
48+
resolvedReporter = (typeof indirect === 'string') ? require(indirect) : indirect;
49+
} catch (ex) {
50+
/* do nothing */
51+
}
52+
});
53+
if (!resolvedReporter) {
54+
throw 'Get JsHint Reporter: Attempt to require reporter from path ' + reporterPath + ' with no success.';
55+
}
5156
}
5257
}
5358

54-
return jsHintReporter;
59+
// return cached copy
60+
// closure that returns a stream
61+
if (typeof resolvedReporter === 'function') {
62+
return resolvedReporter();
63+
}
64+
// jshint plugin object with reporter field
65+
else if (!!(resolvedReporter) && (typeof resolvedReporter.reporter === 'function')) {
66+
return gulpJshint.reporter(resolvedReporter);
67+
}
68+
// unsupported
69+
else {
70+
throw 'Get JsHint Reporter: Given reporter is badly formed';
71+
}
5572
}
5673

5774
var yargsOptionDefiniton = {
5875
key: 'reporter',
5976
value: {
60-
describe: 'Specify a custom JsHint reporter to use. '+
61-
'Either a locally npm installed module, or an asolute path to one.',
77+
describe: 'Specify a custom JsHint reporter to use. Either a locally npm installed module, or the absolute path ' +
78+
'to one.',
6279
alias: ['r'],
6380
default: defaultReporterName,
64-
string: true,
81+
string: true
6582
}
6683
};
6784
var checkJsHintReporter = yargs.createCheck()
@@ -77,15 +94,15 @@ var checkJsHintReporter = yargs.createCheck()
7794
getJsHintReporter(value);
7895
}
7996
catch (ex) {
80-
return 'Illegal value for "reporter"\n'+ex;
97+
return 'Illegal value for "reporter"\n' + ex;
8198
}
82-
},
99+
}
83100
})
84101
.commit();
85102

86103
module.exports = {
87-
get: getJsHintReporter,
88-
yargsCheck: checkJsHintReporter,
89-
yargsOption: yargsOptionDefiniton,
104+
get : getJsHintReporter,
105+
yargsCheck : checkJsHintReporter,
106+
yargsOption : yargsOptionDefiniton,
90107
defaultReporterName: defaultReporterName
91108
};

tasks/javascript.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var path = require('path'),
44
fs = require('fs');
55

66
var gulp = require('gulp'),
7-
gulpFilter = require('gulp-filter'),
87
jshint = require('gulp-jshint'),
98
rimraf = require('gulp-rimraf'),
109
runSequence = require('run-sequence'),

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)