Comparing version 0.0.7 to 0.0.8
@@ -0,0 +0,0 @@ const path = require('path') |
113
lib/line.js
@@ -1,21 +0,1 @@ | ||
//每个文件行数 | ||
const lines = 400 | ||
//源文件,附带路径,最好将代码放在文件目录下执行 | ||
const file = './jquery.js' | ||
//输出文件名称,附带路径(不带后缀) | ||
const dist = './out/backup' | ||
//输出文件后缀,需要带.(可为空'') | ||
const type = '.txt' | ||
//以上配置最终输出文件为: backup1.txt backup2.txt | ||
//从第几行开始丢弃代码 | ||
const del_start_line = 1 | ||
//丢弃多少行 | ||
const del_lines = 3 | ||
//需要配合nodejs使用,安装方式 | ||
/* | ||
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - | ||
sudo apt-get install -y nodejs | ||
*/ | ||
//将line.js 放在需要处理文件同级目录下,按照上面提示配置好,命令行输入 node line.js 即可 | ||
const fs = require('fs') | ||
@@ -25,49 +5,62 @@ const readline = require('readline') | ||
const out = process.stdout | ||
const chalk = require('chalk') | ||
const rl = readline.createInterface({ | ||
input: fs.createReadStream(file) | ||
}); | ||
const styles = { | ||
info: chalk.cyan, | ||
error: chalk.bold.red, | ||
warning: chalk.yellow, | ||
success: chalk.green, | ||
bgRed: chalk.bgRed, | ||
dim: chalk.dim | ||
} | ||
let i = 0 | ||
let index = 1 | ||
let readed = 0 | ||
let lastLines = 0 | ||
let end = false | ||
let startTime = new Date() | ||
let output = fs.createWriteStream(dist + index + type) | ||
module.exports = function line (config) { | ||
const rl = readline.createInterface({ | ||
input: fs.createReadStream(config.source) | ||
}); | ||
rl.on('line', (line) => { | ||
if( i >= del_start_line && i < del_lines + del_start_line) { | ||
var i = 0 | ||
var index = 1 | ||
var readed = 0 | ||
var lastLines = 0 | ||
var end = false | ||
var startTime = new Date() | ||
var output = fs.createWriteStream(config.dist + index + config.ext) | ||
const del_end_line = config.del_lines + config.del_start_line | ||
}else if( i >= lines ) { | ||
i=0 | ||
output.end() | ||
index++ | ||
output = fs.createWriteStream(dist + index + type) | ||
if( del_start_line !== 0){ | ||
output.write(line + "\n") | ||
rl.on('line', (line) => { | ||
if( i < config.del_start_line || i >= del_end_line ) { | ||
if( i >= config.lines ) { | ||
i=0 | ||
output.end() | ||
index++ | ||
output = fs.createWriteStream(config.dist + index + config.ext) | ||
if( config.del_start_line !== 0){ | ||
output.write(line + "\n") | ||
} | ||
} else { | ||
output.write(line + "\n") | ||
} | ||
} | ||
} else { | ||
output.write(line + "\n") | ||
i++; | ||
readed++; | ||
}).on('close', () => { | ||
end = true | ||
let endTime = Date.now(); | ||
console.log(); | ||
console.log(styles.dim('共用时:') + styles.bgRed((endTime - startTime) / 1000) + styles.dim('秒。')); | ||
}); | ||
function show() { | ||
var diff = readed - lastLines; | ||
lastLines = readed; | ||
out.clearLine(); | ||
out.cursorTo(0); | ||
out.write(styles.dim('已处理') + styles.bgRed(readed) + styles.dim('行, 速度:') + styles.bgRed(diff * 2) + styles.dim('行/s')); | ||
if(!end){ | ||
setTimeout(show, 500); | ||
} | ||
} | ||
i++; | ||
readed++; | ||
}).on('close', () => { | ||
end = true | ||
let endTime = Date.now(); | ||
console.log(); | ||
console.log('共用时:' + (endTime - startTime) / 1000 + '秒。'); | ||
}); | ||
function show() { | ||
let diff = readed - lastLines; | ||
lastLines = readed; | ||
out.clearLine(); | ||
out.cursorTo(0); | ||
out.write('已处理' + readed + '行, 速度:' + diff * 2 + '行/s'); | ||
if(!end){ | ||
setTimeout(show, 500); | ||
} | ||
setTimeout(show, 500); | ||
} | ||
setTimeout(show, 500); |
{ | ||
"name": "encp", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "a power copy cli with node js ", | ||
@@ -5,0 +5,0 @@ "preferGlobal": true, |
@@ -0,0 +0,0 @@ # encp |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2
7881
93