tools/build.js

97 lines
2.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 构建脚本 - 生成可部署到nginx的静态文件
*/
const fs = require('fs-extra');
const path = require('path');
const glob = require('glob');
// 输出目录
const outputDir = 'dist';
// 要包含的文件类型
const includeFiles = [
'*.html',
'*.js',
'*.css',
'*.svg',
'*.png',
'*.jpg',
'*.jpeg',
'*.gif',
'*.ico',
'*.json',
'*/**.html',
'*/**.js',
'*/**.css',
'*/**.svg',
'*/**.png',
'*/**.jpg',
'*/**.jpeg',
'*/**.gif'
];
// 要排除的文件和目录
const excludeFiles = [
'node_modules/**',
'dist/**',
'package.json',
'package-lock.json',
'build.js',
'server.js',
'update-statistics.php',
'get-stat.php',
'statistics.json',
'nginx.conf.example',
'README_STAT.md',
'NGINX部署说明.md'
];
// 清理构建目录
console.log('清理输出目录...');
fs.removeSync(outputDir);
fs.ensureDirSync(outputDir);
// 复制文件
console.log('复制文件到输出目录...');
let fileCount = 0;
// 处理要包含的文件
includeFiles.forEach(pattern => {
const files = glob.sync(pattern, { ignore: excludeFiles });
files.forEach(file => {
const dest = path.join(outputDir, file);
fs.ensureDirSync(path.dirname(dest));
fs.copySync(file, dest);
fileCount++;
});
});
// 创建预设的统计数据文件
console.log('创建预设统计数据...');
const presetStats = {
visitorCount: 1254,
usageCount: 5840,
lastVisit: 0
};
fs.writeJsonSync(path.join(outputDir, 'preset-stats.json'), presetStats, { spaces: 2 });
// 创建简单的README
fs.writeFileSync(path.join(outputDir, 'README.md'), `# IT工具合集网站 - 静态版
此目录包含IT工具合集网站的静态版本可直接部署到nginx服务器。
## 部署说明
1. 将此目录下的所有文件上传到您的Web服务器
2. 配置nginx指向此目录
3. 访问您的网站域名即可
## 统计数据说明
统计数据访问人数、使用次数使用浏览器的localStorage存储对每个用户都是独立的。
`);
console.log(`构建完成! ${fileCount}个文件已复制到${outputDir}目录`);