与Yeoman我可以添加路线和控制器
yo angular:route myroute
有没有办法用Yeoman删除路由和控制器?
答案 0 :(得分:18)
我遇到了删除控制器的类似需求......但是从我发现的文档来看,似乎没有用于删除的API。
参考:https://github.com/yeoman/generator-angular
但暂时帮助你,我会说出我做了什么...... 从我知道的文档中,哪些是为每个命令创建的文件。 所以单独删除这些文件,以摆脱yeoman操作产生的文件。
例如
yo angular:route myroute
创建3个文件
1) app/scripts/controllers/myroute.js (controller)
2) app/views/myroute.html (view)
3) app/test/spec/controllers/myroute.js (testing the controller)
所以单独删除这三个文件。
其他人
yo angular:controller user app/scripts/controllers/user.js
yo angular:directive myDirective app/scripts/directives/myDirective.js
yo angular:filter myFilter app/scripts/filters/myFilter.js
yo angular:view user app/views/user.html
yo angular:service myService app/scripts/services/myService.js
yo angular:decorator serviceName app/scripts/decorators/serviceNameDecorator.js
yo angular:controller user --coffee app/scripts/controller/user.coffee
注意:也不要忘记删除app / test / spec中用于测试的测试文件
我们如何确认该功能可能不存在?
来自源代码,例如控制器
https://github.com/yeoman/generator-angular/blob/master/controller/index.js
api只有Generator.prototype.createControllerFiles 所以对于removeControllerFiles没有任何意义 所以我们应该说这个特征目前不存在是正确的。
答案 1 :(得分:2)
就像上面提到的答案一样,你必须在不同的地方删除。
主要位置
1) app/scripts/controllers/myroute.js (controller)
2) app/views/myroute.html (view)
3) app/test/spec/controllers/myroute.js (testing the controller)
奖金位置
4) app/scripts/app.js (delete from app controller)
5)test/spec/controllers/myroute.js (testing the controller) mine was outside the app dirtectory
答案 2 :(得分:0)
如果您使用的是git,可以使用清洁工具轻松完成:
fredTable <-
structure(list(Symbol = structure(c(3L, 1L, 4L, 2L, 5L),
.Label = c("CASACBM027SBOG", "FRPACBW027SBOG", "TLAACBM027SBOG", "TOTBKCR",
"USNIM"), class = "factor"), Name = structure(1:5, .Label = c("bankAssets",
"bankCash", "bankCredWk", "bankFFRRPWk", "bankIntMargQtr"), class = "factor"),
Category = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "Banks", class = "factor"),
Country = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "USA", class = "factor"),
Lead = structure(c(1L, 1L, 3L, 3L, 2L), .Label = c("Monthly", "Quarterly",
"Weekly"), class = "factor"), Freq = structure(c(2L, 1L, 3L, 3L, 4L),
.Label = c("1947-01-01", "1973-01-01", "1973-01-03", "1984-01-01"),
class = "factor"), Start = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "Current",
class = "factor"), End = c(TRUE, TRUE, TRUE, TRUE, FALSE), SeasAdj = c(FALSE,
FALSE, FALSE, FALSE, TRUE), Percent = structure(c(1L, 1L, 1L, 1L, 1L),
.Label = "Fed", class = "factor"), Source = structure(c(1L, 1L, 1L, 1L, 1L),
.Label = "Res", class = "factor"), Series = structure(c(1L, 1L, 1L, 1L, 2L),
.Label = c("Level", "Ratio"), class = "factor")), .Names = c("Symbol", "Name",
"Category", "Country", "Lead", "Freq", "Start", "End", "SeasAdj", "Percent",
"Source", "Series"), class = "data.frame",
row.names = c("1", "2", "3", "4", "5"))
fredNamesOrig <- fredTable$Name # original downloaded FRED object names
fredObjOrig <- mget(fredNamesOrig) # list of original FRED objects
fredNamesTrans <- fredNamesOrig # pre-allocate list of transformed objects
# Strip off period string ("Day", "Qtr")
for(i in 1:length(fredNamesOrig)){
if(grepl("Day",fredNamesOrig[i]))
fredNamesTrans[i] <- sub("Day","",fredNamesOrig[i])
else if(grepl("Qtr",fredNamesOrig[i]))
fredNamesTrans[i] <- sub("Qtr","",fredNamesOrig[i])
}
# Assign transformed series back to appropriately names series:
for(i in 1:length(fredObjOrig)){
colnames(fredObjOrig[[i]]) <- fredNamesTrans[i]
assign(fredNamesTrans[i],fredObjOrig[[i]])
}
以上将删除工作分支中的所有未跟踪文件。如果您修改跟踪文件,您可以执行以下操作:
git clean -f
或者所有人
git checkout file1/ file2