feat: 提交资源

This commit is contained in:
han_han9
2025-10-28 21:55:41 +08:00
parent 591f398085
commit 55c4fcd9ae
2146 changed files with 172747 additions and 456 deletions

View File

@@ -0,0 +1,41 @@
const readFileSync = require("fs")["readFileSync"],
join = require("path")["join"],
spawnSync = require("child_process")["spawnSync"],
PATH = { packageJSON: join(__dirname, "../package.json") };
function checkCreatorTypesVersion(e) {
var o = "win32" === process.platform ? "npm.cmd" : "npm";
let n = spawnSync(o, [
"view",
"@cocos/creator-types",
"versions",
]).stdout.toString();
try {
n = JSON.parse(listString);
} catch (e) {}
return !!n.includes(e);
}
try {
const e = readFileSync(PATH.packageJSON, "utf8"),
f = JSON.parse(e),
g = f.devDependencies["@cocos/creator-types"].replace(/^[^\d]+/, "");
checkCreatorTypesVersion(g) ||
(console.log("Warning:"),
console.log(" @en"),
console.log(" Version check of @cocos/creator-types failed."),
console.log(
` The definition of ${g} has not been released yet. Please export the definition to the ./node_modules directory by selecting "Developer -> Export Interface Definition" in the menu of the Creator editor.`
),
console.log(
" The definition of the corresponding version will be released on npm after the editor is officially released."
),
console.log(" @zh"),
console.log(" @cocos/creator-types 版本检查失败。"),
console.log(
` ${g} 定义还未发布,请先通过 Creator 编辑器菜单 "开发者 -> 导出接口定义",导出定义到 ./node_modules 目录。`
),
console.log(
" 对应版本的定义会在编辑器正式发布后同步发布到 npm 上。"
));
} catch (e) {
console.error(e);
}

View File

@@ -0,0 +1,103 @@
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const args = process.argv.slice(2);
const environment = args[0]; // 'dev' 或 'prod'
const forcePublish = args.includes('--force');
if (!environment || !['dev', 'prod'].includes(environment)) {
console.error('请指定发布环境: dev 或 prod');
console.error('使用方法: npm run publish:dev 或 npm run publish:prod');
process.exit(1);
}
const projectRoot = path.resolve(__dirname, '..');
const npmrcSource = path.join(projectRoot, `.npmrc.${environment}`);
const npmrcTarget = path.join(projectRoot, '.npmrc');
try {
// 检查源配置文件是否存在
if (!fs.existsSync(npmrcSource)) {
throw new Error(`配置文件 .npmrc.${environment} 不存在`);
}
// 检查必要的环境变量
const requiredEnvVars = ['NPM_USERNAME', 'NPM_PASSWORD', 'NPM_EMAIL'];
const missingVars = requiredEnvVars.filter(varName => !process.env[varName]);
if (missingVars.length > 0) {
console.error('❌ 缺少必要的环境变量:');
missingVars.forEach(varName => {
console.error(` - ${varName}`);
});
console.error('\n请设置环境变量:');
console.error('export NPM_USERNAME="your-username"');
console.error('export NPM_PASSWORD="your-password"');
console.error('export NPM_EMAIL="your-email"');
process.exit(1);
}
// 检查 Git 状态(除非强制发布)
if (!forcePublish) {
try {
execSync('git diff-index --quiet HEAD --', { cwd: projectRoot });
} catch (err) {
console.error('❌ Git 工作目录不干净,请先提交更改或使用 --force 参数');
console.error('提示: git add . && git commit -m "发布准备"');
process.exit(1);
}
}
// 复制对应的 .npmrc 配置
fs.copyFileSync(npmrcSource, npmrcTarget);
console.log(`✅ 已切换到 ${environment} 环境配置`);
// 读取 package.json 获取版本信息
const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
const currentVersion = packageJson.version;
console.log(`📦 当前版本: ${currentVersion}`);
console.log(`🚀 开始发布到 ${environment} 仓库...`);
// 验证认证配置
try {
const registryUrl = environment === 'dev'
? 'https://nexus.yangjie.link/repository/npm-snapshots/'
: 'https://nexus.yangjie.link/repository/npm-releases/';
execSync(`npm whoami --registry=${registryUrl}`, {
stdio: 'pipe',
cwd: projectRoot,
env: { ...process.env }
});
console.log('✅ 认证验证成功');
} catch (err) {
console.error('❌ 认证验证失败');
console.error('请检查用户名、密码和邮箱是否正确');
console.error('或者尝试手动登录: npm login');
process.exit(1);
}
// 构建发布命令
const publishCmd = forcePublish ? 'npm publish --force' : 'npm publish';
// 执行发布
execSync(publishCmd, {
stdio: 'inherit',
cwd: projectRoot,
env: { ...process.env }
});
console.log(`✅ 发布成功! 版本 ${currentVersion} 已发布到 ${environment} 仓库`);
} catch (err) {
console.error(`❌ 发布失败: ${err.message}`);
process.exit(1);
} finally {
// 清理临时 .npmrc 文件
if (fs.existsSync(npmrcTarget)) {
fs.unlinkSync(npmrcTarget);
console.log('🧹 已清理临时配置文件');
}
}