-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added quick commands for angular app
- Loading branch information
1 parent
26d14df
commit 67581ac
Showing
12 changed files
with
435 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
/*================================================================ | ||
=> Controller = <%= classedName %>Ctrl | ||
==================================================================*/ | ||
/*global app*/ | ||
|
||
app.controller('<%= classedName %>Ctrl', ['$scope', function ($scope) { | ||
|
||
'use strict'; | ||
|
||
|
||
|
||
|
||
console.log('Controller === <%= classedName %>Ctrl'); | ||
}]); | ||
|
||
|
||
/*----- End of Controller = <%= classedName %> ------*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/*================================================================ | ||
=> Directive = <%= cameledName %> | ||
==================================================================*/ | ||
/*global app*/ | ||
|
||
app.directive('<%= cameledName %>', ['$rootScope', function ($rootScope) { | ||
|
||
'use strict'; | ||
|
||
return { | ||
restrict: 'A', | ||
link: function (scope, element, attrs) { | ||
|
||
console.log('Directive === <%= cameledName %>'); | ||
} | ||
}; | ||
|
||
}]); | ||
|
||
|
||
/*----- End of Directive = <%= cameledName %> ------*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*================================================================ | ||
=> Filter = <%= cameledName %> | ||
==================================================================*/ | ||
/*global app*/ | ||
|
||
app.filter('<%= cameledName %>', function () { | ||
|
||
'use strict'; | ||
|
||
return function (input) { | ||
|
||
console.log('Filter == <%= cameledName %>'); | ||
|
||
return; | ||
}; | ||
}); | ||
|
||
|
||
/*----- End of Filter = <%= cameledName %> ------*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
/*================================================================ | ||
=> Service = <%= cameledName %> | ||
==================================================================*/ | ||
/*global app*/ | ||
|
||
app.service('<%= cameledName %>', ['$rootScope', '$q', '$http', function ($rootScope, $q, $http) { | ||
|
||
'use strict'; | ||
|
||
//GET method | ||
this.getUserData = function (url) { | ||
var defer = $q.defer(); | ||
|
||
$http.get(url) | ||
.success(function (data) { | ||
deferred.resolve(data); | ||
}) | ||
.error(function (err) { | ||
deferred.reject(err); | ||
}); | ||
|
||
return deferred.promise; | ||
|
||
}; | ||
|
||
//POST method | ||
this.postUserData = function (userData) { | ||
var defer = $q.defer(); | ||
|
||
var url = ''; //POST url | ||
|
||
$http.post({ | ||
url : url, | ||
data : userData | ||
}) | ||
.success(function (data) { | ||
deferred.resolve(data); | ||
}) | ||
.error(function (err) { | ||
deferred.reject(err); | ||
}); | ||
|
||
return deferred.promise; | ||
|
||
}; | ||
|
||
}]); | ||
|
||
|
||
/*----- End of Service = <%= cameledName %> ------*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
var util = require('util'), | ||
chalk = require('chalk'); | ||
|
||
var ScriptBase = require('../script-base.js'); | ||
|
||
|
||
var Generator = module.exports = function Generator() { | ||
ScriptBase.apply(this, arguments); | ||
|
||
// if the controller name is suffixed with ctrl, remove the suffix | ||
// if the controller name is just "ctrl," don't append/remove "ctrl" | ||
if (this.name && this.name.toLowerCase() !== 'ctrl' && this.name.substr(-4).toLowerCase() === 'ctrl') { | ||
this.name = this.name.slice(0, -4); | ||
} | ||
}; | ||
|
||
util.inherits(Generator, ScriptBase); | ||
|
||
//Function to create controller | ||
Generator.prototype.createControllerFiles = function createControllerFiles() { | ||
|
||
this.log(chalk.yellow('Creating controller, please wait...... \n')); | ||
|
||
this.generateSourceAndTest( | ||
'_controller', // controller template name | ||
'spec/controller', //for generating test file in test folder | ||
'controllers', //target dir | ||
this.options['skip-add'] || false | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
var util = require('util'), | ||
ScriptBase = require('../script-base.js'); | ||
|
||
var Generator = module.exports = function Generator() { | ||
ScriptBase.apply(this, arguments); | ||
}; | ||
|
||
util.inherits(Generator, ScriptBase); | ||
|
||
Generator.prototype.createDirectiveFiles = function createDirectiveFiles() { | ||
|
||
this.log(chalk.yellow('Creating directive, please wait...... \n')); | ||
|
||
this.generateSourceAndTest( | ||
'_directive', | ||
'spec/directive', | ||
'directives', | ||
this.options['add-index'] || false | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
var util = require('util'), | ||
ScriptBase = require('../script-base.js'); | ||
|
||
var Generator = module.exports = function Generator() { | ||
ScriptBase.apply(this, arguments); | ||
}; | ||
|
||
util.inherits(Generator, ScriptBase); | ||
|
||
Generator.prototype.createFilterFiles = function createFilterFiles() { | ||
|
||
this.log(chalk.yellow('Creating filter, please wait...... \n')); | ||
|
||
this.generateSourceAndTest( | ||
'_filter', | ||
'spec/filter', | ||
'filters', | ||
this.options['add-index'] || false | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
'use strict'; | ||
var util = require('util'); | ||
var path = require('path'); | ||
var yeoman = require('yeoman-generator'); | ||
var angularUtils = require('./util.js'); | ||
var chalk = require('chalk'); | ||
|
||
var Generator = module.exports = function Generator() { | ||
yeoman.generators.NamedBase.apply(this, arguments); | ||
|
||
var bowerJson = {}; | ||
|
||
try { | ||
bowerJson = require(path.join(process.cwd(), 'bower.json')); | ||
} catch (e) {} | ||
|
||
if (bowerJson.name) { | ||
this.appname = bowerJson.name; | ||
} else { | ||
this.appname = path.basename(process.cwd()); | ||
} | ||
|
||
this.appname = this._.slugify(this._.humanize(this.appname)); | ||
|
||
this.scriptAppName = bowerJson.moduleName || this._.camelize(this.appname) + angularUtils.appName(this); | ||
|
||
this.cameledName = this._.camelize(this.name); | ||
this.classedName = this._.classify(this.name); | ||
|
||
if (typeof this.env.options.appPath === 'undefined') { | ||
this.env.options.appPath = this.options.appPath || bowerJson.appPath || 'app'; | ||
this.options.appPath = this.env.options.appPath; | ||
} | ||
|
||
this.env.options.testPath = this.env.options.testPath || bowerJson.testPath || 'test/spec'; | ||
|
||
this.env.options.coffee = this.options.coffee; | ||
if (typeof this.env.options.coffee === 'undefined') { | ||
this.option('coffee'); | ||
|
||
// attempt to detect if user is using CS or not | ||
// if cml arg provided, use that; else look for the existence of cs | ||
if (!this.options.coffee && | ||
this.expandFiles(path.join(this.env.options.appPath, '/scripts/**/*.coffee'), {}).length > 0) { | ||
this.options.coffee = true; | ||
} | ||
|
||
this.env.options.coffee = this.options.coffee; | ||
} | ||
|
||
var sourceRoot = '/app/templates/js'; | ||
this.scriptSuffix = '.js'; | ||
|
||
if (this.env.options.coffee) { | ||
sourceRoot = '/templates/coffeescript'; | ||
this.scriptSuffix = '.coffee'; | ||
} | ||
|
||
this.sourceRoot(path.join(__dirname, sourceRoot)); | ||
}; | ||
|
||
util.inherits(Generator, yeoman.generators.NamedBase); | ||
|
||
Generator.prototype.appTemplate = function (src, dest) { | ||
yeoman.generators.Base.prototype.template.apply(this, [ | ||
src + this.scriptSuffix, | ||
path.join(this.env.options.appPath, dest.toLowerCase()) + this.scriptSuffix | ||
]); | ||
}; | ||
|
||
Generator.prototype.testTemplate = function (src, dest) { | ||
yeoman.generators.Base.prototype.template.apply(this, [ | ||
src + this.scriptSuffix, | ||
path.join(this.env.options.testPath, dest.toLowerCase()) + this.scriptSuffix | ||
]); | ||
}; | ||
|
||
Generator.prototype.htmlTemplate = function (src, dest) { | ||
yeoman.generators.Base.prototype.template.apply(this, [ | ||
src, | ||
path.join(this.env.options.appPath, dest.toLowerCase()) | ||
]); | ||
}; | ||
|
||
Generator.prototype.addScriptToIndex = function (script) { | ||
try { | ||
var appPath = this.env.options.appPath; | ||
var fullPath = path.join(appPath, 'index.html'); | ||
angularUtils.rewriteFile({ | ||
file: fullPath, | ||
needle: '<!-- endbuild -->', | ||
splicable: [ | ||
'<script src="js/' + script.toLowerCase().replace(/\\/g, '/') + '.js"></script>' | ||
] | ||
}); | ||
} catch (e) { | ||
this.log.error(chalk.yellow( | ||
'\nUnable to find ' + fullPath + '. Reference to ' + script + '.js ' + 'not added.\n' | ||
)); | ||
} | ||
}; | ||
|
||
Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, targetDirectory, skipAdd) { | ||
|
||
skipAdd = true; | ||
|
||
this.appTemplate(appTemplate, path.join('js', targetDirectory, this.name)); | ||
// this.testTemplate(testTemplate, path.join(targetDirectory, this.name)); | ||
if (!skipAdd) { | ||
this.addScriptToIndex(path.join(targetDirectory, this.name)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
var util = require('util'), | ||
chalk = require('chalk'); | ||
|
||
var ScriptBase = require('../script-base.js'); | ||
|
||
|
||
var Generator = module.exports = function Generator() { | ||
ScriptBase.apply(this, arguments); | ||
}; | ||
|
||
util.inherits(Generator, ScriptBase); | ||
|
||
Generator.prototype.createServiceFiles = function createServiceFiles() { | ||
|
||
this.log(chalk.yellow('Creating service, please wait...... \n')); | ||
|
||
this.generateSourceAndTest( | ||
'_service', | ||
'spec/service', | ||
'services', | ||
this.options['skip-add'] || false | ||
); | ||
}; |
Oops, something went wrong.