mirror of https://gitee.com/karson/fastadmin.git
新增bower-cleanup.js用于移除bower.json中ignores参数配置的文件或文件夹
bower.json新增ignores配置pull/490/head v1.5.4.20250312
parent
31c3d7b469
commit
ea43d62b1d
5
.bowerrc
5
.bowerrc
|
|
@ -7,5 +7,8 @@
|
||||||
"jspdf",
|
"jspdf",
|
||||||
"jspdf-autotable",
|
"jspdf-autotable",
|
||||||
"pdfmake"
|
"pdfmake"
|
||||||
]
|
],
|
||||||
|
"scripts":{
|
||||||
|
"postinstall": "node bower-cleanup.js"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
/public/assets/libs/
|
/public/assets/libs/
|
||||||
/public/assets/addons/*
|
/public/assets/addons/*
|
||||||
/public/uploads/*
|
/public/uploads/*
|
||||||
|
.DS_Store
|
||||||
.idea
|
.idea
|
||||||
composer.lock
|
composer.lock
|
||||||
*.log
|
*.log
|
||||||
|
|
|
||||||
|
|
@ -302,7 +302,7 @@ return [
|
||||||
//允许跨域的域名,多个以,分隔
|
//允许跨域的域名,多个以,分隔
|
||||||
'cors_request_domain' => 'localhost,127.0.0.1',
|
'cors_request_domain' => 'localhost,127.0.0.1',
|
||||||
//版本号
|
//版本号
|
||||||
'version' => '1.5.3.20250217',
|
'version' => '1.5.4.20250312',
|
||||||
//API接口地址
|
//API接口地址
|
||||||
'api_url' => 'https://api.fastadmin.net',
|
'api_url' => 'https://api.fastadmin.net',
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,140 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const minimatch = require('minimatch');
|
||||||
|
|
||||||
|
// bower.json和bower_components目录路径
|
||||||
|
const bowerJsonPath = path.resolve(__dirname, './bower.json');
|
||||||
|
const bowerDir = path.resolve(__dirname, './public/assets/libs');
|
||||||
|
|
||||||
|
console.log('Bower postinstall: 开始清理依赖包...');
|
||||||
|
|
||||||
|
// 检查bower.json是否存在
|
||||||
|
if (!fs.existsSync(bowerJsonPath)) {
|
||||||
|
console.error('未找到bower.json文件');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取bower.json配置
|
||||||
|
let bowerConfig;
|
||||||
|
try {
|
||||||
|
bowerConfig = JSON.parse(fs.readFileSync(bowerJsonPath, 'utf8'));
|
||||||
|
} catch (err) {
|
||||||
|
console.error('读取bower.json文件失败:', err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 递归删除文件夹
|
||||||
|
function deleteFolderRecursive(folderPath) {
|
||||||
|
if (fs.existsSync(folderPath)) {
|
||||||
|
fs.readdirSync(folderPath).forEach(file => {
|
||||||
|
const curPath = path.join(folderPath, file);
|
||||||
|
if (fs.lstatSync(curPath).isDirectory()) {
|
||||||
|
// 递归删除子文件夹
|
||||||
|
deleteFolderRecursive(curPath);
|
||||||
|
} else {
|
||||||
|
// 删除文件
|
||||||
|
fs.unlinkSync(curPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 删除空文件夹
|
||||||
|
fs.rmdirSync(folderPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取要删除的文件列表(支持gitignore语法)
|
||||||
|
function getFilesToRemove(packagePath, patterns) {
|
||||||
|
const result = [];
|
||||||
|
|
||||||
|
// 递归查找匹配的文件和文件夹
|
||||||
|
function findMatches(dir, relativePath = '') {
|
||||||
|
if (!fs.existsSync(dir)) return;
|
||||||
|
|
||||||
|
const files = fs.readdirSync(dir);
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
const fullPath = path.join(dir, file);
|
||||||
|
const relPath = relativePath ? path.join(relativePath, file) : file;
|
||||||
|
const stats = fs.statSync(fullPath);
|
||||||
|
|
||||||
|
let matched = false;
|
||||||
|
|
||||||
|
// 检查是否匹配任何模式
|
||||||
|
for (const pattern of patterns) {
|
||||||
|
// 处理目录特定模式(以/结尾)
|
||||||
|
if (pattern.endsWith('/') && stats.isDirectory()) {
|
||||||
|
if (minimatch(relPath, pattern.slice(0, -1)) ||
|
||||||
|
minimatch(relPath + '/', pattern)) {
|
||||||
|
matched = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 普通模式匹配
|
||||||
|
else if (minimatch(relPath, pattern)) {
|
||||||
|
matched = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matched) {
|
||||||
|
result.push(fullPath);
|
||||||
|
}
|
||||||
|
// 如果是目录且未匹配,则递归查找
|
||||||
|
else if (stats.isDirectory()) {
|
||||||
|
findMatches(fullPath, relPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
findMatches(packagePath);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取ignores配置
|
||||||
|
const ignores = bowerConfig.ignores || {};
|
||||||
|
|
||||||
|
// 处理每个包的ignores配置
|
||||||
|
Object.keys(ignores).forEach(packageName => {
|
||||||
|
const packagePath = path.join(bowerDir, packageName);
|
||||||
|
|
||||||
|
// 检查包是否存在
|
||||||
|
if (!fs.existsSync(packagePath)) {
|
||||||
|
console.log(`包 ${packageName} 不存在,跳过`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`处理包: ${packageName}`);
|
||||||
|
|
||||||
|
// 获取要删除的文件/文件夹模式列表
|
||||||
|
const patterns = ignores[packageName] || [];
|
||||||
|
|
||||||
|
// 如果没有模式,跳过
|
||||||
|
if (patterns.length === 0) {
|
||||||
|
console.log(`包 ${packageName} 没有配置忽略模式,跳过`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取匹配的文件和文件夹
|
||||||
|
const filesToRemove = getFilesToRemove(packagePath, patterns);
|
||||||
|
|
||||||
|
// 按照路径长度排序,确保先删除深层文件
|
||||||
|
filesToRemove.sort((a, b) => b.length - a.length);
|
||||||
|
|
||||||
|
// 删除匹配的文件和文件夹
|
||||||
|
filesToRemove.forEach(itemPath => {
|
||||||
|
if (fs.existsSync(itemPath)) {
|
||||||
|
const stats = fs.statSync(itemPath);
|
||||||
|
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
console.log(`删除冗余文件夹: ${itemPath}`);
|
||||||
|
deleteFolderRecursive(itemPath);
|
||||||
|
} else {
|
||||||
|
console.log(`删除冗余文件: ${itemPath}`);
|
||||||
|
fs.unlinkSync(itemPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('Bower postinstall清理完成');
|
||||||
74
bower.json
74
bower.json
|
|
@ -6,7 +6,7 @@
|
||||||
"homepage": "https://www.fastadmin.net",
|
"homepage": "https://www.fastadmin.net",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"jquery": "^3.7.0",
|
"jquery": "^3.7.1",
|
||||||
"bootstrap": "^3.3.7",
|
"bootstrap": "^3.3.7",
|
||||||
"font-awesome": "^4.6.1",
|
"font-awesome": "^4.6.1",
|
||||||
"bootstrap-table": "fastadmin-bootstraptable#~1.11.5",
|
"bootstrap-table": "fastadmin-bootstraptable#~1.11.5",
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
"tableExport.jquery.plugin": "~1.10.3",
|
"tableExport.jquery.plugin": "~1.10.3",
|
||||||
"jquery-slimscroll": "~1.3.8",
|
"jquery-slimscroll": "~1.3.8",
|
||||||
"jquery.cookie": "~1.4.1",
|
"jquery.cookie": "~1.4.1",
|
||||||
"Sortable": "~1.10.0",
|
"Sortable": "~1.10.2",
|
||||||
"nice-validator": "karsonzhang/fastadmin-nicevalidator#~1.1.6",
|
"nice-validator": "karsonzhang/fastadmin-nicevalidator#~1.1.6",
|
||||||
"art-template": "~3.1.3",
|
"art-template": "~3.1.3",
|
||||||
"bootstrap-daterangepicker": "~2.1.25",
|
"bootstrap-daterangepicker": "~2.1.25",
|
||||||
|
|
@ -30,5 +30,75 @@
|
||||||
"fastadmin-selectpage": "^1.0.12",
|
"fastadmin-selectpage": "^1.0.12",
|
||||||
"fastadmin-layer": "~3.5.1",
|
"fastadmin-layer": "~3.5.1",
|
||||||
"bootstrap-slider": "*"
|
"bootstrap-slider": "*"
|
||||||
|
},
|
||||||
|
"ignores": {
|
||||||
|
"art-template": [
|
||||||
|
".*",
|
||||||
|
"demo",
|
||||||
|
"doc",
|
||||||
|
"loader",
|
||||||
|
"node",
|
||||||
|
"src",
|
||||||
|
"test"
|
||||||
|
],
|
||||||
|
"jquery": [
|
||||||
|
"src",
|
||||||
|
"test",
|
||||||
|
"external"
|
||||||
|
],
|
||||||
|
"bootstrap": [
|
||||||
|
"grunt",
|
||||||
|
"js",
|
||||||
|
"nuget"
|
||||||
|
],
|
||||||
|
"bootstrap-daterangepicker": [
|
||||||
|
"example",
|
||||||
|
"website",
|
||||||
|
"*.html"
|
||||||
|
],
|
||||||
|
"bootstrap-table": [
|
||||||
|
"src"
|
||||||
|
],
|
||||||
|
"eonasdan-bootstrap-datetimepicker": [
|
||||||
|
"docs",
|
||||||
|
"src",
|
||||||
|
"tasks"
|
||||||
|
],
|
||||||
|
"fastadmin-citypicker": [
|
||||||
|
"src"
|
||||||
|
],
|
||||||
|
"fastadmin-cxselect": [
|
||||||
|
"*.html"
|
||||||
|
],
|
||||||
|
"fastadmin-layer": [
|
||||||
|
"src",
|
||||||
|
"test"
|
||||||
|
],
|
||||||
|
"jquery-slimscroll": [
|
||||||
|
"examples"
|
||||||
|
],
|
||||||
|
"jstree": [
|
||||||
|
"src"
|
||||||
|
],
|
||||||
|
"moment": [
|
||||||
|
"src",
|
||||||
|
"ts3.1-*"
|
||||||
|
],
|
||||||
|
"require-css": [
|
||||||
|
"*.sh"
|
||||||
|
],
|
||||||
|
"Sortable": [
|
||||||
|
"entry",
|
||||||
|
"modular",
|
||||||
|
"plugins",
|
||||||
|
"scripts",
|
||||||
|
"src",
|
||||||
|
"st",
|
||||||
|
".*",
|
||||||
|
"*.html"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"jquery": "^3.7.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue