如何使用Node.js脚本读取文件并在特定行更新文件

时间:2018-11-10 13:26:19

标签: javascript node.js npm-scripts

我想创建一个节点脚本来生成一组文件夹和文件,并向其中写入一些起始代码,就像我们从cli那里获得了cli命令一样。我有一个名为screen_names.js的文件,每当通过运行命令npm run feature [featureName]创建一个新屏幕时,都会在may应用程序的功能文件夹中创建一个包含一些子文件夹和文件的文件夹,我想添加和导入语句在文件中所有其他导入语句之后导入,并在文件中所有其他导出语句之后添加导出状态。

import Input from '../features/Input/containers'
import Segment from '../features/segment/containers'
....
// add an import state here

export {
...,
    Input,
    Segment,
// add export component name here
}

我如何读取此文件并将其附加在适当的位置,然后再次将该文件保存在javascript中。

1 个答案:

答案 0 :(得分:0)

您可以使用import gtk import geany class ClearGeany(geany.Plugin): __plugin_name__ = "Clear Geany VTE" __plugin_version__ = "1.0" __plugin_description__ = "clear geany vte" __plugin_author__ = "John Doe" def __init__(self): self.menu_item = gtk.MenuItem("Clear") self.menu_item.show() geany.main_widgets.editor_menu.append(self.menu_item) self.menu_item.connect("activate", self.on_clear_item_clicked) def cleanup(self): self.menu_item.destroy() def on_clear_item_clicked(widget, data): #geany.dialogs.show_msgbox("Hello World") import os os.system('clear') 模块逐行读取文件,并检查要更新的特定条件,一旦读取了所有数据,然后使用readline模块将其写入同一文件。

index.js

fs