新增package包管理,移除bower包管理

pull/490/head
Karson 2025-03-28 17:21:30 +08:00
parent 49e8cc52e7
commit af25765558
6 changed files with 3197 additions and 244 deletions

4
.npmrc 100644
View File

@ -0,0 +1,4 @@
# 使用自定义镜像源
registry=http://mirrors.tencent.com/npm/
#关闭SSL验证
strict-ssl=false

138
Gruntfile.js 100644
View File

@ -0,0 +1,138 @@
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
main: {
files: []
}
}
});
var build = function (module, type, callback) {
var config = {
compile: {
options: type === 'js' ? {
optimizeCss: "standard",
optimize: "none", //可使用uglify|closure|none
preserveLicenseComments: true,
removeCombined: false,
baseUrl: "./public/assets/js/", //JS文件所在的基础目录
name: "require-" + module, //来源文件,不包含后缀
out: "./public/assets/js/require-" + module + ".min.js" //目标文件
} : {
optimizeCss: "default",
optimize: "uglify", //可使用uglify|closure|none
cssIn: "./public/assets/css/" + module + ".css", //JS文件所在的基础目录
out: "./public/assets/css/" + module + ".min.css" //目标文件
}
}
};
var content = grunt.file.read("./public/assets/js/require-" + module + ".js"),
pattern = /^require\.config\(\{[\r\n]?[\n]?(.*?)[\r\n]?[\n]?}\);/is;
var matches = content.match(pattern);
if (matches) {
if (type === 'js') {
var data = matches[1].replaceAll(/(urlArgs|baseUrl):(.*)\n/gi, '');
const parse = require('parse-config-file'), fs = require('fs');
require('jsonminify');
data = JSON.minify("{\n" + data + "\n}");
let options = parse(data);
options.paths.tableexport = "empty:";
Object.assign(config.compile.options, options);
}
let requirejs = require("./application/admin/command/Min/r");
try {
requirejs.optimize(config.compile.options, function (buildResponse) {
// var contents = require('fs').readFileSync(config.compile.options.out, 'utf8');
callback();
}, function (err) {
console.error(err);
callback();
});
} catch (err) {
console.error(err);
callback();
}
}
};
// 加载 "copy" 插件
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.registerTask('frontend:js', 'build frontend js', function () {
var done = this.async();
build('frontend', 'js', done);
});
grunt.registerTask('backend:js', 'build backend js', function () {
var done = this.async();
build('backend', 'js', done);
});
grunt.registerTask('frontend:css', 'build frontend css', function () {
var done = this.async();
build('frontend', 'css', done);
});
grunt.registerTask('backend:css', 'build frontend css', function () {
var done = this.async();
build('backend', 'css', done);
});
// 注册部署JS和CSS任务
grunt.registerTask('deploy', 'deploy', function () {
const fs = require('fs');
const path = require("path")
const nodeModulesDir = path.resolve(__dirname, "./node_modules");
const getAllFiles = function (dirPath, arrayOfFiles) {
files = fs.readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach(function (file) {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles)
} else {
arrayOfFiles.push(path.join(__dirname, dirPath, "/", file))
}
});
return arrayOfFiles
};
const mainPackage = grunt.config.get('pkg');
let dists = mainPackage.dists || [];
let files = [];
// 兼容旧版本bower使用的目录
let specialKey = {
'fastadmin-bootstraptable': 'bootstrap-table',
'sortablejs': 'Sortable',
'tableexport.jquery.plugin': 'tableExport.jquery.plugin',
};
Object.keys(dists).forEach(key => {
let src = ["**/*LICENSE*", "**/*license*"];
src = src.concat(Array.isArray(dists[key]) ? dists[key] : [dists[key]]);
files.push({expand: true, cwd: nodeModulesDir + "/" + key, src: src, dest: 'public/assets/libs/' + (specialKey[key] || key) + "/"});
});
// 兼容bower历史路径文件
files = [...files,
{src: nodeModulesDir + "/toastr/build/toastr.min.css", dest: "public/assets/libs/toastr/toastr.min.css"},
{src: nodeModulesDir + "/bootstrap-slider/dist/css/bootstrap-slider.css", dest: "public/assets/libs/bootstrap-slider/slider.css"}
]
grunt.config.set('copy.main.files', files);
grunt.task.run("copy:main");
});
// 注册默认任务
grunt.registerTask('default', ['deploy', 'frontend:js', 'backend:js', 'frontend:css', 'backend:css']);
};

View File

@ -1,140 +0,0 @@
#!/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清理完成');

View File

