当前位置: 首页 > news >正文

新闻热点大事件安徽网络关键词优化

新闻热点大事件,安徽网络关键词优化,杭州网站优化,惠州网站建设设计pxToRem.js /*** 使用方式:* 与引入的文件放在同一目录下进行引用配置,执行:node (定义的文件)*/ const fs require(fs) const path require(path) /*** entry:入口文件路径 type:Strng* pxtopx:以倍数转…

pxToRem.js

/*** 使用方式:* 与引入的文件放在同一目录下进行引用配置,执行:node (定义的文件)*/
const fs = require('fs')
const path = require('path')
/*** entry:入口文件路径 type:Strng* pxtopx:以倍数转化px数值,计算方式为除法 ,type:Boolean* pxtorem:以倍数转化rem数值,计算方式为除法 ,type:Boolean* baseNumber:指定除数的基数,type:Number* includeFileTypeList:指定包含的文件类型后缀,type:Array* excludeFile:不包括的文件,可以是路径,type:Array*/
class pxToRemUtil {/*** @type {entry: String, pxtopx: boolean, pxtorem: boolean, baseNumber: number, includeFileTypeList: Array, excludeFile: Array}* @param {初始化参数} option*/constructor(option) {if (!option) {this._logError('请传入配置参数')process.exit(0)}if (!option.entry || !option.entry.trim()) {this._logError('未指定入口文件,请指定')process.exit(0)}if (!option.pxtopx && !option.pxtorem) {this._logError('未指定pxtopx或者pxtorem,检查配置')process.exit(0)}if (!option.baseNumber) {this._logError('未指定基数')process.exit(0)}if (option.pxtopx && option.pxtorem) {this._logError('未指定pxtopx或者pxtorem错误,检查配置')process.exit(0)}this._beginPath = option.entrythis._pxtopx = option.pxtopxthis._pxtorem = option.pxtoremif (this._pxtopx) this._unit = 'px'if (this._pxtorem) this._unit = 'rem'this.BASENUMBER = option.baseNumberthis._includeFileTypeList = option.includeFileTypeList || []this._excludeFile = option.excludeFile || []this._timer = nullthis._fileNumber = 0this._writeFileTimer = nullthis._arr = []this.getRegFile()this.sureHandler()}getRegFile() {let _strconnect = ''this._includeFileTypeList.forEach(item => {_strconnect += `(${item})$|`})_strconnect = _strconnect.length > 1 ? _strconnect.slice(0, _strconnect.length - 1) : ''_strconnect = this._includeFileTypeList.length > 0 ? '^.+' + _strconnect : ''this.regFile = new RegExp(_strconnect)}sureHandler() {process.stdin.setEncoding('utf8')process.stdout.write('此操作不可逆,确认是否进行(Y/n)?')process.stdin.on('data', input => {input = input.toString().trim()if (['Y', 'y', 'YES', 'yes'].indexOf(input) > -1 || !Boolean(input)) {this.fileDisplay(this._beginPath, this.changeFile.bind(this))}if (['N', 'n', 'NO', 'no'].indexOf(input) > -1) process.exit(0)})}fileDisplay(url, cb) {const filePath = path.resolve(url)fs.readdir(filePath, (err, files) => {if (err) return console.error('Error:(spec)', err)files.forEach(filename => {const filedir = path.join(filePath, filename)fs.stat(filedir, (eror, stats) => {if (eror) return console.error('Error:(spec)', err)const isFile = stats.isFile()const isDir = stats.isDirectory()if (isFile) {let exclude = this._excludeFile.some(item => {return filedir.includes(item)})let checkIsImage = filedir.match(/\.(png|jpg|gif|jpeg|webp|ttf|svg)$/)if (filedir.match(this.regFile) && !exclude && !checkIsImage) {this._arr.push({modified: false,path: filedir.replace(__dirname, '').replace(/\\/gim, '/'),})}if (this._timer) clearTimeout(this._timer)this._timer = setTimeout(() => cb && cb(this._arr), 200)}// 如果是文件夹if (isDir) this.fileDisplay(filedir, cb)})})})}changeFile() {/**重新写入文件 替换掉文件的px数值 */const self = thisthis._arr.forEach(item => {fs.readFile('.' + item.path, (err, data) => {let result = data.toString()var reg = /(\-|- |\+ )?([0-9]*\.[0-9]*|\d)+(px\)?)/gilet newStr = result.replace(reg, function (_x) {item.modified = truelet n = _x.search(/px\)/) >= 0 ? 'px\\)' : 'px'let reg = new RegExp(eval(`/(- |\\+ )+([0-9]*\\.[0-9]*|\\d)+${n}/gi`))if (_x.match(reg)) {let C = ''if (_x.search(/\+/) >= 0) {C = '+'} else if (_x.search(/\-/) >= 0) {C = '-'}if (_x.search(/px\)/)) _x = _x.replace(/(- |\+ )/, '').replace(/px/i, '')if (_x.search(/\)/) >= 0) return `${C} ` + parseFloat(_x) / self.BASENUMBER + `${self._unit})`if (!_x.search(/\)/) >= 0) return `${C} ` + parseFloat(_x) / self.BASENUMBER + `${self._unit}`}return parseFloat(_x) / self.BASENUMBER + `${self._unit}`})const opt = {flag: 'w',}if (newStr) {fs.writeFile('.' + item.path, newStr, opt, (err, success) => {if (this._writeFileTimer) clearTimeout(this._writeFileTimer)this._writeFileTimer = setTimeout(() => {this._logSuccess(self._fileNumber + ' 个文件写入成功')process.exit(0)}, 200)if (err) {this._logError(err)process.exit(0)} else {if (item.modified) {self._fileNumber++this._logSuccess('更改并写入:' + item.path.slice(1) + ' 成功')}}})}})})}_logSuccess(str) {console.log('\x1B[32m%s\x1B[39m', str)}_logError(str) {console.log('\x1B[31m%s\x1B[39m', str)}
}
module.exports = pxToRemUtil 

execFile.js

//将上面文件引入
let pxToRemUtil = require('./pxToRemUtil')/*** 接受的参数含义* entry:入口文件路径 type:Strng* pxtopx:以倍数转化px数值,计算方式为除法 ,type:Boolean* pxtorem:以倍数转化rem数值,计算方式为除法 ,type:Boolean* baseNumber:指定除数的基数,type:Number* includeFileTypeList:指定包含的文件类型后缀,type:Array* excludeFile:不包括的文件,可以是路径,type:Array*/
new pxToRemUtil({entry:'./',//需要修改的文件入口pxtorem:true,//设置为px转rembaseNumber:100,//将整体的数值除100,例如10px变成0.1remexcludeFile:[''],//可选值,排除的文件名includeFileTypeList:['.vue','.css']//可选值,包含改那些文件的后缀list
})

然后再控制台中执行:

node execFile.js

http://www.hkea.cn/news/699924/

相关文章:

  • 东营网站建设预算价格百度网盘网页版入口官网
  • 网站建设中标公告18款禁用看奶app入口
  • 网站运营人员岗位职责长沙正规seo优化价格
  • cnzz统计代码放在后台网站为什么没显示seo的英文全称是什么
  • 杭州企业网站建设方案广告门
  • 自己免费做网站(二)seo优化公司信
  • 广州外贸b2b网站建设刷钻业务推广网站
  • 做企业网站用什么怎样宣传自己的品牌
  • 濮阳做网站的公司我的百度账号
  • 美食网站开发如何做好网络营销工作
  • 网站建设案例资料今天的新闻内容
  • 台州专业网站建设方案seo软文代写
  • 个人网站 百度推广全球搜索大全
  • 网站消息推送5118素材网站
  • 天津 响应式网站设计企业网站模板免费
  • 网站用花生壳nas做存储百度seo发包工具
  • wordpress cache深圳纯手工seo
  • 怎样找到正规代加工网站百度地图3d实景地图
  • 潍坊网站建设公司网站搭建免费
  • 惠州做网站好的公司下载百度语音导航地图安装
  • 春节网站怎么做小说排行榜百度搜索风云榜
  • 商城服务是什么软件seo是指什么岗位
  • 无锡网站建设有限公司网站快速收录的方法
  • 网站建设通报推广网站多少钱
  • 网络推广公司成都seo排名优化教程
  • 一台手机登录微信网页版西安优化外
  • 如何做旅游攻略网站长沙seo优化推荐
  • 长春火车站电话咨询电话快排seo
  • 龙城建设网站公司网站内容优化方法
  • 南通网站建设搭建网站卖链接