|
- var fs = require('fs');
- var readline = require('readline');
- var os = require('os');
- var path = require('path');
-
- // Node.js readline 逐行读取、写入文件内容的示例
- // https://www.jb51.net/article/135706.htm
- // nodejs读取文件、按行读取
- // https://blog.csdn.net/weixin_42171955/article/details/100156212
-
- var strInputFileName = '../dist/index.html';
- var strOutputFileName = 'E:\\code\\lou\\public\\view\\order_main\\add.html';
- var strOutputFileName2 = 'E:\\code\\lou\\public\\view\\order_main\\edit.html';
-
- var fRead = fs.createReadStream(strInputFileName);
- var fWrite = fs.createWriteStream(strOutputFileName);
- var fWrite2 = fs.createWriteStream(strOutputFileName2);
-
- fRead.on('end', () => {
- console.log('end');
- });
-
- var objReadline = readline.createInterface({
- input: fRead,
- output: fWrite,
- terminal: false
- });
- objReadline.on('line', (strLine) => {
- let strTemp = `<script>window.id = '';function close(){window.parent.postMessage('message', window.location.protocol+"//"+window.location.host);}</script>${strLine}`;
- let strTemp2 = `<script> window.id = getQueryVariable("id");function getQueryVariable(variable){var query = window.location.search.substring(1);var vars = query.split("&");for (var i=0;i<vars.length;i++) { var pair = vars[i].split("=");if(pair[0] == variable){return pair[1];}}return(false);}function close(){window.parent.postMessage('message', window.location.protocol+"//"+window.location.host);}</script>${strLine}`;
- fWrite.write(strTemp);
- fWrite2.write(strTemp2);
- });
-
-
- objReadline.on('close', () => {
- console.log('readline close...');
- });
- function removeDir(dir) {
- let files = fs.readdirSync(dir)
- for(var i=0;i<files.length;i++){
- let newPath = path.join(dir,files[i]);
- let stat = fs.statSync(newPath)
- if(stat.isDirectory()){
- //如果是文件夹就递归下去
- removeDir(newPath);
- }else {
- //删除文件
- fs.unlinkSync(newPath);
- }
- }
- fs.rmdirSync(dir)//如果文件夹是空的,就将自己删除掉
- }
- if(fs.statSync("E:\\code\\lou\\public\\static").isDirectory()){
- //如果是文件夹就递归下去
- removeDir('E:\\code\\lou\\public\\static');
- }else {
- //删除文件
- fs.unlinkSync(newPath);
- }
- fs.mkdir("E:\\code\\lou\\public\\static",function(){//创建目录
-
- })
-
- var stat=fs.stat;
-
- var copy=function(src,dst){
- //读取目录
- fs.readdir(src,function(err,paths){
- console.log(paths)
- if(err){
- throw err;
- }
- paths.forEach(function(path){
- var _src=src+'/'+path;
- var _dst=dst+'/'+path;
- var readable;
- var writable;
- stat(_src,function(err,st){
- if(err){
- throw err;
- }
-
- if(st.isFile()){
- readable=fs.createReadStream(_src);//创建读取流
- writable=fs.createWriteStream(_dst);//创建写入流
- readable.pipe(writable);
- }else if(st.isDirectory()){
- exists(_src,_dst,copy);
- }
- });
- });
- });
- }
-
- var exists=function(src,dst,callback){
- //测试某个路径下文件是否存在
- fs.exists(dst,function(exists){
- if(exists){//不存在
- callback(src,dst);
- }else{//存在
- fs.mkdir(dst,function(){//创建目录
- callback(src,dst)
- })
- }
- })
- }
-
- exists('../dist/static','E:\\code\\lou\\public\\static',copy)
|