Can Yeoman generators update existing files?

前端 未结 5 1978
旧巷少年郎
旧巷少年郎 2021-01-30 10:57

So just to give you some context, I\'m trying to create a generator that will create some files (based on user input of course) as well as update some existing files in

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-30 11:36

    Ok, so I found the answer to my question.

    Addy Osmani showed me where to look in this thread on twitter, and then I later found this link which shows exactly what I need.

    The gist of it boils down to two functions : readFileAsString and write. Usage is as follows:

    var path = "/path/to/file.html",
        file = this.readFileAsString(path);
    
    /* make modifications to the file string here */
    
    this.write(path, file);
    

    Edit: I've also blogged about this on my blog.

     EDIT 1

    As mentionned in comments by Toilal :

    The write method doesn't exists anymore, and must be replaced by writeFileFromString (arguments are also reversed) – Toilal

    EDIT 2

    And then, as mentionned in comments by ivoba:

    this.writeFileFromString & this.readFileAsString are deprecated, github.com/yeoman/html-wiring should be used by now, things change :) – ivoba

提交回复
热议问题