diff --git a/plugin-cli/.gitignore b/plugin-cli/.gitignore new file mode 100644 index 0000000..04c01ba --- /dev/null +++ b/plugin-cli/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +dist/ \ No newline at end of file diff --git a/plugin-cli/.npmignore b/plugin-cli/.npmignore new file mode 100644 index 0000000..eb6bd5d --- /dev/null +++ b/plugin-cli/.npmignore @@ -0,0 +1,3 @@ +node_modules/ +src/ +tsconfig.json \ No newline at end of file diff --git a/plugin-cli/README.md b/plugin-cli/README.md new file mode 100644 index 0000000..7edd966 --- /dev/null +++ b/plugin-cli/README.md @@ -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) \ No newline at end of file diff --git a/plugin-cli/package.json b/plugin-cli/package.json new file mode 100644 index 0000000..2dbee3f --- /dev/null +++ b/plugin-cli/package.json @@ -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" + } +} \ No newline at end of file diff --git a/plugin-cli/scripts/build.js b/plugin-cli/scripts/build.js new file mode 100644 index 0000000..655859f --- /dev/null +++ b/plugin-cli/scripts/build.js @@ -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)); + diff --git a/plugin-cli/scripts/index.js b/plugin-cli/scripts/index.js new file mode 100644 index 0000000..4740398 --- /dev/null +++ b/plugin-cli/scripts/index.js @@ -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'); +} \ No newline at end of file diff --git a/plugin-cli/scripts/release.js b/plugin-cli/scripts/release.js new file mode 100644 index 0000000..39898e9 --- /dev/null +++ b/plugin-cli/scripts/release.js @@ -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); +}) + + diff --git a/plugin-cli/src/index.ts b/plugin-cli/src/index.ts new file mode 100644 index 0000000..07b05ac --- /dev/null +++ b/plugin-cli/src/index.ts @@ -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; + }; +} \ No newline at end of file diff --git a/plugin-cli/tsconfig.json b/plugin-cli/tsconfig.json new file mode 100644 index 0000000..227342c --- /dev/null +++ b/plugin-cli/tsconfig.json @@ -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"] +} \ No newline at end of file