feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
const chalk = require('chalk')
const spawn = require('cross-spawn')
const defaultConfig = require('cz-customizable');
const { getChangedPackages } = require('./utils')
const typesConfig = [
{ value: 'feat', name: 'A new feature' },
{ value: 'fix', name: 'A bug fix' },
{ value: 'docs', name: 'Documentation only changes' },
{
value: 'style',
name: 'Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)',
},
{
value: 'refactor',
name: 'A code change that neither fixes a bug nor adds a feature',
},
{
value: 'perf',
name: 'A code change that improves performance',
},
{ value: 'test', name: 'Adding missing tests' },
{
value: 'chore',
name: 'Changes to the build process or auxiliary tools',
},
{
value: 'build',
name: 'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
},
{
value: 'ci',
name: 'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
},
{
value: 'revert',
name: 'Reverts a previous commit',
},
]
const { stdout = '' } = spawn.sync(`git diff --staged --name-only`, {
shell: true,
encoding: 'utf8',
stdio: 'pipe',
})
const changedFiles = stdout.split('\n').filter(Boolean)
const changeSet = getChangedPackages(changedFiles)
if (changeSet.size > 1) {
process.stderr.write(
`${[
chalk.yellow(`检测到当前提交可能涉及到多个包的改动,请注意拆分提交粒度`),
].join('\n')}\n`,
)
changeSet.clear()
changeSet.add('multiple')
}
const changedScopes = [...changeSet]
module.exports = {
...defaultConfig,
types: typesConfig.map(({ value, name }) => {
return {
name: `${value}:${new Array(10 - value.length)
.fill(' ')
.join('')}${name}`,
value,
}
}),
messages: {
...defaultConfig.messages,
type: "Select the type of change that you're committing",
scope: 'Ensure the scope of this change',
subject: 'Write a short, imperative tense description of the change',
body: 'Provide a longer description of the change. Use "|" to break new line:\n',
breaking: 'List any BREAKING CHANGES (optional):\n',
confirmCommit: 'Are you sure you want to proceed with the commit above?',
},
scopes: changedScopes.join(','),
allowCustomScopes: false,
skipQuestions: ['customScope', 'footer', 'body'],
allowBreakingChanges: ['feat', 'fix'],
}

View File

@@ -0,0 +1,14 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'header-max-length': [2, 'always', 150],
'subject-full-stop': [0, 'never'],
'subject-case': [
2,
'never',
[
'upper-case', // UPPERCASE
],
],
},
};

View File

@@ -0,0 +1,21 @@
{
"name": "rush-commitlint",
"version": "1.0.0",
"private": true,
"author": "fanwenjie.fe@bytedance.com",
"config": {
"commitizen": {
"path": "common/autoinstallers/rush-commitlint/node_modules/cz-customizable"
}
},
"dependencies": {
"@commitlint/cli": "^17.2.0",
"@commitlint/config-conventional": "^17.2.0",
"@rushstack/rush-sdk": "5.100.2",
"commitizen": "^4.2.6",
"cz-customizable": "^7.2.1"
},
"devDependencies": {
"@types/node": "^18.11.9"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,37 @@
const { RushConfiguration } = require('@rushstack/rush-sdk')
const getRushConfiguration = (function () {
let rushConfiguration = null
return function () {
// eslint-disable-next-line
return (rushConfiguration ||= RushConfiguration.loadFromDefaultLocation({
startingFolder: process.cwd(),
}))
}
})()
function getChangedPackages(changedFiles) {
const changedPackages = new Set()
try {
const rushConfiguration = getRushConfiguration()
const { rushJsonFolder } = rushConfiguration
const lookup = rushConfiguration.getProjectLookupForRoot(rushJsonFolder)
for (const file of changedFiles) {
const project = lookup.findChildPath(file)
// 如果没找到注册的包信息,则认为是通用文件更改
const packageName = project?.packageName || 'misc'
if (!changedPackages.has(packageName)) {
changedPackages.add(packageName)
}
}
} catch (e) {
console.error(e)
throw e
}
return changedPackages
}
exports.getChangedPackages = getChangedPackages
exports.getRushConfiguration = getRushConfiguration