first commit

This commit is contained in:
jefferyzhao
2025-07-31 17:44:12 +08:00
commit b9bdc8598b
42390 changed files with 4467935 additions and 0 deletions

21
node_modules/yorkie/src/hooks.json generated vendored Normal file
View File

@ -0,0 +1,21 @@
[
"applypatch-msg",
"pre-applypatch",
"post-applypatch",
"pre-commit",
"prepare-commit-msg",
"commit-msg",
"post-commit",
"pre-rebase",
"post-checkout",
"post-merge",
"pre-push",
"pre-receive",
"update",
"post-receive",
"post-update",
"push-to-checkout",
"pre-auto-gc",
"post-rewrite",
"sendemail-validate"
]

119
node_modules/yorkie/src/install.js generated vendored Normal file
View File

@ -0,0 +1,119 @@
'use strict'
const fs = require('fs')
const path = require('path')
const findParent = require('./utils/find-parent')
const findHooksDir = require('./utils/find-hooks-dir')
const getHookScript = require('./utils/get-hook-script')
const is = require('./utils/is')
const hooks = require('./hooks.json')
const SKIP = 'SKIP'
const UPDATE = 'UPDATE'
const MIGRATE_GHOOKS = 'MIGRATE_GHOOKS'
const MIGRATE_PRE_COMMIT = 'MIGRATE_PRE_COMMIT'
const CREATE = 'CREATE'
function write(filename, data) {
fs.writeFileSync(filename, data)
fs.chmodSync(filename, parseInt('0755', 8))
}
function createHook(depDir, projectDir, hooksDir, hookName, runnerPath) {
const filename = path.join(hooksDir, hookName)
let packageDir
// prioritize package.json next to .git
// this avoids double-install in lerna monorepos where both root and sub
// package depends on this module
if (fs.existsSync(path.join(projectDir, 'package.json'))) {
packageDir = projectDir
} else {
packageDir = findParent(depDir, 'package.json')
}
// In order to support projects with package.json in a different directory
// than .git, find relative path from project directory to package.json
const relativePath = path.join('.', path.relative(projectDir, packageDir))
const hookScript = getHookScript(hookName, relativePath, runnerPath)
// Create hooks directory if needed
if (!fs.existsSync(hooksDir)) fs.mkdirSync(hooksDir)
if (!fs.existsSync(filename)) {
write(filename, hookScript)
return CREATE
}
if (is.ghooks(filename)) {
write(filename, hookScript)
return MIGRATE_GHOOKS
}
if (is.preCommit(filename)) {
write(filename, hookScript)
return MIGRATE_PRE_COMMIT
}
if (is.huskyOrYorkie(filename)) {
write(filename, hookScript)
return UPDATE
}
return SKIP
}
function installFrom(depDir) {
try {
const isInSubNodeModule = (depDir.match(/node_modules/g) || []).length > 1
if (isInSubNodeModule) {
return console.log(
"trying to install from sub 'node_module' directory,",
'skipping Git hooks installation'
)
}
const projectDir = findParent(depDir, 'package.json')
const hooksDir = findHooksDir(projectDir)
const runnerPath = './node_modules/yorkie/src/runner.js'
if (hooksDir) {
hooks
.map(function(hookName) {
return {
hookName: hookName,
action: createHook(depDir, projectDir, hooksDir, hookName, runnerPath)
}
})
.forEach(function(item) {
switch (item.action) {
case MIGRATE_GHOOKS:
console.log(`migrating existing ghooks ${item.hookName} script`)
break
case MIGRATE_PRE_COMMIT:
console.log(
`migrating existing pre-commit ${item.hookName} script`
)
break
case UPDATE:
break
case SKIP:
console.log(`skipping ${item.hookName} hook (existing user hook)`)
break
case CREATE:
break
default:
console.error('Unknown action')
}
})
console.log('done\n')
} else {
console.log("can't find .git directory, skipping Git hooks installation")
}
} catch (e) {
console.error(e)
}
}
module.exports = installFrom

23
node_modules/yorkie/src/runner.js generated vendored Normal file
View File

@ -0,0 +1,23 @@
const fs = require('fs')
const path = require('path')
const execa = require('execa')
const cwd = process.cwd()
const pkg = fs.readFileSync(path.join(cwd, 'package.json'))
const hooks = JSON.parse(pkg).gitHooks
if (!hooks) {
process.exit(0)
}
const hook = process.argv[2]
const command = hooks[hook]
if (!command) {
process.exit(0)
}
console.log(` > running ${hook} hook: ${command}`)
try {
execa.shellSync(command, { stdio: 'inherit' })
} catch (e) {
process.exit(1)
}

30
node_modules/yorkie/src/uninstall.js generated vendored Normal file
View File

