dsh-github-studio 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +398 -486
- package/lib/core.js +89 -93
- package/lib/core.mjs +89 -93
- package/lib/diagnostics.js +22 -22
- package/lib/diagnostics.mjs +22 -22
- package/lib/gh.js +15 -15
- package/lib/gh.mjs +15 -15
- package/lib/http.js +47 -50
- package/lib/http.mjs +47 -50
- package/lib/index.js +21 -23
- package/lib/program-inspect.js +24 -50
- package/lib/program-inspect.mjs +24 -50
- package/lib/release-copy.js +59 -62
- package/lib/release-copy.mjs +59 -62
- package/lib/repository-name.js +8 -8
- package/lib/repository-name.mjs +8 -8
- package/lib/search.js +28 -28
- package/lib/search.mjs +28 -28
- package/lib/tools.js +22 -22
- package/lib/tools.mjs +22 -22
- package/package.json +1 -1
- package/lib/drafts.js +0 -20
- package/lib/drafts.mjs +0 -20
package/package.json
CHANGED
package/lib/drafts.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {mkdir,readFile,writeFile,rename,unlink} from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
// 草稿自动保存到 GitHub 工作区;不暴露新按钮,只由表单在输入后与切换时调用。
|
|
4
|
-
const clean=s=>String(s??'').replace(/[^a-zA-Z0-9_.-]/g,'_').replace(/^[._]+/,'').slice(0,60)||'untitled';
|
|
5
|
-
const text=(s,label,max)=>{s=s??'';if(typeof s!=='string'||s.length>max)throw Error(`${label}必须是文本,且不超过 ${max} 字符。`);return s;};
|
|
6
|
-
export class Drafts{
|
|
7
|
-
constructor({root,now=Date.now}={}){this.dir=path.join(root,'workspace','drafts');this.now=now;}
|
|
8
|
-
key(a){const kind=a?.kind;
|
|
9
|
-
if(kind==='repository')return{id:'new-repository',label:'新建仓库'};
|
|
10
|
-
if(kind==='release'){if(typeof a.owner!=='string'||!a.owner.trim()||typeof a.repo!=='string'||!a.repo.trim())throw Error('缺少仓库信息。');return{id:`${clean(a.owner)}/${clean(a.repo)}`,label:`${a.owner}/${a.repo}`};}
|
|
11
|
-
throw Error('草稿类型无效。');}
|
|
12
|
-
file(k){return path.join(this.dir,...k.id.split('/'));}
|
|
13
|
-
normalize(a){return a.kind==='release'?{kind:'release',owner:String(a.owner??'').slice(0,100),repo:String(a.repo??'').slice(0,100),title:text(a.title,'版本标题',200),body:text(a.body,'更新说明',50000)}:{kind:'repository',description:text(a.description,'介绍',350)};}
|
|
14
|
-
markdown(k,d){return d.kind==='release'?`# ${k.label} 发布文案草稿\n\n更新时间:${d.updatedAt}\n\n## 版本标题\n\n${d.title||'(未填写)'}\n\n## 更新说明\n\n${d.body||'(未填写)'}\n`:`# 新建仓库草稿\n\n更新时间:${d.updatedAt}\n\n## 介绍\n\n${d.description||'(未填写)'}\n`;}
|
|
15
|
-
async save(a){const key=this.key(a),data={...this.normalize(a),updatedAt:new Date(this.now()).toISOString()};await mkdir(this.dir,{recursive:true});const base=this.file(key);await mkdir(path.dirname(base),{recursive:true});
|
|
16
|
-
await writeFile(base+'.json.tmp',JSON.stringify(data,null,2),{mode:0o600});await rename(base+'.json.tmp',base+'.json');await writeFile(base+'.md',this.markdown(key,data),{mode:0o600});
|
|
17
|
-
return{savedAt:data.updatedAt,label:key.label};}
|
|
18
|
-
async load(a){try{const data=JSON.parse(await readFile(this.file(this.key(a))+'.json','utf8'));return typeof data==='object'&&data?data:null;}catch{return null;}}
|
|
19
|
-
async clear(a){const base=this.file(this.key(a));await Promise.all([unlink(base+'.json').catch(()=>{}),unlink(base+'.md').catch(()=>{})]);return{ok:true};}
|
|
20
|
-
}
|
package/lib/drafts.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {mkdir,readFile,writeFile,rename,unlink} from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
// 草稿自动保存到 GitHub 工作区;不暴露新按钮,只由表单在输入后与切换时调用。
|
|
4
|
-
const clean=s=>String(s??'').replace(/[^a-zA-Z0-9_.-]/g,'_').replace(/^[._]+/,'').slice(0,60)||'untitled';
|
|
5
|
-
const text=(s,label,max)=>{s=s??'';if(typeof s!=='string'||s.length>max)throw Error(`${label}必须是文本,且不超过 ${max} 字符。`);return s;};
|
|
6
|
-
export class Drafts{
|
|
7
|
-
constructor({root,now=Date.now}={}){this.dir=path.join(root,'workspace','drafts');this.now=now;}
|
|
8
|
-
key(a){const kind=a?.kind;
|
|
9
|
-
if(kind==='repository')return{id:'new-repository',label:'新建仓库'};
|
|
10
|
-
if(kind==='release'){if(typeof a.owner!=='string'||!a.owner.trim()||typeof a.repo!=='string'||!a.repo.trim())throw Error('缺少仓库信息。');return{id:`${clean(a.owner)}/${clean(a.repo)}`,label:`${a.owner}/${a.repo}`};}
|
|
11
|
-
throw Error('草稿类型无效。');}
|
|
12
|
-
file(k){return path.join(this.dir,...k.id.split('/'));}
|
|
13
|
-
normalize(a){return a.kind==='release'?{kind:'release',owner:String(a.owner??'').slice(0,100),repo:String(a.repo??'').slice(0,100),title:text(a.title,'版本标题',200),body:text(a.body,'更新说明',50000)}:{kind:'repository',description:text(a.description,'介绍',350)};}
|
|
14
|
-
markdown(k,d){return d.kind==='release'?`# ${k.label} 发布文案草稿\n\n更新时间:${d.updatedAt}\n\n## 版本标题\n\n${d.title||'(未填写)'}\n\n## 更新说明\n\n${d.body||'(未填写)'}\n`:`# 新建仓库草稿\n\n更新时间:${d.updatedAt}\n\n## 介绍\n\n${d.description||'(未填写)'}\n`;}
|
|
15
|
-
async save(a){const key=this.key(a),data={...this.normalize(a),updatedAt:new Date(this.now()).toISOString()};await mkdir(this.dir,{recursive:true});const base=this.file(key);await mkdir(path.dirname(base),{recursive:true});
|
|
16
|
-
await writeFile(base+'.json.tmp',JSON.stringify(data,null,2),{mode:0o600});await rename(base+'.json.tmp',base+'.json');await writeFile(base+'.md',this.markdown(key,data),{mode:0o600});
|
|
17
|
-
return{savedAt:data.updatedAt,label:key.label};}
|
|
18
|
-
async load(a){try{const data=JSON.parse(await readFile(this.file(this.key(a))+'.json','utf8'));return typeof data==='object'&&data?data:null;}catch{return null;}}
|
|
19
|
-
async clear(a){const base=this.file(this.key(a));await Promise.all([unlink(base+'.json').catch(()=>{}),unlink(base+'.md').catch(()=>{})]);return{ok:true};}
|
|
20
|
-
}
|