dsh-go 手机版 GitHub 自动上传插件(胶囊 + 面板 + 回合脚注)
由 dsh-go 自动上传 · 2026/11/17 12:09:15
This commit is contained in:
commit
7c02807cb6
12 files changed
+1302
No files matched your search
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env node
|
||||
// 命令行上传:node bin/push.js [项目目录…] [--desc 说明] [--all]
|
||||
// 和面板走同一套逻辑(补 README、建仓库、提交、推送),不依赖 dsh-go 桥接。
|
||||
import { existsSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import { loadConfig, readToken } from '../lib/store.js'
|
||||
import { discoverRoots, findProjects, projectName } from '../lib/project.js'
|
||||
import { DSH_HOME } from '../lib/store.js'
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
const dirs = []
|
||||
let description = ''
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const a = args[i]
|
||||
if (a === '--desc' || a === '-d') description = args[++i] ?? ''
|
||||
else if (a === '--all') dirs.push('__all__')
|
||||
else if (a === '--help' || a === '-h') { printHelp(); process.exit(0) }
|
||||
else dirs.push(a)
|
||||
}
|
||||
|
||||
function printHelp() {
|
||||
console.log(`用法:node bin/push.js [目录…] [--desc "说明"] [--all]
|
||||
|
||||
目录 要上传的项目路径,默认当前目录
|
||||
--desc 这次提交的说明(也会在第一次生成 README 时用上)
|
||||
--all 上传工作区里检测到的所有项目
|
||||
`)
|
||||
}
|
||||
|
||||
const token = readToken()
|
||||
if (token === '') {
|
||||
console.error('还没有配置 GitHub 令牌。先运行:node bin/token.js')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
let targets = []
|
||||
if (dirs.includes('__all__')) {
|
||||
targets = findProjects(discoverRoots(loadConfig().roots, DSH_HOME)).map((p) => p.dir)
|
||||
} else if (dirs.length === 0) {
|
||||
targets = [process.cwd()]
|
||||
} else {
|
||||
targets = dirs.map((d) => resolve(d))
|
||||
}
|
||||
|
||||
const { uploadOne } = await import('../lib/index.js')
|
||||
let failed = 0
|
||||
for (const dir of targets) {
|
||||
if (!existsSync(dir)) {
|
||||
console.error(`✗ ${dir} 不存在`)
|
||||
failed++
|
||||
continue
|
||||
}
|
||||
process.stdout.write(`→ ${projectName(dir)} … `)
|
||||
try {
|
||||
const rec = await uploadOne(dir, { description })
|
||||
console.log(`✓ ${rec.repo}${rec.created ? '(新建)' : ''} · ${rec.files} 个文件 · ${rec.url}`)
|
||||
} catch (error) {
|
||||
console.log(`✗ ${error?.message ?? error}`)
|
||||
failed++
|
||||
}
|
||||
}
|
||||
if (failed > 0) process.exitCode = 1
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env node
|
||||
// 交互式写入 GitHub 令牌:在终端里运行,粘贴令牌后回车。令牌只写本机文件,权限 600。
|
||||
import { mkdirSync, writeFileSync, chmodSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
|
||||
const home = process.env.DSH_HOME || join(process.env.HOME || '/root', '.dsh')
|
||||
const file = join(home, 'dsh-go', 'github-token')
|
||||
|
||||
process.stdout.write('把 GitHub 令牌粘贴到这里,然后按回车(只保存在本机):\n')
|
||||
let raw = ''
|
||||
process.stdin.setEncoding('utf8')
|
||||
process.stdin.on('data', (chunk) => { raw += chunk })
|
||||
process.stdin.on('end', () => {
|
||||
const token = raw.split('\n')[0].trim()
|
||||
if (!/^[A-Za-z0-9_]{20,255}$/.test(token)) {
|
||||
console.error('这看起来不像 GitHub 令牌(应该是一串 40 位左右的字母数字,可能以 ghp_ 开头),没有写入。')
|
||||
process.exitCode = 1
|
||||
return
|
||||
}
|
||||
mkdirSync(dirname(file), { recursive: true, mode: 0o700 })
|
||||
writeFileSync(file, `${token}\n`, { mode: 0o600 })
|
||||
chmodSync(file, 0o600)
|
||||
console.log(`已保存到 ${file}(权限 600,不会上传、不会进仓库)。`)
|
||||
console.log('回到 dsh-go 的「GitHub 上传」面板,点一下项目就能上传了。')
|
||||
})
|
||||
Reference in new issue
Block a user