@ -0,0 +1,30 @@
'use strict'
const fs = require('fs')
const hooks = require('./hooks.json')
const findParent = require('./utils/find-parent')
const findHooksDir = require('./utils/find-hooks-dir')
const is = require('./utils/is')
function removeHook(dir, name) {
const filename = `${dir}/${name}`
if (fs.existsSync(filename) && is.huskyOrYorkie(filename)) {
fs.unlinkSync(`${dir}/${name}`)
}
}
function uninstallFrom(huskyDir) {
try {
const hooksDir = findHooksDir(findParent(huskyDir, '.git'))
hooks.forEach(function(hookName) {
removeHook(hooksDir, hookName)
})
console.log('done\n')
} catch (e) {
console.error(e)
}
}
module.exports = uninstallFrom

32
node_modules/yorkie/src/utils/find-hooks-dir.js generated vendored Normal file
View File

@ -0,0 +1,32 @@
'use strict'
const fs = require('fs')
const path = require('path')
const findParent = require('./find-parent')
function findHooksDir(dir) {
if (dir) {
let gitDir = path.join(dir, '.git')
if (!fs.existsSync(gitDir)) {
return
}
const stats = fs.lstatSync(gitDir)
if (stats.isFile()) {
// Expect following format
// git: pathToGit
// On Windows pathToGit can contain ':' (example "gitdir: C:/Some/Path")
const gitFileData = fs.readFileSync(gitDir, 'utf-8')
gitDir = gitFileData
.split(':')
.slice(1)
.join(':')
.trim()
}
return path.resolve(dir, gitDir, 'hooks')
}
}
module.exports = findHooksDir

16
node_modules/yorkie/src/utils/find-parent.js generated vendored Normal file
View File

@ -0,0 +1,16 @@
'use strict'
const fs = require('fs')
const path = require('path')
module.exports = function findParent(currentDir, name) {
const dirs = currentDir.split(path.sep)
while (dirs.pop()) {
const dir = dirs.join(path.sep)
if (fs.existsSync(path.join(dir, name))) {
return path.resolve(dir)
}
}
}

100
node_modules/yorkie/src/utils/get-hook-script.js generated vendored Normal file
View File

@ -0,0 +1,100 @@
'use strict'
const normalize = require('normalize-path')
const stripIndent = require('strip-indent')
const pkg = require('../../package.json')
function platformSpecific() {
// On OS X and Linux, try to use nvm if it's installed
if (process.platform === 'win32') {
// Add
// Node standard installation path /c/Program Files/nodejs
// for GUI apps
// https://github.com/typicode/yorkie/issues/49
return stripIndent(
`
# Node standard installation
export PATH="$PATH:/c/Program Files/nodejs"`
)
} else {
// Using normalize to support ' in path
// https://github.com/typicode/yorkie/issues/117
const home = normalize(process.env.HOME)
return stripIndent(
`
# Add common path where Node can be found
# Brew standard installation path /usr/local/bin
# Node standard installation path /usr/local
export PATH="$PATH:/usr/local/bin:/usr/local"
# Try to load nvm using path of standard installation
load_nvm ${home}/.nvm
run_nvm`
)
return arr.join('\n')
}
}
module.exports = function getHookScript(hookName, relativePath, runnerPath) {
// On Windows normalize path (i.e. convert \ to /)
const normalizedPath = normalize(relativePath)
const noVerifyMessage =
hookName === 'prepare-commit-msg'
? '(cannot be bypassed with --no-verify due to Git specs)'
: '(add --no-verify to bypass)'
return [
stripIndent(
`
#!/bin/sh
#yorkie ${pkg.version}
command_exists () {
command -v "$1" >/dev/null 2>&1
}
has_hook_script () {
[ -f package.json ] && cat package.json | grep -q "\\"$1\\"[[:space:]]*:"
}
# OS X and Linux only
load_nvm () {
# If nvm is not loaded, load it
command_exists nvm || {
export NVM_DIR="$1"
[ -s "$1/nvm.sh" ] && . "$1/nvm.sh"
}
}
# OS X and Linux only
run_nvm () {
# If nvm has been loaded correctly, use project .nvmrc
command_exists nvm && [ -f .nvmrc ] && nvm use
}
cd "${normalizedPath}"
# Check if ${hookName} is defined, skip if not
has_hook_script ${hookName} || exit 0`
).trim(),
platformSpecific(),
stripIndent(
`
# Export Git hook params
export GIT_PARAMS="$*"
# Run hook
node "${runnerPath}" ${hookName} || {
echo
echo "${hookName} hook failed ${noVerifyMessage}"
exit 1
}
`
)
].join('\n')
}

28
node_modules/yorkie/src/utils/is.js generated vendored Normal file
View File

@ -0,0 +1,28 @@
'use strict'
const fs = require('fs')
function readFile(filename) {
return fs.readFileSync(filename, 'utf-8')
}
function huskyOrYorkie(filename) {
const data = readFile(filename)
return data.indexOf('#husky') !== -1 || data.indexOf('#yorkie') !== -1
}
function ghooks(filename) {
const data = readFile(filename)
return data.indexOf('// Generated by ghooks. Do not edit this file.') !== -1
}
function preCommit(filename) {
const data = readFile(filename)
return data.indexOf('./node_modules/pre-commit/hook') !== -1
}
module.exports = {
huskyOrYorkie,
ghooks,
preCommit
}