git-publish 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +26 -52
package/dist/index.js CHANGED
@@ -106,4 +106,4 @@ See: https://github.com/isaacs/node-glob/issues/167`);if(!(this instanceof E))re
106
106
  `)+`
107
107
  `,i);else{const s=this.mustHaveFilesFromPackage(u).map(l=>`!${l}`).join(`
108
108
  `)+`
109
- `;super.onReadIgnoreFile($d,s,i)}}stat({entry:t,file:u,dir:i},o){hb(t)?o():super.stat({entry:t,file:u,dir:i},o)}onstat({st:t,entry:u,file:i,dir:o,isSymbolicLink:s},l){t.isSymbolicLink()?l():super.onstat({st:t,entry:u,file:i,dir:o,isSymbolicLink:s},l)}onReadIgnoreFile(t,u,i){if(t==="package.json")try{const o=Le.resolve(this.path,t);this.onPackageJson(o,JSON.parse(u),i)}catch{i()}else super.onReadIgnoreFile(t,u,i)}sort(t,u){const i=Le.extname(t).toLowerCase(),o=Le.extname(u).toLowerCase(),s=Le.basename(t).toLowerCase(),l=Le.basename(u).toLowerCase();return i.localeCompare(o,"en")||s.localeCompare(l,"en")||t.localeCompare(u,"en")}globFiles(t,u){cb(Gr(t),{dot:!0,cwd:this.path,nocase:!0},u)}readPackageJson(t){jd.readFile(this.path+"/package.json",(u,i)=>this.onReadPackageJson(t,u,i))}walker(t,u,i){new xi(this.walkerOpt(t,u)).on("done",i).start()}}const zd=(e,t)=>{e=e||{};const u=new Promise((i,o)=>{const s=new ub(e);s.on("done",l=>{e.bundled=l,e.packageJsonCache=s.packageJsonCache,new xi(e).on("done",i).on("error",o).start()}),s.start()});return t?u.then(i=>t(null,i),t):u};var pb=zd;zd.Walker=xi;var gb="git-publish",mb="1.0.0",Eb="Publish your npm package to a GitHub repository branch";async function Cb(){const{stdout:e}=await Qe("git",["status","--porcelain","--untracked-files=no"]).catch(t=>{throw t.stderr.includes("not a git repository")?new Error("Not in a git repository"):t});if(e)throw new Error("Working tree is not clean")}async function bb(){const e=()=>{},t=await Qe("git",["symbolic-ref","--short","-q","HEAD"]).then(({stdout:i})=>i,e);if(t)return t;const u=await Qe("git",["describe","--tags"]).then(({stdout:i})=>i,e);if(u)return u;throw new Error("Failed to get current branch name")}async function yb(e){const t=await rt.default.promises.readFile(e,"utf8");try{return JSON.parse(t)}catch{throw new Error(`Failed to parse JSON file: ${e}`)}}const{stringify:rn}=JSON;(async()=>{const e=tC({name:gb,version:mb,flags:{branch:{type:String,alias:"b",placeholder:"<branch name>",description:'The branch to publish the package to. Defaults to prefixing "npm/" to the current branch or tag name.'},remote:{type:String,alias:"r",placeholder:"<remote>",description:"The remote to push to.",default:"origin"},dry:{type:Boolean,alias:"d",description:"Dry run mode. Will not commit or push to the remote."}},help:{description:Eb}});await Cb();const t=await bb(),u="package.json";await rt.default.promises.access(u).catch(()=>{throw new Error("No package.json found in current working directory")});const{branch:i=`npm/${t}`,remote:o,dry:s}=e.flags;await T2(`Publishing branch ${rn(t)} \u2192 ${rn(i)}`,async({task:l,setTitle:c,setStatus:d,setOutput:h})=>{s&&d("Dry run");const m=`git-publish/${i}-${Date.now()}`;let E=!1;try{let g=[];const C=await l("Running hooks",async({setWarning:z,setTitle:w})=>{if(s){z("");return}w('Running hook "prepare"'),await Qe("npm",["run","--if-present","prepare"]),w('Running hook "prepack"'),await Qe("npm",["run","--if-present","prepack"])});s||C.clear();const y=await l("Getting publish files",async({setWarning:z})=>{if(s){z("");return}if(g=await pb(),g.length===0)throw new Error("No publish files found")});s||y.clear();const v=await l('Removing "prepare" & "prepack" hooks',async({setWarning:z})=>{if(s){z("");return}const w=await yb(u);if(!("scripts"in w))return;const{scripts:B}=w;let x=!1;"prepare"in B&&(delete B.prepare,x=!0),"prepack"in B&&(delete B.prepack,x=!0),x&&await rt.default.promises.writeFile(u,rn(w,null,2))});s||v.clear();const k=await l(`Checking out branch ${rn(i)}`,async({setWarning:z})=>{if(s){z("");return}await Qe("git",["checkout","--orphan",m]),await Qe("git",["reset"])});s||k.clear();const R=await l("Commiting publish assets",async({setWarning:z})=>{if(s){z("");return}await Qe("git",["add","-f",...g]),await Qe("git",["commit","-nm",`Published branch ${rn(t)}`])});s||R.clear();const N=await l(`Force pushing branch ${rn(i)} to remote ${rn(o)}`,async({setWarning:z})=>{if(s){z("");return}await Qe("git",["push","-f",o,`${m}:${i}`]),E=!0});s||N.clear()}finally{(await l(`Switching branch back to ${rn(t)}`,async({setWarning:C})=>{if(s){C("");return}await Qe("git",["reset","--hard"]),await Qe("git",["checkout","-f",t]),await Qe("git",["branch","-D",m])})).clear()}if(E){let g=o;try{const{stdout:y}=await Qe("git",["remote","get-url",g]);g=y.trim()}catch{}const C=g.match(/github\.com:(.+)\.git$/);if(C){const[,y]=C;c("Successfully published branch! Install with command:"),h(`npm i '${y}#${i}'`)}}})})().catch(e=>{console.error("Error:",e.message),process.exit(1)});
109
+ `;super.onReadIgnoreFile($d,s,i)}}stat({entry:t,file:u,dir:i},o){hb(t)?o():super.stat({entry:t,file:u,dir:i},o)}onstat({st:t,entry:u,file:i,dir:o,isSymbolicLink:s},l){t.isSymbolicLink()?l():super.onstat({st:t,entry:u,file:i,dir:o,isSymbolicLink:s},l)}onReadIgnoreFile(t,u,i){if(t==="package.json")try{const o=Le.resolve(this.path,t);this.onPackageJson(o,JSON.parse(u),i)}catch{i()}else super.onReadIgnoreFile(t,u,i)}sort(t,u){const i=Le.extname(t).toLowerCase(),o=Le.extname(u).toLowerCase(),s=Le.basename(t).toLowerCase(),l=Le.basename(u).toLowerCase();return i.localeCompare(o,"en")||s.localeCompare(l,"en")||t.localeCompare(u,"en")}globFiles(t,u){cb(Gr(t),{dot:!0,cwd:this.path,nocase:!0},u)}readPackageJson(t){jd.readFile(this.path+"/package.json",(u,i)=>this.onReadPackageJson(t,u,i))}walker(t,u,i){new xi(this.walkerOpt(t,u)).on("done",i).start()}}const zd=(e,t)=>{e=e||{};const u=new Promise((i,o)=>{const s=new ub(e);s.on("done",l=>{e.bundled=l,e.packageJsonCache=s.packageJsonCache,new xi(e).on("done",i).on("error",o).start()}),s.start()});return t?u.then(i=>t(null,i),t):u};var pb=zd;zd.Walker=xi;var gb="git-publish",mb="1.0.1",Eb="Publish your npm package to a GitHub repository branch";async function Cb(){const{stdout:e}=await Qe("git",["status","--porcelain","--untracked-files=no"]).catch(t=>{throw t.stderr.includes("not a git repository")?new Error("Not in a git repository"):t});if(e)throw new Error("Working tree is not clean")}async function bb(){const e=()=>{},t=await Qe("git",["symbolic-ref","--short","-q","HEAD"]).then(({stdout:i})=>i,e);if(t)return t;const u=await Qe("git",["describe","--tags"]).then(({stdout:i})=>i,e);if(u)return u;throw new Error("Failed to get current branch name")}async function yb(e){const t=await rt.default.promises.readFile(e,"utf8");try{return JSON.parse(t)}catch{throw new Error(`Failed to parse JSON file: ${e}`)}}const{stringify:rn}=JSON;(async()=>{const e=tC({name:gb,version:mb,flags:{branch:{type:String,alias:"b",placeholder:"<branch name>",description:'The branch to publish the package to. Defaults to prefixing "npm/" to the current branch or tag name.'},remote:{type:String,alias:"r",placeholder:"<remote>",description:"The remote to push to.",default:"origin"},dry:{type:Boolean,alias:"d",description:"Dry run mode. Will not commit or push to the remote."}},help:{description:Eb}});await Cb();const t=await bb(),u="package.json";await rt.default.promises.access(u).catch(()=>{throw new Error("No package.json found in current working directory")});const{branch:i=`npm/${t}`,remote:o,dry:s}=e.flags;await T2(`Publishing branch ${rn(t)} \u2192 ${rn(i)}`,async({task:l,setTitle:c,setStatus:d,setOutput:h})=>{s&&d("Dry run");const m=`git-publish/${i}-${Date.now()}`;let E=!1;try{let g=[];const C=await l("Running hooks",async({setWarning:z,setTitle:w})=>{if(s){z("");return}w('Running hook "prepare"'),await Qe("npm",["run","--if-present","prepare"]),w('Running hook "prepack"'),await Qe("npm",["run","--if-present","prepack"])});s||C.clear();const y=await l("Getting publish files",async({setWarning:z})=>{if(s){z("");return}if(g=await pb(),g.length===0)throw new Error("No publish files found")});s||y.clear();const v=await l('Removing "prepare" & "prepack" hooks',async({setWarning:z})=>{if(s){z("");return}const w=await yb(u);if(!("scripts"in w))return;const{scripts:B}=w;let x=!1;"prepare"in B&&(delete B.prepare,x=!0),"prepack"in B&&(delete B.prepack,x=!0),x&&await rt.default.promises.writeFile(u,rn(w,null,2))});s||v.clear();const k=await l(`Checking out branch ${rn(i)}`,async({setWarning:z})=>{if(s){z("");return}await Qe("git",["checkout","--orphan",m]),await Qe("git",["reset"])});s||k.clear();const R=await l("Commiting publish assets",async({setWarning:z})=>{if(s){z("");return}await Qe("git",["add","-f",...g]),await Qe("git",["commit","-nm",`Published branch ${rn(t)}`])});s||R.clear();const N=await l(`Force pushing branch ${rn(i)} to remote ${rn(o)}`,async({setWarning:z})=>{if(s){z("");return}await Qe("git",["push","-f",o,`${m}:${i}`]),E=!0});s||N.clear()}finally{(await l(`Switching branch back to ${rn(t)}`,async({setWarning:C})=>{if(s){C("");return}await Qe("git",["reset","--hard"]),await Qe("git",["checkout","-f",t]),await Qe("git",["branch","-D",m])})).clear()}if(E){let g=o;try{const{stdout:y}=await Qe("git",["remote","get-url",g]);g=y.trim()}catch{}const C=g.match(/github\.com:(.+)\.git$/);if(C){const[,y]=C;c("Successfully published branch! Install with command:"),h(`npm i '${y}#${i}'`)}}})})().catch(e=>{console.error("Error:",e.message),process.exit(1)});
package/package.json CHANGED
@@ -1,53 +1,27 @@
1
1
  {
2
- "name": "git-publish",
3
- "version": "1.0.0",
4
- "description": "Publish your npm package to a GitHub repository branch",
5
- "keywords": [
6
- "npm",
7
- "publish",
8
- "git",
9
- "github",
10
- "branch",
11
- "branches"
12
- ],
13
- "license": "MIT",
14
- "repository": "privatenumber/git-publish",
15
- "funding": "https://github.com/privatenumber/git-publish?sponsor=1",
16
- "author": {
17
- "name": "Hiroki Osame",
18
- "email": "hiroki.osame@gmail.com"
19
- },
20
- "files": [
21
- "bin",
22
- "dist"
23
- ],
24
- "bin": "dist/index.js",
25
- "scripts": {
26
- "build": "pkgroll --minify --target=node12.19",
27
- "lint": "eslint .",
28
- "prepack": "npm run build",
29
- "pretest": "npm run build",
30
- "test": "tsx tests"
31
- },
32
- "dependencies": {
33
- "yoga-layout-prebuilt": "^1.10.0"
34
- },
35
- "devDependencies": {
36
- "@pvtnbr/eslint-config": "^0.27.0",
37
- "@types/node": "^18.6.4",
38
- "@types/npm-packlist": "^3.0.0",
39
- "cleye": "^1.2.1",
40
- "eslint": "^8.21.0",
41
- "execa": "^6.1.0",
42
- "fs-fixture": "^1.1.0",
43
- "manten": "^0.2.1",
44
- "npm-packlist": "^5.1.1",
45
- "pkgroll": "^1.4.0",
46
- "tasuku": "^2.0.0",
47
- "tsx": "^3.8.0",
48
- "typescript": "^4.7.4"
49
- },
50
- "eslintConfig": {
51
- "extends": "@pvtnbr"
52
- }
53
- }
2
+ "name": "git-publish",
3
+ "version": "1.0.1",
4
+ "description": "Publish your npm package to a GitHub repository branch",
5
+ "keywords": [
6
+ "npm",
7
+ "publish",
8
+ "git",
9
+ "github",
10
+ "branch",
11
+ "branches"
12
+ ],
13
+ "license": "MIT",
14
+ "repository": "privatenumber/git-publish",
15
+ "funding": "https://github.com/privatenumber/git-publish?sponsor=1",
16
+ "author": {
17
+ "name": "Hiroki Osame",
18
+ "email": "hiroki.osame@gmail.com"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "bin": "dist/index.js",
24
+ "dependencies": {
25
+ "yoga-layout-prebuilt": "^1.10.0"
26
+ }
27
+ }