mirror of
https://github.com/cool-team-official/cool-admin-midway-packages.git
synced 2025-12-14 15:32:51 +00:00
插件脚手架
This commit is contained in:
parent
01c8577507
commit
f99203fdfe
2
plugin-cli/.gitignore
vendored
Normal file
2
plugin-cli/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
3
plugin-cli/.npmignore
Normal file
3
plugin-cli/.npmignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
node_modules/
|
||||||
|
src/
|
||||||
|
tsconfig.json
|
||||||
27
plugin-cli/README.md
Normal file
27
plugin-cli/README.md
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
### COOL-ADMIN
|
||||||
|
|
||||||
|
cool-admin一个很酷的后台权限管理系统,开源免费,模块化、插件化、极速开发CRUD,方便快速构建迭代后台管理系统
|
||||||
|
|
||||||
|
大数据、微服务、AI编码快速开发!!!
|
||||||
|
|
||||||
|
|
||||||
|
### 技术栈
|
||||||
|
|
||||||
|
- 后端:node.js midway.js koa.js mysql typescript
|
||||||
|
- 前端:vue.js element-plus jsx pinia vue-router
|
||||||
|
|
||||||
|
### 官网
|
||||||
|
|
||||||
|
[https://cool-js.com](https://cool-js.com)
|
||||||
|
|
||||||
|
|
||||||
|
### 演示地址
|
||||||
|
|
||||||
|
[https://show.cool-admin.com](https://show.cool-admin.com)
|
||||||
|
|
||||||
|
- 账户:admin
|
||||||
|
- 密码:123456
|
||||||
|
|
||||||
|
### 项目地址
|
||||||
|
|
||||||
|
[https://github.com/cool-team-official/cool-admin-midway](https://github.com/cool-team-official/cool-admin-midway)
|
||||||
33
plugin-cli/package.json
Normal file
33
plugin-cli/package.json
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "@cool-midway/plugin-cli",
|
||||||
|
"version": "7.0.0-beta4",
|
||||||
|
"description": "cool-admin midway plugin",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"cool",
|
||||||
|
"cool-admin",
|
||||||
|
"cooljs"
|
||||||
|
],
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://cool-js.com"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"cool-plugin-cli": "scripts/index.js"
|
||||||
|
},
|
||||||
|
"author": "COOL",
|
||||||
|
"readme": "README.md",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@midwayjs/core": "^3.14.0",
|
||||||
|
"archiver": "^6.0.1",
|
||||||
|
"esbuild": "^0.19.11",
|
||||||
|
"esbuild-plugin-copy": "^2.1.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"typescript": "^5.3.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
47
plugin-cli/scripts/build.js
Normal file
47
plugin-cli/scripts/build.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
console.log("cool-plugin-cli run build");
|
||||||
|
|
||||||
|
const esbuild = require('esbuild');
|
||||||
|
const copyPlugin = require('esbuild-plugin-copy').default;
|
||||||
|
const packageJson = require('../package.json');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const projectRoot = process.cwd();
|
||||||
|
|
||||||
|
// 输出目录
|
||||||
|
const outdir = path.join(projectRoot, 'dist');
|
||||||
|
|
||||||
|
// 删除 dist 目录
|
||||||
|
if (fs.existsSync(outdir)) {
|
||||||
|
fs.rmdirSync(outdir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建
|
||||||
|
module.exports.result = esbuild.build({
|
||||||
|
entryPoints: [path.join(projectRoot, 'src', 'index.ts'), path.join(projectRoot, 'test', 'index.ts')],
|
||||||
|
external: Object.keys(packageJson.devDependencies),
|
||||||
|
bundle: true,
|
||||||
|
platform: 'node',
|
||||||
|
outdir,
|
||||||
|
plugins: [
|
||||||
|
copyPlugin({
|
||||||
|
assets: [{
|
||||||
|
from: ['./README.md'],
|
||||||
|
to: ['./README.md']
|
||||||
|
},{
|
||||||
|
from: ['./package.json'],
|
||||||
|
to: ['./package.json']
|
||||||
|
},{
|
||||||
|
from: ['./plugin.json'],
|
||||||
|
to: ['./plugin.json']
|
||||||
|
},{
|
||||||
|
from: ['./assets/*'],
|
||||||
|
to: ['./assets']
|
||||||
|
},{
|
||||||
|
from: ['./src/*'],
|
||||||
|
to: ['./source']
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}).catch(() => process.exit(1));
|
||||||
|
|
||||||
12
plugin-cli/scripts/index.js
Normal file
12
plugin-cli/scripts/index.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const args = process.argv.slice(2); // 去掉数组的前两个元素
|
||||||
|
|
||||||
|
// 发布
|
||||||
|
if(args.includes('--release')){
|
||||||
|
require('./release.js');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打包
|
||||||
|
if(args.includes('--build')){
|
||||||
|
require('./build.js');
|
||||||
|
}
|
||||||
48
plugin-cli/scripts/release.js
Normal file
48
plugin-cli/scripts/release.js
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
console.log("cool-plugin-cli run release");
|
||||||
|
|
||||||
|
const projectRoot = process.cwd();
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const archiver = require('archiver');
|
||||||
|
const pluginJson = require(path.join(projectRoot, 'plugin.json'));
|
||||||
|
|
||||||
|
const packFolder = (folderPath, outputPath) => {
|
||||||
|
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
||||||
|
// 创建文件写入流
|
||||||
|
const output = fs.createWriteStream(outputPath);
|
||||||
|
const archive = archiver('zip', {
|
||||||
|
zlib: { level: 9 } // 设置压缩级别
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听关闭事件
|
||||||
|
output.on('close', function() {
|
||||||
|
console.log(`cool plugin package successfully. Total size: ${archive.pointer()} bytes`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听错误事件
|
||||||
|
archive.on('error', function(err) {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 将压缩内容流连接到文件写入流
|
||||||
|
archive.pipe(output);
|
||||||
|
|
||||||
|
// 添加文件夹
|
||||||
|
archive.directory(folderPath, false);
|
||||||
|
|
||||||
|
// 完成归档
|
||||||
|
archive.finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打包
|
||||||
|
const folderPath = path.join(projectRoot, 'dist'); // 替换为你的文件夹路径
|
||||||
|
const outputPath = path.join(projectRoot, 'release', `${pluginJson.name}_v${pluginJson.version}.cool`); // 替换为你希望创建的 .cool 文件路径
|
||||||
|
|
||||||
|
const { result } = require('./build.js');
|
||||||
|
|
||||||
|
result.then(()=>{
|
||||||
|
packFolder(folderPath, outputPath);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
51
plugin-cli/src/index.ts
Normal file
51
plugin-cli/src/index.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { IMidwayContext, IMidwayApplication } from '@midwayjs/core';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插件信息
|
||||||
|
*/
|
||||||
|
export interface PluginInfo {
|
||||||
|
/** 名称 */
|
||||||
|
name: string;
|
||||||
|
/** 唯一标识 */
|
||||||
|
key: string;
|
||||||
|
/** 钩子 */
|
||||||
|
hook: string;
|
||||||
|
/** 版本 */
|
||||||
|
version: string;
|
||||||
|
/** 描述 */
|
||||||
|
description: string;
|
||||||
|
/** 作者 */
|
||||||
|
author: string;
|
||||||
|
/** logo */
|
||||||
|
logo: string;
|
||||||
|
/** README 使用说明 */
|
||||||
|
readme: string;
|
||||||
|
/** 配置 */
|
||||||
|
config: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插件基类,不建议修改
|
||||||
|
*/
|
||||||
|
export abstract class BasePlugin {
|
||||||
|
/** 插件信息 */
|
||||||
|
pluginInfo: PluginInfo;
|
||||||
|
/** 请求上下文,用到此项无法本地调试,需安装到cool-admin中才能调试 */
|
||||||
|
ctx: IMidwayContext;
|
||||||
|
/** 应用实例,用到此项无法本地调试,需安装到cool-admin中才能调试 */
|
||||||
|
app: IMidwayApplication;
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化插件
|
||||||
|
* @param pluginInfo
|
||||||
|
* @param ctx
|
||||||
|
* @param app
|
||||||
|
*/
|
||||||
|
async init(pluginInfo: PluginInfo, ctx?: IMidwayContext, app?: IMidwayApplication){
|
||||||
|
this.pluginInfo = pluginInfo;
|
||||||
|
this.ctx = ctx;
|
||||||
|
this.app = app;
|
||||||
|
};
|
||||||
|
}
|
||||||
15
plugin-cli/tsconfig.json
Normal file
15
plugin-cli/tsconfig.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"target": "ES2018",
|
||||||
|
"module": "CommonJS",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"noImplicitAny": false,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"resolveJsonModule":true,
|
||||||
|
"outDir": "./dist"
|
||||||
|
},
|
||||||
|
"include": ["src/**/*", "scripts"],
|
||||||
|
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user