This repository has been archived by the owner on Jul 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngmodule.coffee
115 lines (91 loc) · 2.78 KB
/
ngmodule.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
yargs = require 'yargs'
path = require 'path'
_str = require 'underscore.string'
_ = require 'lodash'
path = require 'path'
NGModule = (args)-> @main(args)
NGModule:: =
main: (args)->
_.defaults args,
path: null
@path = args.path
@moduleFilename = path.basename @path.replace /\/src/gi, ''
@ngModuleName = _str.camelize @moduleFilename
return @
# todo: refactor for re-using NGModule in gulpfile.coffee
module.exports = (modulepath)->
module = new NGModule path: modulepath
# [patrick] why don't we move this below to NGModule (prototype)?
types =
module: 'm'
factory: 'f'
service: 's'
directive: 'd'
provider: 'p'
value: 'v'
controller: 'c'
config: 'o'
constant: 'n'
decorator: 'e'
template: 't'
style: 'y'
args = _.reduce types, (args, option, type)->
args
.alias option, type
.describe option, 'Create a new ' + type
return args
, yargs
.demand ['m']
# _.forEach args, (arg, key)-> console.log arg, key
pluralize = (type) ->
plurals =
factory: 'factories'
service: 'services'
directive: 'directives'
provider: 'providers'
value: 'values'
controller: 'controllers'
constant: 'constants'
decorator: 'decorators'
template: 'templates'
style: 'styles'
return type = if plurals[type] then plurals[type] else type
isModuleOnly = (_.filter types, (option, type)-> args.argv[type]).length == 1 && args.argv['module']?
filesToCreate = _.reduce args.argv, (result, optionVal, type)->
if types[type]?
filename = (_str.ltrim (_str.dasherize optionVal), ['-'])
ext = '.coffee'
switch type
when 'template' then ext = '.jade'
when 'style' then ext = '.scss'
if optionVal.indexOf('_') == 0
filename = '_' + (_str.ltrim (_str.dasherize optionVal), ['-'])
if type != 'module'
result.push
modulepath: module.path
template: path.join __dirname, '/templates/', type + ext
dest: path.join '/src/', pluralize(type), filename + ext
templateData:
# util
_s: _str
# data
module: module.ngModuleName
type: type
name: _str.camelize optionVal
filename: filename
else if isModuleOnly
result.push
modulepath: module.path
template: path.join __dirname, '/templates/', type + ext
dest: path.join '/src/' + 'index' + ext
templateData:
# util
_s: _str
# data
module: module.ngModuleName
type: type
name: module.ngModuleName
return result
, []
yargs.resetOptions()
return filesToCreate