-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathyeoman.cli.txt
194 lines (160 loc) · 12 KB
/
yeoman.cli.txt
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
┏━━━━━━━━━━━━┓
┃ YEOMAN ┃
┗━━━━━━━━━━━━┛
INSTALL ==> #npm install -g yo + any generator
#Version: 1.1.2
YEOMAN #require("yeoman-generator")
BASE #YEOMAN.generators.Base
yo #Uses interactive prompt to:
# - run yo GENERATOR, choosing among ones installed
# - update GENERATOR: run npm update -g generator-*
# - install GENERATOR: run npm search generator-* then npm install -g generator-*
yo GENERATOR[:SUBGENERATOR] #Look for Node module generator-GENERATOR/SUBGENERATOR/index.js (often installed globally)
[ARGS] [OPTIONS] #which should module.exports = BASE.extend({ FUNC... }):
# - fire FUNC... in order
# - _FUNC are not fired
# - init, askFor (prompts), app (main files) and projectfiles (other files) are often used.
# - Usually scaffold a project, by populating current directory, using an interactive
# prompt, and running npm install + bower install
# - this of these FUNC:
# - has several useful functions (see next)
#Déf. SUBGENERATOR is "app"
#Explicit SUBGENERATOR is usually used for a small part of the directory, e.g. a file.
#Can use generator-generator to get the basic structure started, and
#generator-generator:subgenerator NAME for an explicit subgenerator.
#ARGS (without dash) and OPTIONS (with dash) depends on GENERATOR
-f #Overwrite files.
this.invoke(
GENERATOR[:SUBGENERATOR]_STR, #Like running yo. OBJ are the options, OBJ.args the arguments.
OBJ[, FUNC()]) #Fires FUNC() at the end.
this.composeWith(
GENERATOR[:SUBGENERATOR][, OBJ] #Same but:
[{ local: require.resolve( # - run at the end
"NODE_MODULE/...") }]) # - can use a local file NODE_MODULE/.../index.js
┌───────────────┐
│ ARGUMENTS │
└───────────────┘
this.options.namespace #GENERATOR:SUBGENERATOR
this.options.name
this.generatorName #SUBGENERATOR (GENERATOR if "app")
this.rootGeneratorName() #generator-GENERATOR
this.appName #Name in bower.json, package.json or of the current directory, supposedly of the project
#to create
this.args #ARGS as STR_ARR
this.argument(STR, OBJ) #Help messages and default value for an argument.
#OBJ members are desc STR, required BOOL, optional BOOL, type TYPE, defaults VAL and
#banner STR
#Can be retrieved as this.STR
#Using NamedBase.extend() instead of Base.extend() is same as doing
#this.argument("name", { required: true, type: String })
this.options #OPTIONS as OBJ
this.option(STR, OBJ) #Help messages and default value for an option --STR=VAL
#OBJ members are:
# - banner STR: short help message
# - desc STR: long help message
# - type TYPE: Boolean, Number and String
# - defaults VAL: can be retrieved with this.defaultFor(STR)
# - hide BOOL: if true, hides from help messages
#Options are stored in this.options.STR
this.help() #Prints help message taking options into account
this.alias(REGEXP, STR) #If GENERATOR[:SUBGENERATOR] not found and matches REGEXP, tries looking for STR
#(can use "$1" for GENERATOR[:SUBGENERATOR]).
┌────────────┐
│ CONFIG │
└────────────┘
this.config.path #$PWD/.yo-rc.json
#Should be as { "generator-GENERATOR": OBJ ... }
#If it exists, will be stored in this.config OBJ, with members:
# - get(VAR), set(VAR, VAL): set() saves
# - getAll(): as OBJ
# - defaults(OBJ): like set(), but don't set if already existing
# - delete(VAR): saves too
this.config.existed #true if there is one
this.resolved #PATH_STR of the GENERATOR defining module.exports
┌───────────┐
│ FILES │
└───────────┘
DEFAULT SRC/DEST DIRECTORY ==> #Either:
# - $PWD for dest|src
# - $PWD for dest, ./node_modules/generator-GENERATOR/SUBGENERATOR/template/ for src if:
# - this.*
# - this.src.*, which is same as YEOMAN.file.*
# $PWD for src and dest can be get/set with this.source|destinationRoot([PATH])
# - this.dest.*: same as this.src.* but inverse src and dest
this.copy|directory(PATH, #Like cp [-R]
PATH2[, FUNC(STR)]) #FUNC() returns STR2 (transforms content)
this.remote(USERNAME_STR, REPO_STR #Git fetch a repo into this.cacheRoot() (déf: ~/.cache/yeoman/), unless cache already
[, BRANCH_STR], FUNC(ERROR, OBJ) #exists (unless BOOL is true)
[, BOOL]) #OBJ has members cachePath (repo path), copy, template, directory, src, dest
#(same as this.*)
this.user.git.username|email #Returns Git config user.name|email from .git/ ("" if nothing)
this.fetch|extract( URL_STR,DIR_STR,#Do require("download")(URL, DIR, OBJ), where OBJ uses:
FUNC() ) # - if extract, { extract: true, strip: 1 }
# - { proxy: URL }, if env variable HTTP[S]_PROXY
#When done, fires FUNC() (on success or error)
this.request #Like require("request")
this.checkForCollision(PATH_STR, #Prompt to override file at PATH with STR, and fires FUNC, with OBJ members:
STR, FUNC(ERROR, OBJ)) # - status: "identical" (if STR same as PATH content, doesn't prompt), "force|skip"
# (yes/no)
# - callback FUNC(ERROR): to call afterwise
YEOMAN.file.* #same as GRUNT.file.*
YEOMAN.file.isExecutable(PATH...)
YEOMAN.file.option(STR[, VAL]) #Getter/setter of options for YEOMAN.file.*:
# - write (déf: true): if false, readonly
# - encoding (déf: "utf8")
# - force (déf: true): if false, readonly outside a FILEENV
YEOMAN.file.createEnv #Returns a FILEENV. It is like YEOMAN.file.*, but all read|write functions of GRUNT.file.*
({ base|dest: PATH_STR|FUNC() }) #with PATH (FUNC() returns PATH) of base|dest
FILEENV.registerWriteFilter(STR, #Fires FUNC() each time YEOMAN.file.copy|write() is called.
FUNC({ path STR2, contents STR3 })) #FUNC() can change filename|content, and must return the OBJ.
#STR is the id.
FILEENV.removeWriteFilter(STR)
FILEENV.register| #Same but FUNC() returns true if nothing happens, and false|STR (error message) if nothing
removeValidationFilter(...) #should be written.
this.expand(STR[, OBJ]) #Same as require("glob").sync(...)
this.expandFiles(...) #Same but only returns regular files (not directories)
┌──────────────┐
│ INSTALLS │
└──────────────┘
this.runInstall(STR, STR2[_ARR]
[, OBJ][, FUNC([ERROR])]) #Run command line "STR install STR2 --OBJ_VAR OBJ_VAL"
this.bower|npmInstall(STR2[_ARR])
[, OBJ][, FUNC([ERROR])]) #Same for "bower" and "npm"
this.installDependencies([OBJ]) #Run "bower install" then "npm install"
#Options OBJ are:
# - npm|bower BOOL: if false, skip it
# - skipInstall BOOL: if true, only prints a message asking user to run bower install
# and npm install by themselves
# - skipMessage BOOL: if true, silent
┌─────────────┐
│ CONSOLE │
└─────────────┘
this.log(STR) #Can use this.yeoman, which is set to the Yeoman greeting screen
this.prompt(OBJ_ARR, FUNC(OBJ2)) #Like require("inquirer").prompt(...)
#Needs to use this.async()
#To use this in FUNC(), must do FUNC.bind(this). Often OBJ3.VAR is assigned to this.VAR
this.env.adapter.diff(STR, STR2) #Prints difference.
this.async() #Returns FUNC() to call when async. work is done.
#To do in any async. FUNC
┌───────────────┐
│ TEMPLATES │
└───────────────┘
this._ #require("lodash")
this.engine(STR, OBJ[, OBJ2]) #Like LODASH.template(...).
#Can be changed with e.g. this.engine = FUNC; or as an option:
# yo --engine=MODULE (does not seem to work)
#with MODULE exporting FUNC
this.template(PATH,PATH2,OBJ[,OBJ2])#Apply this.engine(PATH_CONTENT, OBJ[, OBJ2]), then store into PATH2
┌──────────────────────┐
│ DOM MANIPULATION │
└──────────────────────┘
this.domUpdate(HTML_STR, SELECTOR, #Same as CHEERIO.load(HTML_STR)(SELECTOR).append|prepend|html|remove(VAL) where FUNC
VAL, CHAR) #is decided by CHAR 'a|p|r|d'
this.append|prepend(...) #Same as this.domUpdate(..., 'a|p')
this.append|prependToFile(PATH,
SELECTOR, VAL) #Same but directly modify a file content.
this.removeScript|Style
(HTML_STR, PATH) #Returns HTML without <script|style> with src|href=PATH
this.attributes(OBJ) #Returns as "VAR=VAL ..."
this.readFileAsString(PATH)
this.writeFileFromString(STR, PATH) #Same as FS.readFileSync() and FS.writeFileSync()