【问题标题】:How to delete/remove a scaffolded route generated in Yeoman Angular如何删除/移除在 Yeoman Angular 中生成的脚手架路由
【发布时间】:2014-01-01 02:54:57
【问题描述】:

我知道我可以删除代码和文件;但是,有没有办法在类似的自动命令中删除 yeoman 中的 generated 路由 - angular?

例如yo angular:route myroute 是你生成它的方式

我将运行什么命令行代码来移除、回滚或删除此路由脚手架?

【问题讨论】:

    标签: javascript angularjs yeoman


    【解决方案1】:

    我认为没有命令可以这样做。

    我阅读了有关生成器和子生成器的文档 (http://yeoman.io/generators.html#writing-your-first-generator),但找不到有关删除进程的任何信息。

    我还阅读了有关生成器 API (http://yeoman.github.io/generator/actions.html) 的文档,并且有诸如 copydirectoryreadwrite 之类的选项,但仍然没有关于删除的内容。所以我认为甚至为这些生成器编写自己的命令也是不可能的。

    【讨论】:

      【解决方案2】:

      即使我尝试删除路线,也来自 Rails 背景,但似乎没有任何方法可以这样做。我浏览了docs。而且好像也没有加入iy的计划。

      无论如何,当我们生成文件时,我们会看到生成了哪些文件,所以我们要做的就是删除这些文件。

      yo angular:route route1 创建 3 个文件

      app/scripts/controllers/route1.js              (controller)
      app/views/route1.html                          (view)
      app/test/spec/controllers/route1.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 
      

      测试也同时生成。

      【讨论】:

        【解决方案3】:

        这是我一直在使用的一个 shell hack。

        $ yo angular:controller testcontroller
            create app/scripts/controllers/testcontroller.js
            create test/spec/controllers/testcontroller.js
        $ rm -v `yo angular:controller testcontroller 2>&1 | awk '{print $2}'`
        app/scripts/controllers/testcontroller.js
        test/spec/controllers/testcontroller.js
        

        【讨论】:

        • 它不会删除生成器添加到 app/index.html 的脚本标签
        【解决方案4】:

        您可以使用 rjoyal 之前提到的 shell hack,但请记住删除 te index.html 文件中的脚本和 app.js 中显示的代码行

        .when('/myroute',{ 
        templateUrl: 'views/myroute.html',
        controller: 'myRouteCtrl' })
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-11-19
          • 2013-09-11
          • 1970-01-01
          • 1970-01-01
          • 2011-07-27
          • 2020-11-23
          • 1970-01-01
          相关资源
          最近更新 更多