diff --git a/package.json b/package.json index f47054d30..0bc089b84 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "@types/webpack-env": "^1.18.4", "@wessberg/rollup-plugin-ts": "^2.0.4", "add-asset-html-webpack-plugin": "^6.0.0", + "ali-oss": "^6.20.0", "autoresponsive-react": "^1.2.3", "cache-loader": "^4.1.0", "clean-terminal-webpack-plugin": "^3.0.0", @@ -132,8 +133,8 @@ "react-zmage": "0.7.0", "remark-gfm": "^4.0.0", "stats.js": "^0.17.0", - "three": "npm:three-cf@0.122.6", "swiper": "6.8.4", + "three": "npm:three-cf@0.122.6", "xaop": "^2.1.0" }, "resolutions": { diff --git a/utils/publish.ts b/utils/publish.ts index 878b7ed1f..f0e262972 100644 --- a/utils/publish.ts +++ b/utils/publish.ts @@ -1,10 +1,9 @@ -import * as fs from "fs"; +import OSS from 'ali-oss'; +import * as fs from "fs-extra-plus"; import * as path from "path"; import * as rq from "request-promise-native"; -import { getFiles } from "./utils"; -var GitRevisionPlugin = require('git-revision-webpack-plugin'); - -var gitRevisionPlugin = new GitRevisionPlugin(); +import { getFiles } from './utils'; +var gitRevisionPlugin = require('git-revision-webpack-plugin'); let dir = path.resolve("./dist"); @@ -18,7 +17,7 @@ if (formData.BranchName === "master") formData.BranchName = ""; for (let f of files) - formData[f.substr(dir.length + 1)] = fs.createReadStream(f); + formData[f.substring(dir.length + 1)] = fs.createReadStream(f); let url = "http://publish.cfcad.cn:3000/upload"; // let url = `http://127.0.0.1:3000/upload`; @@ -32,3 +31,42 @@ rq.post({ url: url, formData: formData }, function optionalCallback(err, httpRes console.log(`http://t.cfcad.cn/${formData.BranchName}`); } }); + +async function up2oss() +{ + const oss = new OSS({ + region: 'oss-rg-china-mainland', + accessKeyId: process.env.OSS_ACCESS_KEY_ID, + accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET, + bucket: 'webcad', + }); + + let branch = new gitRevisionPlugin().branch(); + if (branch === "master") branch = ""; + + let files = await fs.glob("./dist/**/*"); + for (let file of files) + { + let name = file.substring(7); + if (branch) name = branch + "/" + name; + + if (path.extname(file) === ".map") continue; + if (path.basename(file) === "manifest.json") continue; + + try + { + const uploadResult = await oss.put(name, file); + console.log('上传成功:', name); + const getResult = await oss.get(name); + console.log('获取文件成功:', name); + } + catch (error) + { + console.error('发生错误:', error); + } + } + + console.log("上传完成!"); +} + +up2oss();