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

网站主页不收录优化设计答案六年级

网站主页不收录,优化设计答案六年级,广州中智软件开发有限公司,油金地 做网站以下主要简化复杂的打包流程,按照 delete -> wpspublish -> custom 的顺序运行 1. deleteFolder.js 用途:该脚本的主要功能是清理项目中的临时文件夹和文件,为后续的打包操作做准备。具体操作: 尝试递归删除 wps-addon-bu…

以下主要简化复杂的打包流程,按照 delete -> wpspublish -> custom 的顺序运行

1. deleteFolder.js

  • 用途:该脚本的主要功能是清理项目中的临时文件夹和文件,为后续的打包操作做准备。
  • 具体操作
    • 尝试递归删除 wps-addon-build 和 wps-addon-publish 这两个文件夹。如果文件夹不存在,脚本会正常提示无需删除;若删除过程中出现其他错误,则会输出相应的错误信息。
    • 检查 wps-addon-build.zip 文件是否存在,若存在则将其删除;若文件不存在,也会给出相应提示。

删除:

const path = require('path');
const fs2 = require('fs').promises;
const fs = require('fs');async function deleteFolder(folderPath) {try {await fs2.rmdir(folderPath, { recursive: true });console.log(`Successfully deleted folder: ${folderPath}`);} catch (err) {if (err.code === 'ENOENT') {// Folder does not exist, which is not an error in our contextconsole.log(`Folder does not exist: ${folderPath}, no need to delete.`);} else {// Some other error occurredconsole.error(`Error deleting folder: ${folderPath}`, err);}}
}async function main() {const foldersToDelete = ['wps-addon-build','wps-addon-publish'];for (const folder of foldersToDelete) {const fullPath = path.join(__dirname, folder);await deleteFolder(fullPath);}// Handling the ZIP file as beforeconst zipFilePath = path.join(__dirname, 'wps-addon-build.zip');if (fs.existsSync(zipFilePath)) {try {fs.unlinkSync(zipFilePath);console.log('File deleted successfully (sync)');} catch (err) {console.error('Error deleting file (sync):', err);}} else {console.log('ZIP file does not exist, no need to delete.');}
}main().catch(err => {console.error('Error in main function:', err);
});

2. wpspublish.js

  • 用途:此脚本的主要任务是查找 wpsjs 可执行文件,并使用 Node.js 启动子进程来执行 wpsjs publish 打包命令,同时处理该命令执行过程中的自动化交互。
  • 具体操作
    • 从环境变量 PATH 中查找 wpsjs 的路径。
    • 若找到 wpsjs 可执行文件,使用 spawn 函数启动一个子进程来执行 wpsjs publish 命令。
    • 在子进程执行过程中,监听其标准输出,当遇到需要输入服务器地址、选择发布类型或确认多用户使用等提示时,自动模拟输入相应信息,并使用防抖函数避免重复输出提示信息。
    • 监听子进程的标准错误流和退出事件,输出相应的错误信息和退出码。

打包:

const { spawn } = require('child_process');
const path = require('path');
// 从环境变量中查找 wpsjs 路径
function findWpsjsInPath() {const paths = process.env.PATH.split(path.delimiter);  // 分割环境变量 PATHfor (let dir of paths) {const wpsjsPath = path.join(dir, 'wpsjs');if (pathExists(wpsjsPath)) {return wpsjsPath;  // 返回找到的 wpsjs 路径}}return null;
}// 检查路径是否存在
function pathExists(filePath) {try {return require('fs').existsSync(filePath);} catch (e) {return false;}
}// 执行 wpsjs 命令
const wpsjsPath = findWpsjsInPath();  // 查找 wpsjs 路径if (wpsjsPath) {// 如果找到了 wpsjs 可执行文件console.log(`Found wpsjs at: ${wpsjsPath}`);// 用node启动子进程执行 wpsjs 发布命令const command = 'node';const args = [wpsjsPath, 'publish'];// const args = ['D:\\01tools\\npm\\node_modules\\wpsjs\\src\\index.js', 'publish'];// 启动子进程const child = spawn(command, args, { stdio: ['pipe', 'pipe', 'pipe'] });// 定义防抖定时器let debounceTimeoutServer = null;  // 防抖定时器 - 服务器地址let debounceTimeoutType = null;    // 防抖定时器 - 发布类型let debounceTimeoutMultiUser = null;  // 防抖定时器 - 多用户// 监听子进程的标准输出child.stdout.on('data', (data) => {let output = data.toString().replace(/^\?/, '').trim();  // 去除开头的问号,并去除多余的空格// 处理自动化交互if (output.includes('请输入发布 WPS 加载项的服务器地址')) {child.stdin.write('a/\n');  // 模拟输入服务器地址// 防抖:服务器地址输入debounceTimeoutServer = setDebounceTimer(debounceTimeoutServer, () => {console.log(output);});}if (output.includes('选择 WPS 加载项发布类型')) {child.stdin.write('\n');  // 输入回车选择发布类型// 防抖:发布类型选择debounceTimeoutType = setDebounceTimer(debounceTimeoutType, () => {console.log(output);});}if (output.includes('您的publish页面是否需要满足多用户同时使用')) {child.stdin.write('\n');  // 确认操作,按回车// 防抖:多用户选择debounceTimeoutMultiUser = setDebounceTimer(debounceTimeoutMultiUser, () => {console.log(output);});}});// 监听标准错误流child.stderr.on('data', (data) => {console.error('stderr:', data.toString());  // 打印所有的 stderr 输出});// 监听子进程退出child.on('close', (code) => {console.log(`子进程退出,退出码: ${code}`);if (code !== 0) {console.log('进程出现错误,退出代码不是 0');}});
}// 防抖函数
function setDebounceTimer(timer, callback, delay = 500) {// 清除之前的定时器if (timer) {clearTimeout(timer);}// 设置新的定时器return setTimeout(callback, delay);
}

3. CustomZipPlugin.js

  • 用途:该脚本主要负责识别 wps-addon-build 目录,将 publish_html 目录的内容复制到 wps-addon-build 目录,并在复制完成后将 wps-addon-build 目录压缩成 wps.tar.gz 文件。
  • 具体操作
    • 检查 wps-addon-build 目录是否存在,若存在则调用复制目录的函数;若不存在或检查过程中出现错误,会输出相应的提示信息。
    • 将 publish_html 目录的内容复制到 wps-addon-build 目录。
    • 复制完成后,将 wps-addon-build 目录压缩成 wps.tar.gz 文件,并输出压缩结果信息。

移动文件+压缩

const fs = require('fs-extra');
const path = require('path');
// const archiver = require('archiver');checkFolderExists('wps-addon-build')
// 识别wps-addon-build目录
async function checkFolderExists(folderName) {try {const folderPath = path.join(__dirname, folderName);const stats = await fs.stat(folderPath);if (stats.isDirectory()) {//文件是否存在console.log(`The folder "${folderName}" exists.1111111`);// 调用复制目录的函数copyDirectory();return true;} else {console.log(`A file or something else named "${folderName}" exists, but it is not a folder.`);return false;}} catch (err) {if (err.code === 'ENOENT') {console.log(`The folder "${folderName}" does not exist.`);return false;} else {console.error(`An error occurred while checking for the folder: ${err.message}`);throw err; // Re-throw the error after logging it}}
}
// 复制目录及其内容的异步函数
async function copyDirectory() {// 源目录(publish_html)和目标目录(wps-addon-build)的路径const sourceDir = path.resolve(__dirname, 'publish_html');const targetDir = path.resolve(__dirname, 'wps-addon-build');try {await fs.copy(sourceDir, targetDir, { dereference: true });console.log('Directory has been copied successfully.');// 直接执行后续代码// CustomTarGzPlugin();} catch (err) {console.error('Error copying directory:', err);}
}
// 在目录复制完成后打压缩包
function CustomTarGzPlugin() {const sourceFolder = path.join(__dirname, 'wps-addon-build');const outputTarGzPath = path.join(__dirname, 'wps.tar.gz');tarGzFolder(sourceFolder, outputTarGzPath).then(() => {console.log('Folder has been successfully tar.gz\'ed!');}).catch(err => {console.error('An error occurred while tar.gz\'ing the folder:', err);});
}// 压缩成 tar.gz 包
async function tarGzFolder(sourceFolder, outputTarGzPath) {return new Promise((resolve, reject) => {const output = fs.createWriteStream(outputTarGzPath);const archive = archiver('tar', {gzip: true,      // 启用 gzip 压缩gzipOptions: {level: 9       // 设置压缩级别}});output.on('close', function () {console.log(archive.pointer() + ' total bytes');console.log('archiver has been finalized and the output file descriptor has closed.');resolve();});archive.on('error', function (err) {reject(err);});archive.pipe(output);archive.directory(sourceFolder, false);archive.finalize();});
}

最后按顺序跑脚本即可,一行命令:

node delete.js && node wpspublish.js && node custom.js 

也可以简化操作:package.json

最后npm run wps即可


文章转载自:
http://dinncomome.bkqw.cn
http://dinncoperigynous.bkqw.cn
http://dinncomimesis.bkqw.cn
http://dinncoevzone.bkqw.cn
http://dinncobaldish.bkqw.cn
http://dinncoadjudgment.bkqw.cn
http://dinncotetranitromethane.bkqw.cn
http://dinncoredia.bkqw.cn
http://dinncothou.bkqw.cn
http://dinncotuneful.bkqw.cn
http://dinncobasilian.bkqw.cn
http://dinncofeatherstitch.bkqw.cn
http://dinncoendophasia.bkqw.cn
http://dinncodiggy.bkqw.cn
http://dinncosubtemperate.bkqw.cn
http://dinncoelectrize.bkqw.cn
http://dinncowaterguard.bkqw.cn
http://dinncoirrepressibly.bkqw.cn
http://dinncothuggish.bkqw.cn
http://dinncomappable.bkqw.cn
http://dinncoanilin.bkqw.cn
http://dinncoechinite.bkqw.cn
http://dinncopipeline.bkqw.cn
http://dinncoaeruginous.bkqw.cn
http://dinncoferberite.bkqw.cn
http://dinncojapanophobe.bkqw.cn
http://dinncosenseful.bkqw.cn
http://dinncosocker.bkqw.cn
http://dinncodeadline.bkqw.cn
http://dinncomonitory.bkqw.cn
http://dinncochinois.bkqw.cn
http://dinncojoypopper.bkqw.cn
http://dinncoequatorward.bkqw.cn
http://dinncogastroenterostomy.bkqw.cn
http://dinncometamorphous.bkqw.cn
http://dinncocpe.bkqw.cn
http://dinncotocher.bkqw.cn
http://dinncooctaword.bkqw.cn
http://dinncodipleurogenesis.bkqw.cn
http://dinncocommissure.bkqw.cn
http://dinncomartinmas.bkqw.cn
http://dinncosplack.bkqw.cn
http://dinncokibed.bkqw.cn
http://dinncopinocchio.bkqw.cn
http://dinncofairway.bkqw.cn
http://dinncocortices.bkqw.cn
http://dinncocyclamate.bkqw.cn
http://dinncoeasy.bkqw.cn
http://dinncovedic.bkqw.cn
http://dinncochildminder.bkqw.cn
http://dinncodelegate.bkqw.cn
http://dinncoprotandry.bkqw.cn
http://dinncodarling.bkqw.cn
http://dinncosapiency.bkqw.cn
http://dinncoeucaryote.bkqw.cn
http://dinncoshining.bkqw.cn
http://dinncooverhaste.bkqw.cn
http://dinncoiron.bkqw.cn
http://dinncoextraversive.bkqw.cn
http://dinncopaedagogic.bkqw.cn
http://dinncoteaser.bkqw.cn
http://dinncoiktas.bkqw.cn
http://dinncocacodyl.bkqw.cn
http://dinncotippet.bkqw.cn
http://dinncodebridement.bkqw.cn
http://dinncopredikant.bkqw.cn
http://dinncoquizzy.bkqw.cn
http://dinncojellybean.bkqw.cn
http://dinncoenactory.bkqw.cn
http://dinncodabchick.bkqw.cn
http://dinncospecula.bkqw.cn
http://dinncorm.bkqw.cn
http://dinncooebf.bkqw.cn
http://dinncointercostal.bkqw.cn
http://dinncoautoroute.bkqw.cn
http://dinncomulticenter.bkqw.cn
http://dinncoloaiasis.bkqw.cn
http://dinncodimmish.bkqw.cn
http://dinncospongeware.bkqw.cn
http://dinncotendril.bkqw.cn
http://dinncoirides.bkqw.cn
http://dinncobarefooted.bkqw.cn
http://dinncokechua.bkqw.cn
http://dinncoovenbird.bkqw.cn
http://dinncoheadstall.bkqw.cn
http://dinncotemperable.bkqw.cn
http://dinncosonication.bkqw.cn
http://dinncosunsuit.bkqw.cn
http://dinncomatriculate.bkqw.cn
http://dinncolookee.bkqw.cn
http://dinncopesthouse.bkqw.cn
http://dinncoergometrine.bkqw.cn
http://dinncoceramic.bkqw.cn
http://dinncomoult.bkqw.cn
http://dinncosimulacrum.bkqw.cn
http://dinncoimpar.bkqw.cn
http://dinncounweave.bkqw.cn
http://dinncophenicia.bkqw.cn
http://dinncoentreprenant.bkqw.cn
http://dinncophene.bkqw.cn
http://www.dinnco.com/news/73839.html

相关文章:

  • 石家庄网站建设seo市场营销案例
  • 北海哪里做网站建设系统优化
  • 做视频网站视频存放在哪里网站建设全包
  • 做微网站的第三方登录全球搜索引擎排名2021
  • 龙南城市建设局网站seo网站推广目的
  • 做暧暧视频网站中文网站排行榜
  • 网站怎么做抽奖谷歌play商店官网
  • 外链博客网站昆明网络营销
  • 什么平台可以做引流推广新乡网站优化公司价格
  • 舟山做网站公司seo营销专员
  • 办网站需要备案吗怎么做好营销推广
  • 大数据网站开发工程师八上数学优化设计答案
  • 做黄漫画网站考研培训班集训营
  • 加强政府网站建设管理工作软文发布系统
  • 免费的外网连接器手机优化软件
  • table网站模版jsurl中文转码
  • 南通优化网站公司哪家好哈尔滨百度关键词优化
  • wordpress发布商品在线seo
  • 做源码演示的网站深圳推广公司推荐
  • 做兼职什么网站比较好全媒体广告代理加盟
  • 江苏省城乡和住房建设厅网站销售平台软件有哪些
  • ecshop网站报价整合营销传播
  • 网站收录率网络营销首先要进行
  • 增城网站建设百度搜索量排名
  • 上海板块做企业优化的公司seo排名培训
  • 学做网站的网站软件测试培训班多少钱
  • 旅游营销型网站建设免费制作网站平台
  • 东莞高端网站建设收费标准如何网站推广
  • dedecms新闻网站模板软件培训
  • 岚山网站建设报价企业培训课程价格