mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-04-28 14:18:40 +00:00
feat: add OSS upload functionality
- integrated ali-oss for file uploads - modified upload logic to use OSS instead of SFTP - updated package.json to include ali-oss dependency
This commit is contained in:
parent
7254c95883
commit
52095219a8
@ -1,4 +1,5 @@
|
|||||||
import { confirm, input } from "@inquirer/prompts";
|
import { confirm, input } from "@inquirer/prompts";
|
||||||
|
import OSS from "ali-oss";
|
||||||
import { $ } from "execa";
|
import { $ } from "execa";
|
||||||
import gracefulFs from "graceful-fs";
|
import gracefulFs from "graceful-fs";
|
||||||
import { Octokit } from 'octokit';
|
import { Octokit } from 'octokit';
|
||||||
@ -95,9 +96,21 @@ async function uploadBySFTP(host, port, username, password, filePath, targetFile
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function uploadByOSS(sourceFile, targetFile) {
|
||||||
|
const client = new OSS({
|
||||||
|
region: env.OSS_REGION,
|
||||||
|
accessKeyId: env.OSS_ACCESS_KEY_ID,
|
||||||
|
accessKeySecret: env.OSS_ACCESS_KEY_SECRET,
|
||||||
|
bucket: env.OSS_BUCKET,
|
||||||
|
});
|
||||||
|
await client.put(targetFile, sourceFile, { timeout: 6000000 });
|
||||||
|
}
|
||||||
|
|
||||||
// 试运行
|
// 试运行
|
||||||
const DRYRUN = false;
|
const DRYRUN = false;
|
||||||
|
const COMPILING_JS = false;
|
||||||
const COMPILING_SIMULATOR = false;
|
const COMPILING_SIMULATOR = false;
|
||||||
|
const CREATE_ZIP = false;
|
||||||
|
|
||||||
// 目录
|
// 目录
|
||||||
const masterPath = cwd();
|
const masterPath = cwd();
|
||||||
@ -183,7 +196,7 @@ const minigamePath = join(sourcePath, "adapters");
|
|||||||
const dtsPath = join(sourcePath, "creator-sp.d.ts");
|
const dtsPath = join(sourcePath, "creator-sp.d.ts");
|
||||||
const zipPath = join(masterTempPath, `cocos-enhance-kit-v${kitVersion}-v${engineVersion}.zip`);
|
const zipPath = join(masterTempPath, `cocos-enhance-kit-v${kitVersion}-v${engineVersion}.zip`);
|
||||||
|
|
||||||
if (!DRYRUN) {
|
if (!DRYRUN && COMPILING_JS) {
|
||||||
console.log("开始编译 JavaScript 引擎");
|
console.log("开始编译 JavaScript 引擎");
|
||||||
try {
|
try {
|
||||||
await $$({ cwd: jsPath })`npx gulp build-dev`;
|
await $$({ cwd: jsPath })`npx gulp build-dev`;
|
||||||
@ -228,7 +241,7 @@ console.log("移动目录", cppBuildPath, "->", tempCppBuildPath);
|
|||||||
console.log("移动目录", jsNpmPath, "->", tempJsNpmPath);
|
console.log("移动目录", jsNpmPath, "->", tempJsNpmPath);
|
||||||
|
|
||||||
// 创建压缩包
|
// 创建压缩包
|
||||||
if (!DRYRUN) {
|
if (!DRYRUN && CREATE_ZIP) {
|
||||||
const sourceZipFile = new Zip();
|
const sourceZipFile = new Zip();
|
||||||
console.log("正在压缩", jsPath);
|
console.log("正在压缩", jsPath);
|
||||||
sourceZipFile.addFolder(jsPath, "engine");
|
sourceZipFile.addFolder(jsPath, "engine");
|
||||||
@ -250,7 +263,7 @@ console.log("已压缩至文件", zipPath);
|
|||||||
if (extensionPath) {
|
if (extensionPath) {
|
||||||
// 创建压缩包
|
// 创建压缩包
|
||||||
const payZipPath = join(masterTempPath, `${kitVersion}.zip`);
|
const payZipPath = join(masterTempPath, `${kitVersion}.zip`);
|
||||||
if (!DRYRUN) {
|
if (!DRYRUN && CREATE_ZIP) {
|
||||||
const sourceZipFile = new Zip();
|
const sourceZipFile = new Zip();
|
||||||
console.log("正在压缩", jsPath);
|
console.log("正在压缩", jsPath);
|
||||||
sourceZipFile.addFolder(jsPath, `${kitVersion}/engine`);
|
sourceZipFile.addFolder(jsPath, `${kitVersion}/engine`);
|
||||||
@ -271,14 +284,15 @@ if (extensionPath) {
|
|||||||
if (!DRYRUN) {
|
if (!DRYRUN) {
|
||||||
console.log("正在上传文件", payZipPath);
|
console.log("正在上传文件", payZipPath);
|
||||||
try {
|
try {
|
||||||
await uploadBySFTP(
|
// await uploadBySFTP(
|
||||||
env.HOST,
|
// env.SFTP_HOST,
|
||||||
env.PORT,
|
// env.SFTP_PORT,
|
||||||
env.USERNAME,
|
// env.SFTP_USERNAME,
|
||||||
env.PASSWORD,
|
// env.SFTP_PASSWORD,
|
||||||
payZipPath,
|
// payZipPath,
|
||||||
`/www/wwwroot/download.smallmain.com/cocos-enhance-kit/${engineVersion}/${kitVersion}.zip`,
|
// `/www/wwwroot/download.smallmain.com/cocos-enhance-kit/${engineVersion}/${kitVersion}.zip`,
|
||||||
);
|
// );
|
||||||
|
await uploadByOSS(payZipPath, `/cocos-enhance-kit/${engineVersion}/${kitVersion}.zip`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
await confirm({
|
await confirm({
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@inquirer/prompts": "^7.0.0",
|
"@inquirer/prompts": "^7.0.0",
|
||||||
|
"ali-oss": "^6.22.0",
|
||||||
"execa": "^9.4.1",
|
"execa": "^9.4.1",
|
||||||
"graceful-fs": "^4.2.11",
|
"graceful-fs": "^4.2.11",
|
||||||
"octokit": "^4.0.2",
|
"octokit": "^4.0.2",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user