Personal items: WC (Node.js + Web-side implementation)

The project GitHub Address: https://github.com/sherlockHSY/WC

First, the project requirements

  wc.exe is a common tool, you can count the number of characters of text files, words, and lines. The project asked to write a command line program, to mimic the function of the existing wc.exe, and be expanded, given the number of characters in a programming language source files, words, and lines.

Implement a statistical program, the number of characters it can correct statistics program file, the number of words, lines, and also has other extended functions, and can handle multiple files quickly.

  Specific functional requirements:

    Program processing mode as user requirements: wc.exe [parameter] [file_name]

    The basic list of features:

      wc.exe -c file.c // returns the number of characters in the file file.c

      The number of wc.exe -w file.c // Returns the file of the word file.c

      wc.exe -l file.c // returns the number of rows of file file.c

    extensions:

      -s recursive processing files that meet the conditions of the directory.
      -a return more complex data (line / space lines / comment lines).

    Advanced Features:

      -x This parameter is used alone. The user may select a graphical interface to select the file shows file information.

Two, PSP form

PSP Personal Software Process Stages Estimated time consuming (minutes) The actual time-consuming (minutes)
Planning plan  40 30
· Estimate • Estimate how much time this task requires  30  25
Development Develop  790 710
· Analysis · demand analysis 20  20
· Design Spec Generate design documents  40  30
· Design Review · Design Review   30  30
· Coding Standard · Code Specification  30  40
· Design · Specific design  80  100
· Coding · Specific coding (Find document)  470  370
· Code Review · Code Review  60  50
· Test · Test (self-test, modify the code, submit modifications)  60  80
Reporting report 120 120
· Test Report · testing report  60  80
· Size Measurement · Computing workload  30  50
· Postmortem & Process Improvement Plan · Hindsight, and propose process improvement plan  30  30
  total  950  960

Third, the problem-solving ideas

  After getting this problem, first understand the needs of the project, approximately statistics file, you need to count the number of characters including the results, the number of lines, words, lines, comment lines, blank lines and so on. It involves reading and writing files. After consideration, we decided to implement with Node.js. Graphical interface directly using a web page.

  1. Development Readiness

   Implementation language: Node.js

   IDE: VSCode

  2. Requirements Analysis:

   (1) basic functions: The first is the command-line instructions and parameters of the acquisition. Yargs module using a read command input, determines the instruction type and verify the commands and parameters to ensure that the input is valid. Then perform the appropriate logic. Use native fs module creates file IO streams, read the contents of the file using the readline module line by line, combined with a regular expression to achieve statistical document the number of characters, the number of lines, words of

   (2) Advanced features: essentially expand on some of the basic functions, write a recursive function to increase recursive processing of folders, as well as the regular matching the wildcard (*?), To be judged in the file search. -A complex command lookup, combined with regular statistical matching can be realized.

   (3) Advanced functions: to achieve graphical interface. Because Node.js language itself as a new language from the back end in itself serves the web side, so the graphical interface directly with the web to achieve, as long as the command line command, calling the child's Node automatically open a browser window to run. web pages using html, css, js achieve.

Fourth, design and implementation

  flow chart

  

  1. index.js as the main entry, acquisition instruction and command line parameters, verifies whether the command input method, make the appropriate treatment, equivalent Controll layer.

  2. handleCommand.js将对各个指令的逻辑处理过程高度封装对应函数,并通过export暴露出模块,相当于Service层,对数据的深层处理。供Controll层调用

  3. webView.js实现对web层的处理。通过开启http server监听页面请求,并主动触发自动打开web页面,渲染index.html(相当于View层)。

五、测试

  单元测试

  1.测试基础指令

          测试文件 1.c

   

   测试结果:

     

  2.测试进阶指令  测试递归读取文件夹下的文件,并统计复杂数据

         测试文件夹 testDir

         

    测试结果:

     

  3.测试高级指令

     

   4. 通配符测试

   测试通配符 * :

     

     测试通配符 ? :

          

六、总结     

  本项目采用Node.js+web是我的一次尝试,使用web的初衷是想要与传统的GUI不一样。这个项目的开发,我第一次一个人实现一个完整的流程,从需求分析、设计、开发到测试,学习到了软件工程的很多思想和知识,把项目的本身功能点实现是一方面,项目的测试也是非常重要的一部分。在实际开发中,模块的构建和整体框架的搭建也十分重要。我也认识到只有把各个方面都尽可能的做好,才能使程序具有更好的健壮性。

Guess you like

Origin www.cnblogs.com/sherlocksy/p/11588216.html