import { execSync } from "child_process" ; import { sync as rmdirSync } from "rimraf" ; import { version as rawVersion } from "../package.json" ; const cd = ( path ) => { console . log ( "$ cd" , path ) ; process . chdir ( path ) ; } ; const rm = ( path ) => { console . log ( "$ rm -rf" , path ) ; rmdirSync ( path ) ; } ; const sh = ( command ) => { console . log ( "$" , command ) ; execSync ( command , { encoding : "utf8" , stdio : "inherit" } ) ; } ; const stdoutOf = ( command ) => { console . log ( "$" , command , "> self" ) ; return execSync ( command , { encoding : "utf8" , stdio : [ "inherit" , "pipe" , "inherit" ] , } ) . trim ( ) ; } ; const originUrl = stdoutOf ( "git remote get-url origin" ) ; const branch = stdoutOf ( "git symbolic-ref --short HEAD" ) ; const version = branch === "master" ? rawVersion : `${ rawVersion }-${ branch }` ; const sha1 = stdoutOf ( 'git log -1 --format="%h"' ) ; const commitMessage = `🔖 ${ version } (built with ${ sha1 })` ; sh ( "git push origin master" ) ; try { sh ( `git tag -d "v${ rawVersion }"` ) ; } catch ( ignore ) { } cd ( "dist" ) ; sh ( "git init" ) ; try { sh ( "git add ." ) ; sh ( `git commit -m "${ commitMessage }"` ) ; sh ( `git tag "v${ version }"` ) ; sh ( `git push "${ originUrl }" "v${ version }"` ) ; sh ( "npm publish" ) ; } finally { rm ( ".git" ) ; cd ( ".." ) ; sh ( "git fetch --tags" ) ; }