11const fs = require ( "fs" ) ;
22const path = require ( "path" ) ;
33
4- // 获取项目根目录( GitHub Actions 中可用 GITHUB_WORKSPACE )
4+ // 项目根目录(本地或 GitHub Actions 都可用 )
55const projectRoot = process . env . GITHUB_WORKSPACE || path . resolve ( __dirname , "../" ) ;
66const scriptingDir = projectRoot ;
77const readmePath = path . join ( projectRoot , "README.md" ) ;
88
99let collectedLinks = [ ] ;
1010
11- // 遍历目录,收集 .scripting 文件
11+ // 遍历目录(递归收集 .scripting 文件)
1212function walkDir ( dir , callback ) {
1313 fs . readdirSync ( dir ) . forEach ( ( file ) => {
1414 const filepath = path . join ( dir , file ) ;
1515 const stat = fs . statSync ( filepath ) ;
1616 if ( stat . isFile ( ) && filepath . endsWith ( ".scripting" ) ) {
1717 callback ( filepath ) ;
1818 } else if ( stat . isDirectory ( ) ) {
19- walkDir ( filepath , callback ) ; // 递归子目录
19+ walkDir ( filepath , callback ) ;
2020 }
2121 } ) ;
2222}
2323
2424// 生成 scripting.fun 链接
2525function generateScriptLink ( filename ) {
2626 const baseUrl = "https://github.com/ScriptingApp/Community-Scripts/raw/refs/heads/main/" ;
27- const relativePath = path . relative ( scriptingDir , filename ) . replace ( / \\ / g, "/" ) ; // 保留目录结构
27+ const relativePath = path . relative ( scriptingDir , filename ) . replace ( / \\ / g, "/" ) ;
2828 const fullUrl = baseUrl + encodeURIComponent ( relativePath ) ;
2929 const name = path . basename ( filename , ".scripting" ) ; // 去掉后缀
3030 const link = `https://scripting.fun/import_scripts?urls=${ encodeURIComponent ( `[\"${ fullUrl } \"]` ) } ` ;
@@ -41,7 +41,7 @@ let readmeContent = fs.existsSync(readmePath) ? fs.readFileSync(readmePath, "utf
4141const startTag = "<!-- SCRIPTS_LINKS_START -->" ;
4242const endTag = "<!-- SCRIPTS_LINKS_END -->" ;
4343
44- // Markdown 列表 + 时间戳保证内容每次都变
44+ // Markdown 列表 + 时间戳保证每次文件内容变化
4545const linksMarkdown = collectedLinks . map ( ( { name, link } ) => `- [${ name } ](${ link } )` ) . join ( "\n" ) ;
4646const replacement = `${ startTag } \n${ linksMarkdown } \n<!-- updated at ${ new Date ( ) . toISOString ( ) } -->\n${ endTag } ` ;
4747
@@ -52,6 +52,6 @@ if (readmeContent.includes(startTag)) {
5252 readmeContent += `\n\n${ replacement } \n` ;
5353}
5454
55- // 写入 README.md,GitHub Actions workflow 会提交
55+ // 写入 README.md,workflow 会自动提交
5656fs . writeFileSync ( readmePath , readmeContent , "utf-8" ) ;
5757console . log ( "README.md updated with latest links." ) ;
0 commit comments