@ -1,104 +0,0 @@
{
"name": "fastadmin",
"description": "the fastest admin framework",
"main": "",
"license": "Apache2.0",
"homepage": "https://www.fastadmin.net",
"private": true,
"dependencies": {
"jquery": "^3.7.1",
"bootstrap": "^3.3.7",
"font-awesome": "^4.6.1",
"bootstrap-table": "fastadmin-bootstraptable#~1.11.5",
"jstree": "~3.3.2",
"moment": "~2.29.0",
"toastr": "~2.1.3",
"eonasdan-bootstrap-datetimepicker": "~4.17.43",
"bootstrap-select": "~1.13.18",
"require-css": "~0.1.8",
"tableExport.jquery.plugin": "~1.10.3",
"jquery-slimscroll": "~1.3.8",
"jquery.cookie": "~1.4.1",
"Sortable": "~1.10.2",
"nice-validator": "karsonzhang/fastadmin-nicevalidator#~1.1.6",
"art-template": "~3.1.3",
"bootstrap-daterangepicker": "~2.1.25",
"fastadmin-citypicker": "~1.3.1",
"fastadmin-cxselect": "~1.4.0",
"fastadmin-dragsort": "~1.0.0",
"fastadmin-addtabs": "~1.0.8",
"fastadmin-selectpage": "^1.0.12",
"fastadmin-layer": "~3.5.1",
"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"
}
}

2945
package-lock.json generated 100644

File diff suppressed because it is too large Load Diff

110
package.json 100644
View File

@ -0,0 +1,110 @@
{
"name": "fastadmin",
"version": "1.6.0",
"description": "FastAdmin是一款基于ThinkPHP+Bootstrap的极速后台开发框架。",
"scripts": {
"build": "grunt"
},
"repository": {
"type": "git",
"url": "git@gitee.com:karson/fastadmin.git"
},
"dependencies": {
"bootstrap": "^3.4.1",
"bootstrap-daterangepicker": "~2.1.25",
"bootstrap-select": "^1.13.18",
"bootstrap-slider": "^11.0.2",
"eonasdan-bootstrap-datetimepicker": "^4.17.49",
"cxselect": "^1.4.0",
"fastadmin-addtabs": "^1.0.8",
"fastadmin-arttemplate": "^3.1.4",
"fastadmin-bootstraptable": "^1.11.12",
"fastadmin-citypicker": "^1.3.6",
"fastadmin-cxselect": "npm:cxselect@^1.4.0",
"fastadmin-dragsort": "^1.0.5",
"fastadmin-layer": "^3.5.6",
"fastadmin-selectpage": "^1.1.1",
"fastadmin-nicevalidator": "^1.1.6",
"art-template": "npm:fastadmin-arttemplate@^3.1.4",
"bootstrap-table": "npm:fastadmin-bootstraptable@^1.11.12",
"nice-validator": "npm:fastadmin-nicevalidator@^1.1.6",
"font-awesome": "^4.6.1",
"jquery": "^3.7.1",
"jquery-slimscroll": "~1.3.8",
"jquery.cookie": "~1.4.1",
"jstree": "~3.3.2",
"moment": "^2.10",
"require-css": "~0.1.8",
"sortablejs": "^1.12.0",
"tableexport.jquery.plugin": "^1.20.0",
"toastr": "~2.1.3"
},
"author": "FastAdmin",
"license": "Apache-2.0",
"devDependencies": {
"grunt": "^1.5.3",
"grunt-contrib-clean": "^2.0.1",
"grunt-contrib-copy": "^1.0.0",
"jsonminify": "^0.4.2",
"parse-config-file": "^1.0.4"
},
"overrides": {
"canvg": {
"xmldom": "^0.7.0"
},
"tableexport.jquery.plugin": {
"xlsx": "npm:@e965/xlsx@^0.20.3"
},
"eonasdan-bootstrap-datetimepicker": {
"moment-timezone": "^0.5.35"
}
},
"dists": {
"art-template": "dist/**",
"bootstrap": "dist/**",
"bootstrap-daterangepicker": [
"daterangepicker.js",
"daterangepicker.css"
],
"bootstrap-select": "dist/**",
"bootstrap-slider": [
"dist/**",
"*.css",
"*.js"
],
"coloris": [
"dist/umd/**",
"dist/*.css"
],
"eonasdan-bootstrap-datetimepicker": "build/**",
"fastadmin-addtabs": "*.js",
"fastadmin-bootstraptable": "dist/**",
"fastadmin-citypicker": "dist/**",
"fastadmin-cxselect": "js/**",
"fastadmin-dragsort": "*.js",
"fastadmin-layer": "dist/**",
"fastadmin-selectpage": "*",
"font-awesome": [
"css/**",
"fonts/**"
],
"jquery": "dist/**",
"jquery-slimscroll": "*.js",
"jquery.cookie": "*.js",
"jstree": "dist/**",
"moment": [
"moment.js",
"locale/**"
],
"nice-validator": "dist/**",
"require-css": "*.js",
"sortablejs": "*.js",
"tableexport.jquery.plugin": "tableExport.min.js",
"toastr": [
"*.less",
"*.css",
"*.js",
"build/**"
]
}
}