Node front-end automation

Source: Internet
Author: User

First, front-end automation-project construction

We usually write code, like to build a project, and then inside is CSS, JS, images files, and index.html, and node can be automated to build a good project, as follows:

/** * Created by Yi on 2015/9/20.*/varProjectdata = {    'name':'Project',    'FileData' : [        {            'name':'CSS',            'type':'dir'        },        {            'name':'JS',            'type':'dir'        },        {            'name':'Images',            'type':'dir'        },        {            'name':'index.html',            'type':'file',            'content':'',        }    ]};varFS = require ('FS');if(projectdata.name) {fs.mkdirsync (projectdata.name); varFileData =Projectdata.filedata; if(FileData &&Filedata.foreach) {Filedata.foreach (function (f) {F.path= Projectdata.name +'/'+F.name; F.content= F.content | |"'; Switch(f.type) { Case 'dir': Fs.mkdirsync (F.path);  Break;  Case 'file': Fs.writefilesync (F.path, f.content);  Break; default :                     Break;    }        }); }}

Second, the front-end automation-monitoring file changes

Build a source folder in the auto-generated project folder above. The following code is to listen for any changes in the source folder, whether you are creating a new file or adding content to a new file. It will be merged into the js/index.js.

varFS = require ('FS');varFiledir ='./project/source'; Fs.watch (Filedir, function (EV, file) {//console.log (ev + '/' + file);//There is no need to determine if file has content//as soon as one file changes, we need to read all the files in this folder and mergeFs.readdir (Filedir, function (err, dataList) {vararr = [];        Console.log (dataList); Datalist.foreach (function (f) {if(f) {varinfo = Fs.statsync (Filedir +'/'+f); //Console.log (info);                if(Info.mode = =33206) {Arr.push (Filedir+'/'+f);        }            }        }); //Console.log (arr); //reads the contents of the file in the array and merges        varContent ="'; Arr.foreach (function (f) {varc =Fs.readfilesync (f); //Console.log (c);content+ = c.tostring () +'\ n';        });        Console.log (content); Fs.writefile ('./project/js/index.js', content); });})

Node front-end automation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.