@shipstatic/ship 0.1.6 → 0.1.8
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/README.md +4 -4
- package/dist/browser.js +17 -25
- package/dist/browser.js.map +1 -1
- package/dist/cli.cjs +25 -18
- package/dist/cli.cjs.map +1 -1
- package/dist/completions/ship.bash +30 -0
- package/dist/completions/ship.fish +24 -0
- package/dist/completions/ship.zsh +46 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -21
- package/dist/index.d.ts +26 -21
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +13 -10
package/dist/cli.cjs
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var Fe=Object.create;var Y=Object.defineProperty;var De=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var Se=Object.getPrototypeOf,xe=Object.prototype.hasOwnProperty;var j=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pe(t))!xe.call(e,o)&&o!==i&&Y(e,o,{get:()=>t[o],enumerable:!(n=De(t,o))||n.enumerable});return e},X=(e,t,i)=>(j(e,t,"default"),i&&j(i,t,"default")),g=(e,t,i)=>(i=e!=null?Fe(Se(e)):{},j(t||!e||!e.__esModule?Y(i,"default",{value:e,enumerable:!0}):i,e));var ge=require("commander");var Z=null;function Ae(){return typeof process<"u"&&process.versions&&process.versions.node?"node":typeof window<"u"||typeof self<"u"?"browser":"unknown"}function u(){return Z||Ae()}var E=require("zod");var x={};X(x,require("@shipstatic/types"));var $="https://api.shipstatic.com";var Q="ship",Ce=E.z.object({apiUrl:E.z.string().url().optional(),apiKey:E.z.string().optional()}).strict();function ee(e){try{return Ce.parse(e)}catch(t){if(t instanceof E.z.ZodError){let i=t.issues[0],n=i.path.length>0?` at ${i.path.join(".")}`:"";throw x.ShipError.config(`Configuration validation failed${n}: ${i.message}`)}throw x.ShipError.config("Configuration validation failed")}}async function Ee(){try{if(u()!=="node")return{};let{cosmiconfigSync:e}=await import("cosmiconfig"),i=e(Q,{searchPlaces:[`.${Q}rc`,"package.json"]}).search();if(i&&!i.isEmpty&&i.config)return ee(i.config)}catch(e){if(e instanceof x.ShipError)throw e}return{}}async function te(){if(u()!=="node")return{};let e={apiUrl:process.env.SHIP_API_URL,apiKey:process.env.SHIP_API_KEY},t=await Ee(),i={apiUrl:e.apiUrl??t.apiUrl,apiKey:e.apiKey??t.apiKey};return ee(i)}function H(e={},t={}){let i={apiUrl:e.apiUrl||t.apiUrl||$,apiKey:e.apiKey!==void 0?e.apiKey:t.apiKey};return i.apiKey!==void 0?{apiUrl:i.apiUrl,apiKey:i.apiKey}:{apiUrl:i.apiUrl}}function ie(e={},t){let i={...e};return i.onProgress===void 0&&t.onProgress!==void 0&&(i.onProgress=t.onProgress),i.onProgressStats===void 0&&t.onProgressStats!==void 0&&(i.onProgressStats=t.onProgressStats),i.maxConcurrency===void 0&&t.maxConcurrentDeploys!==void 0&&(i.maxConcurrency=t.maxConcurrentDeploys),i.timeout===void 0&&t.timeout!==void 0&&(i.timeout=t.timeout),i.apiKey===void 0&&t.apiKey!==void 0&&(i.apiKey=t.apiKey),i.apiUrl===void 0&&t.apiUrl!==void 0&&(i.apiUrl=t.apiUrl),i}var L=g(require("mime-types"),1),y=require("@shipstatic/types");var T="/deployments",Re="/ping",k="/aliases",Ie="/config",Oe="/account";function $e(e){return typeof e=="string"?L.lookup(e)||"application/octet-stream":L.lookup(e.name)||e.type||"application/octet-stream"}async function Te(e){let t=[];for await(let i of e)t.push(i);return t}var R=class{constructor(t){this.apiUrl=t.apiUrl||$,this.apiKey=t.apiKey??""}#o(t={}){let i={...t};return this.apiKey&&(i.Authorization=`Bearer ${this.apiKey}`),i}async#i(t,i={},n){let o=this.#o(i.headers),s={...i,headers:o,credentials:u()==="browser"?"include":"same-origin"};try{return await fetch(t,s)}catch(a){throw this.#t(a,n),a}}async#e(t,i={},n){try{let o=await this.#i(t,i,n);return o.ok||await this.#n(o,n),o.headers.get("Content-Length")==="0"||o.status===204?void 0:await o.json()}catch(o){throw o instanceof y.ShipError||this.#t(o,n),o}}async ping(){return(await this.#e(`${this.apiUrl}${Re}`,{method:"GET"},"Ping"))?.success||!1}async getConfig(){return await this.#e(`${this.apiUrl}${Ie}`,{method:"GET"},"Config")}async deploy(t,i={}){this.#s(t);let{apiUrl:n=this.apiUrl,signal:o}=i;try{let{requestBody:s,requestHeaders:a}=await this.#r(t),p={method:"POST",body:s,headers:a,signal:o||null},m=await this.#i(`${n}${T}`,p,"Deploy");return m.ok||await this.#n(m,"Deploy"),await m.json()}catch(s){throw s instanceof y.ShipError?s:(this.#t(s,"Deploy"),y.ShipError.business("An unexpected error occurred and was not handled."))}}#s(t){if(!t.length)throw y.ShipError.business("No files to deploy.");for(let i of t)if(!i.md5)throw y.ShipError.file(`MD5 checksum missing for file: ${i.path}`,i.path)}async#r(t){let i,n={};if(u()==="browser")i=this.#a(t);else if(u()==="node"){let{body:o,headers:s}=await this.#c(t);i=o,n=s}else throw y.ShipError.business("Unknown or unsupported execution environment");return{requestBody:i,requestHeaders:n}}#a(t){let i=new FormData,n=[];for(let o=0;o<t.length;o++){let s=t[o],a;if(s.content instanceof File||s.content instanceof Blob)a=s.content;else throw y.ShipError.file(`Unsupported file.content type for browser FormData: ${s.path}`,s.path);let p=$e(a instanceof File?a:s.path),m=new File([a],s.path,{type:p});i.append("files[]",m),n.push(s.md5)}return i.append("checksums",JSON.stringify(n)),i}async#c(t){let{FormData:i,File:n}=await import("formdata-node"),{FormDataEncoder:o}=await import("form-data-encoder"),s=await import("path"),a=new i,p=[];for(let b=0;b<t.length;b++){let f=t[b],O=L.lookup(f.path)||"application/octet-stream",F;if(Buffer.isBuffer(f.content))F=new n([f.content],s.basename(f.path),{type:O});else if(typeof Blob<"u"&&f.content instanceof Blob)F=new n([f.content],s.basename(f.path),{type:O});else throw y.ShipError.file(`Unsupported file.content type for Node.js FormData: ${f.path}`,f.path);let be=f.path.startsWith("/")?f.path:"/"+f.path;a.append("files[]",F,be),p.push(f.md5)}a.append("checksums",JSON.stringify(p));let m=new o(a),c=await Te(m.encode()),r=Buffer.concat(c.map(b=>Buffer.from(b))),l={"Content-Type":m.contentType,"Content-Length":Buffer.byteLength(r).toString()};return{body:r,headers:l}}async#n(t,i){let n={};try{let o=t.headers.get("content-type");o&&o.includes("application/json")?n=await t.json():n={message:await t.text()}}catch{n={message:"Failed to parse error response"}}if(n.error||n.code||n.message){let o=n.message||n.error||`${i} failed due to API error`;throw y.ShipError.api(o,t.status,n.code,n)}throw y.ShipError.api(`${i} failed due to API error`,t.status,void 0,n)}#t(t,i){throw t.name==="AbortError"?y.ShipError.cancelled(`${i} operation was cancelled.`):t instanceof TypeError&&t.message.includes("fetch")?y.ShipError.network(`${i} failed due to network error: ${t.message}`,t):t instanceof y.ShipError?t:y.ShipError.business(`An unexpected error occurred during ${i}: ${t.message||"Unknown error"}`)}async listDeployments(){return await this.#e(`${this.apiUrl}${T}`,{method:"GET"},"List Deployments")}async getDeployment(t){return await this.#e(`${this.apiUrl}${T}/${t}`,{method:"GET"},"Get Deployment")}async removeDeployment(t){await this.#e(`${this.apiUrl}${T}/${t}`,{method:"DELETE"},"Remove Deployment")}async setAlias(t,i){return await this.#e(`${this.apiUrl}${k}/${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({deploymentId:i})},"Set Alias")}async getAlias(t){return await this.#e(`${this.apiUrl}${k}/${encodeURIComponent(t)}`,{method:"GET"},"Get Alias")}async listAliases(){return await this.#e(`${this.apiUrl}${k}`,{method:"GET"},"List Aliases")}async removeAlias(t){await this.#e(`${this.apiUrl}${k}/${encodeURIComponent(t)}`,{method:"DELETE"},"Remove Alias")}async getAccount(){return await this.#e(`${this.apiUrl}${Oe}`,{method:"GET"},"Get Account")}async createApiKey(){return await this.#e(`${this.apiUrl}/key`,{method:"POST"},"Create API Key")}};var de=require("@shipstatic/types");var ne=require("@shipstatic/types"),G=null;function oe(e){G=e}function I(){if(G===null)throw ne.ShipError.config("Platform configuration not initialized. The SDK must fetch configuration from the API before performing operations.");return G}var h=require("@shipstatic/types");var A=require("@shipstatic/types");async function ke(e){let t=(await import("spark-md5")).default;return new Promise((i,n)=>{let s=Math.ceil(e.size/2097152),a=0,p=new t.ArrayBuffer,m=new FileReader,c=()=>{let r=a*2097152,l=Math.min(r+2097152,e.size);m.readAsArrayBuffer(e.slice(r,l))};m.onload=r=>{let l=r.target?.result;if(!l){n(A.ShipError.business("Failed to read file chunk"));return}p.append(l),a++,a<s?c():i({md5:p.end()})},m.onerror=()=>{n(A.ShipError.business("Failed to calculate MD5: FileReader error"))},c()})}async function Le(e){let t=await import("crypto");if(Buffer.isBuffer(e)){let n=t.createHash("md5");return n.update(e),{md5:n.digest("hex")}}let i=await import("fs");return new Promise((n,o)=>{let s=t.createHash("md5"),a=i.createReadStream(e);a.on("error",p=>o(A.ShipError.business(`Failed to read file for MD5: ${p.message}`))),a.on("data",p=>s.update(p)),a.on("end",()=>n({md5:s.digest("hex")}))})}async function U(e){let t=u();if(t==="browser"){if(!(e instanceof Blob))throw A.ShipError.business("Invalid input for browser MD5 calculation: Expected Blob or File.");return ke(e)}if(t==="node"){if(!(Buffer.isBuffer(e)||typeof e=="string"))throw A.ShipError.business("Invalid input for Node.js MD5 calculation: Expected Buffer or file path string.");return Le(e)}throw A.ShipError.business("Unknown or unsupported execution environment for MD5 calculation.")}var se=require("junk"),Ue=["__MACOSX",".Trashes",".fseventsd",".Spotlight-V100"];function N(e){return!e||e.length===0?[]:e.filter(t=>{if(!t)return!1;let i=t.replace(/\\/g,"/").split("/").filter(Boolean);if(i.length===0)return!0;let n=i[i.length-1];if((0,se.isJunk)(n))return!1;let o=i.slice(0,-1);for(let s of o)if(Ue.some(a=>s.toLowerCase()===a.toLowerCase()))return!1;return!0})}var C=require("@shipstatic/types");function z(e){if(!e||e.length===0)return"";let t=e.filter(s=>s&&typeof s=="string").map(s=>s.replace(/\\/g,"/"));if(t.length===0)return"";if(t.length===1)return t[0];let i=t.map(s=>s.split("/").filter(Boolean)),n=[],o=Math.min(...i.map(s=>s.length));for(let s=0;s<o;s++){let a=i[0][s];if(i.every(p=>p[s]===a))n.push(a);else break}return n.join("/")}function J(e){return e.replace(/\\/g,"/").replace(/^\/+/,"")}var S=g(require("fs"),1),d=g(require("path"),1);function ae(e){let t=[];try{let i=S.readdirSync(e);for(let n of i){let o=d.join(e,n),s=S.statSync(o);if(s.isDirectory()){let a=ae(o);t.push(...a)}else s.isFile()&&t.push(o)}}catch(i){console.error(`Error reading directory ${e}:`,i)}return t}async function re(e,t={}){let i=d.resolve(e),o=(()=>{let r=S.statSync(i);return r.isFile()?[i]:r.isDirectory()?ae(i):[]})().filter(r=>{let l=d.basename(r);return N([l]).length>0}),s=S.statSync(i),a;if(t.preserveDirs)a=s.isDirectory()?i:d.dirname(i);else{let r=o.map(l=>d.dirname(l));a=z(r)}let p=[],m=0;for(let r of o)try{let l=S.statSync(r);if(l.size===0){console.warn(`Skipping empty file: ${r}`);continue}let b=I();if(l.size>b.maxFileSize)throw C.ShipError.business(`File ${r} is too large. Maximum allowed size is ${b.maxFileSize/(1024*1024)}MB.`);if(m+=l.size,m>b.maxTotalSize)throw C.ShipError.business(`Total deploy size is too large. Maximum allowed is ${b.maxTotalSize/(1024*1024)}MB.`);let f=S.readFileSync(r),{md5:O}=await U(f),F=d.relative(a,r).replace(/\\/g,"/");(F.includes("..")||F.includes("\0"))&&(F=d.basename(r)),F||(F=d.basename(r)),p.push({path:F,content:f,size:f.length,md5:O})}catch(l){if(l instanceof C.ShipError&&l.isClientError&&l.isClientError())throw l;console.error(`Could not process file ${r}:`,l)}let c=I();if(p.length>c.maxFilesCount)throw C.ShipError.business(`Too many files to deploy. Maximum allowed is ${c.maxFilesCount} files.`);return p}async function q(e,t={}){if(u()!=="node")throw C.ShipError.business("processFilesForNode can only be called in a Node.js environment.");if(e.length>1){let i=[];for(let n of e){let o=await re(n,t);i.push(...o)}return i}return await re(e[0],t)}var W=require("@shipstatic/types");async function V(e,t={}){if(u()!=="browser")throw W.ShipError.business("processFilesForBrowser can only be called in a browser environment.");let i=Array.isArray(e)?e:Array.from(e),n="";if(!t.preserveDirs){let c=i.map(r=>r.webkitRelativePath||r.name).filter(r=>r).map(r=>r.includes("/")?r.substring(0,r.lastIndexOf("/")):"");n=z(c)}let o=[];for(let c of i){let r=c.webkitRelativePath||c.name;if(n&&!t.preserveDirs){r=J(r);let l=n.endsWith("/")?n:`${n}/`;r.startsWith(l)?r=r.substring(l.length):r===n&&(r="")}if(r=J(r),r.includes("..")||r.includes("\0"))throw W.ShipError.business(`Security error: Unsafe file path "${r}" for file: ${c.name}`);r||(r=c.name),o.push({file:c,relativePath:r})}let s=o.map(c=>c.relativePath),a=N(s),p=new Set(a),m=[];for(let c of o){if(!p.has(c.relativePath)||c.file.size===0)continue;let{md5:r}=await U(c.file);m.push({content:c.file,path:c.relativePath,size:c.file.size,md5:r})}return m}function ce(e,t={}){let i=I();if(!t.skipEmptyCheck&&e.length===0)throw h.ShipError.business("No files to deploy.");if(e.length>i.maxFilesCount)throw h.ShipError.business(`Too many files to deploy. Maximum allowed is ${i.maxFilesCount}.`);let n=0;for(let o of e){if(o.size>i.maxFileSize)throw h.ShipError.business(`File ${o.name} is too large. Maximum allowed size is ${i.maxFileSize/(1024*1024)}MB.`);n+=o.size}if(n>i.maxTotalSize)throw h.ShipError.business(`Total deploy size is too large. Maximum allowed is ${i.maxTotalSize/(1024*1024)}MB.`)}function le(e){return ce(e,{skipEmptyCheck:!0}),e.forEach(t=>{t.path&&(t.path=t.path.replace(/\\/g,"/"))}),e}async function Ne(e,t={}){if(!Array.isArray(e)||!e.every(n=>typeof n=="string"))throw h.ShipError.business("Invalid input type for Node.js environment. Expected string[] file paths.");if(e.length===0)throw h.ShipError.business("No files to deploy.");let i=await q(e,t);return le(i)}async function ze(e,t={}){let i;if(e instanceof HTMLInputElement){if(!e.files)throw h.ShipError.business("No files selected in HTMLInputElement");i=Array.from(e.files)}else if(typeof e=="object"&&e!==null&&typeof e.length=="number"&&typeof e.item=="function")i=Array.from(e);else if(Array.isArray(e)){if(e.length>0&&typeof e[0]=="string")throw h.ShipError.business("Invalid input type for browser environment. Expected File[], FileList, or HTMLInputElement.");i=e}else throw h.ShipError.business("Invalid input type for browser environment. Expected File[], FileList, or HTMLInputElement.");i=i.filter(o=>o.size===0?(console.warn(`Skipping empty file: ${o.name}`),!1):!0),ce(i);let n=await V(i,t);return le(n)}async function pe(e,t={}){let i=u();if(i==="node"){if(!Array.isArray(e)||!e.every(n=>typeof n=="string"))throw h.ShipError.business("Invalid input type for Node.js environment. Expected string[] file paths.");return Ne(e,t)}else if(i==="browser"){if(!(e instanceof HTMLInputElement||Array.isArray(e)||typeof FileList<"u"&&e instanceof FileList))throw h.ShipError.business("In browser, input must be FileList, File[], or HTMLInputElement.");return ze(e,t)}else throw h.ShipError.business("Unsupported execution environment.")}function me(e,t,i){return{create:async(n,o={})=>{t&&await t();let s=i?ie(o,i):o,a=await pe(n,s);return await e.deploy(a,s)},list:async()=>e.listDeployments(),remove:async n=>{await e.removeDeployment(n)},get:async n=>e.getDeployment(n)}}function fe(e){return{set:async(t,i)=>e.setAlias(t,i),get:async t=>e.getAlias(t),list:async()=>e.listAliases(),remove:async t=>{await e.removeAlias(t)}}}function ue(e){return{get:async()=>e.getAccount()}}function ye(e){return{create:async()=>e.createApiKey()}}var he=require("@shipstatic/types"),B=class{constructor(t={}){this.configInitialized=!1;this.configLoaded=!1;if(this.clientOptions=t,this.environment=u(),this.environment!=="node"&&this.environment!=="browser")throw de.ShipError.business("Unsupported execution environment.");let i=H(t,{});this.http=new R({...t,...i})}async initializeConfig(){if(this.configInitialized)return;if(!this.configLoaded){let i=await te(),n=H(this.clientOptions,i);this.http=new R({...this.clientOptions,...n}),this.configLoaded=!0}let t=await this.http.getConfig();oe(t),this.configInitialized=!0}async ping(){return await this.initializeConfig(),this.http.ping()}get deployments(){return this._deployments||(this._deployments=me(this.http,()=>this.initializeConfig(),this.clientOptions)),this._deployments}get aliases(){return this._aliases||(this._aliases=fe(this.http)),this._aliases}get account(){return this._account||(this._account=ue(this.http)),this._account}get keys(){return this._keys||(this._keys=ye(this.http)),this._keys}async deploy(t,i){return this.deployments.create(t,i)}};var we=require("fs"),_=g(require("path"),1),ve={version:"0.0.0"},Be=[_.resolve(__dirname,"../package.json"),_.resolve(__dirname,"../../package.json"),_.resolve(__dirname,"../../../package.json")];for(let e of Be)try{ve=JSON.parse((0,we.readFileSync)(e,"utf-8"));break}catch{}var D=new ge.Command;function w(e){console.error("Error:",e.message||e),process.exit(1)}function v(){let e=D.opts();return new B({apiUrl:e.api,apiKey:e.apiKey})}var _e={deployments:e=>{e.deployments.forEach(t=>{console.log(`${t.deployment} (${t.status})`)})},aliases:e=>{e.aliases.forEach(t=>{console.log(`${t.alias} -> ${t.deployment}`)})},deployment:e=>{console.log(`${e.deployment} (${e.status})`)},alias:e=>{console.log(`${e.alias} -> ${e.deployment}`)},email:e=>{console.log(`${e.email} (${e.subscription})`)}};function P(e){if(D.opts().json){console.log(JSON.stringify(e,null,2));return}for(let[i,n]of Object.entries(_e))if(e[i]){n(e);return}console.log("Success")}D.name("ship").description("CLI for Shipstatic").version(ve.version).option("-u, --api <URL>","API URL").option("-k, --apiKey <KEY>","API key").option("--json","JSON output").addHelpText("after",`
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
"use strict";var _e=Object.create;var ce=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,Me=Object.prototype.hasOwnProperty;var Y=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ze(t))!Me.call(e,s)&&s!==o&&ce(e,s,{get:()=>t[s],enumerable:!(n=Ue(t,s))||n.enumerable});return e},pe=(e,t,o)=>(Y(e,t,"default"),o&&Y(o,t,"default")),g=(e,t,o)=>(o=e!=null?_e(Be(e)):{},Y(t||!e||!e.__esModule?ce(o,"default",{value:e,enumerable:!0}):o,e));var Oe=require("commander");var me=null;function Ke(){return typeof process<"u"&&process.versions&&process.versions.node?"node":typeof window<"u"||typeof self<"u"?"browser":"unknown"}function w(){return me||Ke()}var j=require("zod");var R={};pe(R,require("@shipstatic/types"));var z="https://api.shipstatic.com";var X="ship",He=j.z.object({apiUrl:j.z.string().url().optional(),apiKey:j.z.string().optional()}).strict();function fe(e){try{return He.parse(e)}catch(t){if(t instanceof j.z.ZodError){let o=t.issues[0],n=o.path.length>0?` at ${o.path.join(".")}`:"";throw R.ShipError.config(`Configuration validation failed${n}: ${o.message}`)}throw R.ShipError.config("Configuration validation failed")}}async function Je(e){try{if(w()!=="node")return{};let{cosmiconfigSync:t}=await import("cosmiconfig"),o=await import("os"),n=t(X,{searchPlaces:[`.${X}rc`,"package.json",`${o.homedir()}/.${X}rc`],stopDir:o.homedir()}),s;if(e?s=n.load(e):s=n.search(),s&&s.config)return fe(s.config)}catch(t){if(t instanceof R.ShipError)throw t}return{}}async function ue(e){if(w()!=="node")return{};let t={apiUrl:process.env.SHIP_API_URL,apiKey:process.env.SHIP_API_KEY},o=await Je(e),n={apiUrl:t.apiUrl??o.apiUrl,apiKey:t.apiKey??o.apiKey};return fe(n)}function Q(e={},t={}){let o={apiUrl:e.apiUrl||t.apiUrl||z,apiKey:e.apiKey||t.apiKey};return o.apiKey!==void 0?{apiUrl:o.apiUrl,apiKey:o.apiKey}:{apiUrl:o.apiUrl}}function de(e={},t){return{onProgress:t.onProgress,onProgressStats:t.onProgressStats,maxConcurrency:t.maxConcurrentDeploys,timeout:t.timeout,apiKey:t.apiKey,apiUrl:t.apiUrl,...e}}var K=g(require("mime-types"),1),b=require("@shipstatic/types");var B="/deployments",he="/ping",M="/aliases",Ge="/config",Ve="/account";function qe(e){return typeof e=="string"?K.lookup(e)||"application/octet-stream":K.lookup(e.name)||e.type||"application/octet-stream"}async function We(e){let t=[];for await(let o of e)t.push(o);return t}var L=class{constructor(t){this.apiUrl=t.apiUrl||z,this.apiKey=t.apiKey??""}#s(t={}){let o={...t};return this.apiKey&&(o.Authorization=`Bearer ${this.apiKey}`),o}async#o(t,o={},n){let s=this.#s(o.headers),i={...o,headers:s,credentials:w()==="browser"?"include":"same-origin"};try{return await fetch(t,i)}catch(a){throw this.#t(a,n),a}}async#e(t,o={},n){try{let s=await this.#o(t,o,n);return s.ok||await this.#n(s,n),s.headers.get("Content-Length")==="0"||s.status===204?void 0:await s.json()}catch(s){throw s instanceof b.ShipError||this.#t(s,n),s}}async ping(){return(await this.#e(`${this.apiUrl}${he}`,{method:"GET"},"Ping"))?.success||!1}async getPingResponse(){return await this.#e(`${this.apiUrl}${he}`,{method:"GET"},"Ping")}async getConfig(){return await this.#e(`${this.apiUrl}${Ge}`,{method:"GET"},"Config")}async deploy(t,o={}){this.#i(t);let{apiUrl:n=this.apiUrl,signal:s}=o,{requestBody:i,requestHeaders:a}=await this.#r(t),l={method:"POST",body:i,headers:a,signal:s||null};return await this.#e(`${n}${B}`,l,"Deploy")}#i(t){if(!t.length)throw b.ShipError.business("No files to deploy.");for(let o of t)if(!o.md5)throw b.ShipError.file(`MD5 checksum missing for file: ${o.path}`,o.path)}async#r(t){let o,n={};if(w()==="browser")o=this.#a(t);else if(w()==="node"){let{body:s,headers:i}=await this.#l(t);o=s,n=i}else throw b.ShipError.business("Unknown or unsupported execution environment");return{requestBody:o,requestHeaders:n}}#a(t){let o=new FormData,n=[];for(let s=0;s<t.length;s++){let i=t[s],a;if(i.content instanceof File||i.content instanceof Blob)a=i.content;else throw b.ShipError.file(`Unsupported file.content type for browser FormData: ${i.path}`,i.path);let l=qe(a instanceof File?a:i.path),p=new File([a],i.path,{type:l});o.append("files[]",p),n.push(i.md5)}return o.append("checksums",JSON.stringify(n)),o}async#l(t){let{FormData:o,File:n}=await import("formdata-node"),{FormDataEncoder:s}=await import("form-data-encoder"),i=await import("path"),a=new o,l=[];for(let F=0;F<t.length;F++){let y=t[F],U=K.lookup(y.path)||"application/octet-stream",x;if(Buffer.isBuffer(y.content))x=new n([y.content],i.basename(y.path),{type:U});else if(typeof Blob<"u"&&y.content instanceof Blob)x=new n([y.content],i.basename(y.path),{type:U});else throw b.ShipError.file(`Unsupported file.content type for Node.js FormData: ${y.path}`,y.path);let ke=y.path.startsWith("/")?y.path:"/"+y.path;a.append("files[]",x,ke),l.push(y.md5)}a.append("checksums",JSON.stringify(l));let p=new s(a),c=await We(p.encode()),r=Buffer.concat(c.map(F=>Buffer.from(F))),m={"Content-Type":p.contentType,"Content-Length":Buffer.byteLength(r).toString()};return{body:r,headers:m}}async#n(t,o){let n={};try{let s=t.headers.get("content-type");s&&s.includes("application/json")?n=await t.json():n={message:await t.text()}}catch{n={message:"Failed to parse error response"}}if(n.error||n.code||n.message){let s=n.message||n.error||`${o} failed due to API error`;throw t.status===401?b.ShipError.authentication(s):b.ShipError.api(s,t.status,n.code,n)}throw t.status===401?b.ShipError.authentication(`Authentication failed for ${o}`):b.ShipError.api(`${o} failed due to API error`,t.status,void 0,n)}#t(t,o){throw t.name==="AbortError"?b.ShipError.cancelled(`${o} operation was cancelled.`):t instanceof TypeError&&t.message.includes("fetch")?b.ShipError.network(`${o} failed due to network error: ${t.message}`,t):t instanceof b.ShipError?t:b.ShipError.business(`An unexpected error occurred during ${o}: ${t.message||"Unknown error"}`)}async listDeployments(){return await this.#e(`${this.apiUrl}${B}`,{method:"GET"},"List Deployments")}async getDeployment(t){return await this.#e(`${this.apiUrl}${B}/${t}`,{method:"GET"},"Get Deployment")}async removeDeployment(t){await this.#e(`${this.apiUrl}${B}/${t}`,{method:"DELETE"},"Remove Deployment")}async setAlias(t,o){try{let n=await this.#o(`${this.apiUrl}${M}/${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({deployment:o})},"Set Alias");return n.ok||await this.#n(n,"Set Alias"),{...await n.json(),isCreate:n.status===201}}catch(n){this.#t(n,"Set Alias")}}async getAlias(t){return await this.#e(`${this.apiUrl}${M}/${encodeURIComponent(t)}`,{method:"GET"},"Get Alias")}async listAliases(){return await this.#e(`${this.apiUrl}${M}`,{method:"GET"},"List Aliases")}async removeAlias(t){await this.#e(`${this.apiUrl}${M}/${encodeURIComponent(t)}`,{method:"DELETE"},"Remove Alias")}async getAccount(){return await this.#e(`${this.apiUrl}${Ve}`,{method:"GET"},"Get Account")}async createApiKey(){return await this.#e(`${this.apiUrl}/key`,{method:"POST"},"Create API Key")}};var Re=require("@shipstatic/types");var ye=require("@shipstatic/types"),ee=null;function ge(e){ee=e}function N(){if(ee===null)throw ye.ShipError.config("Platform configuration not initialized. The SDK must fetch configuration from the API before performing operations.");return ee}var v=require("@shipstatic/types");var $=require("@shipstatic/types");async function Ze(e){let t=(await import("spark-md5")).default;return new Promise((o,n)=>{let i=Math.ceil(e.size/2097152),a=0,l=new t.ArrayBuffer,p=new FileReader,c=()=>{let r=a*2097152,m=Math.min(r+2097152,e.size);p.readAsArrayBuffer(e.slice(r,m))};p.onload=r=>{let m=r.target?.result;if(!m){n($.ShipError.business("Failed to read file chunk"));return}l.append(m),a++,a<i?c():o({md5:l.end()})},p.onerror=()=>{n($.ShipError.business("Failed to calculate MD5: FileReader error"))},c()})}async function Ye(e){let t=await import("crypto");if(Buffer.isBuffer(e)){let n=t.createHash("md5");return n.update(e),{md5:n.digest("hex")}}let o=await import("fs");return new Promise((n,s)=>{let i=t.createHash("md5"),a=o.createReadStream(e);a.on("error",l=>s($.ShipError.business(`Failed to read file for MD5: ${l.message}`))),a.on("data",l=>i.update(l)),a.on("end",()=>n({md5:i.digest("hex")}))})}async function H(e){let t=w();if(t==="browser"){if(!(e instanceof Blob))throw $.ShipError.business("Invalid input for browser MD5 calculation: Expected Blob or File.");return Ze(e)}if(t==="node"){if(!(Buffer.isBuffer(e)||typeof e=="string"))throw $.ShipError.business("Invalid input for Node.js MD5 calculation: Expected Buffer or file path string.");return Ye(e)}throw $.ShipError.business("Unknown or unsupported execution environment for MD5 calculation.")}var we=require("junk"),Xe=["__MACOSX",".Trashes",".fseventsd",".Spotlight-V100"];function J(e){return!e||e.length===0?[]:e.filter(t=>{if(!t)return!1;let o=t.replace(/\\/g,"/").split("/").filter(Boolean);if(o.length===0)return!0;let n=o[o.length-1];if((0,we.isJunk)(n))return!1;let s=o.slice(0,-1);for(let i of s)if(Xe.some(a=>i.toLowerCase()===a.toLowerCase()))return!1;return!0})}var I=require("@shipstatic/types");function G(e){if(!e||e.length===0)return"";let t=e.filter(i=>i&&typeof i=="string").map(i=>i.replace(/\\/g,"/"));if(t.length===0)return"";if(t.length===1)return t[0];let o=t.map(i=>i.split("/").filter(Boolean)),n=[],s=Math.min(...o.map(i=>i.length));for(let i=0;i<s;i++){let a=o[0][i];if(o.every(l=>l[i]===a))n.push(a);else break}return n.join("/")}function te(e){return e.replace(/\\/g,"/").replace(/^\/+/,"")}var A=g(require("fs"),1),S=g(require("path"),1);function Se(e){let t=[];try{let o=A.readdirSync(e);for(let n of o){let s=S.join(e,n),i=A.statSync(s);if(i.isDirectory()){let a=Se(s);t.push(...a)}else i.isFile()&&t.push(s)}}catch(o){console.error(`Error reading directory ${e}:`,o)}return t}async function be(e,t={}){let o=S.resolve(e),s=(()=>{let r=A.statSync(o);return r.isFile()?[o]:r.isDirectory()?Se(o):[]})().filter(r=>{let m=S.basename(r);return J([m]).length>0}),i=A.statSync(o),a;if(t.preserveDirs)a=i.isDirectory()?o:S.dirname(o);else{let r=s.map(m=>S.dirname(m));a=G(r)}let l=[],p=0;for(let r of s)try{let m=A.statSync(r);if(m.size===0){console.warn(`Skipping empty file: ${r}`);continue}let F=N();if(m.size>F.maxFileSize)throw I.ShipError.business(`File ${r} is too large. Maximum allowed size is ${F.maxFileSize/(1024*1024)}MB.`);if(p+=m.size,p>F.maxTotalSize)throw I.ShipError.business(`Total deploy size is too large. Maximum allowed is ${F.maxTotalSize/(1024*1024)}MB.`);let y=A.readFileSync(r),{md5:U}=await H(y),x=S.relative(a,r).replace(/\\/g,"/");(x.includes("..")||x.includes("\0"))&&(x=S.basename(r)),x||(x=S.basename(r)),l.push({path:x,content:y,size:y.length,md5:U})}catch(m){if(m instanceof I.ShipError&&m.isClientError&&m.isClientError())throw m;console.error(`Could not process file ${r}:`,m)}let c=N();if(l.length>c.maxFilesCount)throw I.ShipError.business(`Too many files to deploy. Maximum allowed is ${c.maxFilesCount} files.`);return l}async function oe(e,t={}){if(w()!=="node")throw I.ShipError.business("processFilesForNode can only be called in a Node.js environment.");if(e.length>1){let o=[];for(let n of e){let s=await be(n,t);o.push(...s)}return o}return await be(e[0],t)}var ne=require("@shipstatic/types");async function se(e,t={}){if(w()!=="browser")throw ne.ShipError.business("processFilesForBrowser can only be called in a browser environment.");let o=Array.isArray(e)?e:Array.from(e),n="";if(!t.preserveDirs){let c=o.map(r=>r.webkitRelativePath||r.name).filter(r=>r).map(r=>r.includes("/")?r.substring(0,r.lastIndexOf("/")):"");n=G(c)}let s=[];for(let c of o){let r=c.webkitRelativePath||c.name;if(n&&!t.preserveDirs){r=te(r);let m=n.endsWith("/")?n:`${n}/`;r.startsWith(m)?r=r.substring(m.length):r===n&&(r="")}if(r=te(r),r.includes("..")||r.includes("\0"))throw ne.ShipError.business(`Security error: Unsafe file path "${r}" for file: ${c.name}`);r||(r=c.name),s.push({file:c,relativePath:r})}let i=s.map(c=>c.relativePath),a=J(i),l=new Set(a),p=[];for(let c of s){if(!l.has(c.relativePath)||c.file.size===0)continue;let{md5:r}=await H(c.file);p.push({content:c.file,path:c.relativePath,size:c.file.size,md5:r})}return p}function ve(e,t={}){let o=N();if(!t.skipEmptyCheck&&e.length===0)throw v.ShipError.business("No files to deploy.");if(e.length>o.maxFilesCount)throw v.ShipError.business(`Too many files to deploy. Maximum allowed is ${o.maxFilesCount}.`);let n=0;for(let s of e){if(s.size>o.maxFileSize)throw v.ShipError.business(`File ${s.name} is too large. Maximum allowed size is ${o.maxFileSize/(1024*1024)}MB.`);if(n+=s.size,n>o.maxTotalSize)throw v.ShipError.business(`Total deploy size is too large. Maximum allowed is ${o.maxTotalSize/(1024*1024)}MB.`)}}function Ce(e,t){if(t==="node"){if(!Array.isArray(e))throw v.ShipError.business("Invalid input type for Node.js environment. Expected string[] file paths.");if(e.length===0)throw v.ShipError.business("No files to deploy.");if(!e.every(o=>typeof o=="string"))throw v.ShipError.business("Invalid input type for Node.js environment. Expected string[] file paths.")}else if(t==="browser"&&e instanceof HTMLInputElement&&!e.files)throw v.ShipError.business("No files selected in HTMLInputElement")}function Pe(e){return ve(e,{skipEmptyCheck:!0}),e.forEach(t=>{t.path&&(t.path=t.path.replace(/\\/g,"/"))}),e}async function Qe(e,t={}){Ce(e,"node");let o=await oe(e,t);return Pe(o)}async function et(e,t={}){Ce(e,"browser");let o;if(e instanceof HTMLInputElement)o=Array.from(e.files);else if(typeof e=="object"&&e!==null&&typeof e.length=="number"&&typeof e.item=="function")o=Array.from(e);else if(Array.isArray(e)){if(e.length>0&&typeof e[0]=="string")throw v.ShipError.business("Invalid input type for browser environment. Expected File[], FileList, or HTMLInputElement.");o=e}else throw v.ShipError.business("Invalid input type for browser environment. Expected File[], FileList, or HTMLInputElement.");o=o.filter(s=>s.size===0?(console.warn(`Skipping empty file: ${s.name}`),!1):!0),ve(o);let n=await se(o,t);return Pe(n)}async function De(e,t={}){let o=w();if(o!=="node"&&o!=="browser")throw v.ShipError.business("Unsupported execution environment.");return o==="node"?Qe(e,t):et(e,t)}function Fe(e,t,o){return{create:async(n,s={})=>{o&&await o();let i=t?de(s,t):s,a=await De(n,i);return await e().deploy(a,i)},list:async()=>(o&&await o(),e().listDeployments()),remove:async n=>{o&&await o(),await e().removeDeployment(n)},get:async n=>(o&&await o(),e().getDeployment(n))}}function xe(e,t){return{set:async(o,n)=>(t&&await t(),e().setAlias(o,n)),get:async o=>(t&&await t(),e().getAlias(o)),list:async()=>(t&&await t(),e().listAliases()),remove:async o=>{t&&await t(),await e().removeAlias(o)}}}function Ee(e,t){return{get:async()=>(t&&await t(),e().getAccount())}}function Ae(e,t){return{create:async()=>(t&&await t(),e().createApiKey())}}var T=require("@shipstatic/types"),V=class{constructor(t={}){this.initPromise=null;if(this.clientOptions=t,this.environment=w(),this.environment!=="node"&&this.environment!=="browser")throw Re.ShipError.business("Unsupported execution environment.");let o=Q(t,{});this.http=new L({...t,...o});let n=this.getInitCallback(),s=()=>this.http;this._deployments=Fe(s,this.clientOptions,n),this._aliases=xe(s,n),this._account=Ee(s,n),this._keys=Ae(s,n)}async ensureInitialized(){return this.initPromise||(this.initPromise=this.initializeConfig()),this.initPromise}getInitCallback(){return()=>this.ensureInitialized()}async initializeConfig(){try{let t=await ue(this.clientOptions.configFile),o=Q(this.clientOptions,t);this.http=new L({...this.clientOptions,...o});let n=await this.http.getConfig();ge(n)}catch(t){throw this.initPromise=null,t}}async ping(){return await this.ensureInitialized(),this.http.ping()}async deploy(t,o){return this.deployments.create(t,o)}async whoami(){return this.account.get()}get deployments(){return this._deployments}get aliases(){return this._aliases}get account(){return this._account}get keys(){return this._keys}};var O=require("fs"),h=g(require("path"),1);var ie=g(require("columnify"),1),d=require("yoctocolors"),C=(e,t,o)=>o?t:e(t),P=(e,t,o)=>{console.log(t?JSON.stringify({success:e},null,2)+`
|
|
3
|
+
`:`${C(d.green,e.toLowerCase().replace(/\.$/,""),o)}
|
|
4
|
+
`)},D=(e,t,o)=>{if(t)console.error(JSON.stringify({error:e},null,2)+`
|
|
5
|
+
`);else{let n=C(i=>(0,d.inverse)((0,d.red)(i)),"error",o),s=C(d.red,e.toLowerCase().replace(/\.$/,""),o);console.error(`${n} ${s}
|
|
6
|
+
`)}},k=(e,t,o)=>{if(t)console.log(JSON.stringify({warning:e},null,2)+`
|
|
7
|
+
`);else{let n=C(i=>(0,d.inverse)((0,d.yellow)(i)),"warning",o),s=C(d.yellow,e.toLowerCase().replace(/\.$/,""),o);console.log(`${n} ${s}
|
|
8
|
+
`)}},_=(e,t,o)=>{if(t)console.log(JSON.stringify({info:e},null,2)+`
|
|
9
|
+
`);else{let n=C(i=>(0,d.inverse)((0,d.blue)(i)),"info",o),s=C(d.blue,e.toLowerCase().replace(/\.$/,""),o);console.log(`${n} ${s}
|
|
10
|
+
`)}},tt=(e,t="details",o)=>{if(e==null||e===0)return"-";let n=new Date(e*1e3).toISOString().replace(/\.\d{3}Z$/,"Z");return t==="table"?n.replace(/T/,C(d.hidden,"T",o)).replace(/Z$/,C(d.hidden,"Z",o)):n},$e=(e,t,o="details",n)=>{if(typeof t=="number"&&(e==="created"||e==="expires"||e==="confirmed"||e==="subscribed"||e==="suspended"))return tt(t,o,n);if(e==="size"&&typeof t=="number"){let s=t/1048576;return s>=1?`${s.toFixed(1)}Mb`:`${(t/1024).toFixed(1)}Kb`}if(e==="config"){if(typeof t=="boolean")return t?"yes":"no";if(typeof t=="number")return t===1?"yes":"no"}return String(t)},re=(e,t,o)=>{if(!e||e.length===0)return"";let n=e[0]||{},s=t||Object.keys(n).filter(l=>n[l]!==void 0&&l!=="verified"&&l!=="isCreate"),i=e.map(l=>{let p={};return s.forEach(c=>{c in l&&l[c]!==void 0&&(p[c]=$e(c,l[c],"table",o))}),p});return(0,ie.default)(i,{columnSplitter:" ",columns:s,config:s.reduce((l,p)=>(l[p]={headingTransform:c=>C(d.dim,c,o)},l),{})}).split(`
|
|
11
|
+
`).map(l=>l.replace(/\0/g,"").replace(/\s+$/,"")).join(`
|
|
12
|
+
`)+`
|
|
13
|
+
`},q=(e,t)=>{let o=Object.entries(e).filter(([i,a])=>i==="verified"||i==="isCreate"?!1:a!==void 0);if(o.length===0)return"";let n=o.map(([i,a])=>({property:i+":",value:$e(i,a,"details",t)}));return(0,ie.default)(n,{columnSplitter:" ",showHeaders:!1,config:{property:{dataTransform:i=>C(d.dim,i,t)}}}).split(`
|
|
14
|
+
`).map(i=>i.replace(/\0/g,"")).join(`
|
|
15
|
+
`)+`
|
|
16
|
+
`};var u=g(require("fs"),1),le=g(require("os"),1),ae={version:"0.0.0"};try{let e=h.resolve(__dirname,"../package.json");ae=JSON.parse((0,O.readFileSync)(e,"utf-8"))}catch{let t=h.resolve(__dirname,"../../package.json");try{ae=JSON.parse((0,O.readFileSync)(t,"utf-8"))}catch{}}var f=new Oe.Command;function Ie(e,t){if(!(e instanceof T.ShipError)){let s=e.message||e,i=f.opts();i.json?(console.error(JSON.stringify({error:s,details:{originalError:s}},null,2)),console.error()):D(s,void 0,i.noColor),process.exit(1)}let o=e.message;if(e.details?.data?.error==="not_found")if(t?.operation==="remove"){let s=t.resourceType||"resource";o=`${t.resourceId||""} ${s.toLowerCase()} not found`}else{let s=e.details.data.message||"Resource not found",i=s.match(/^(.*?)\s+(.+?)\s+not found$/);if(i){let[,a,l]=i;o=`${l} ${a.toLowerCase()} not found`}else o=s}else e.details?.data?.error==="business_logic_error"?o=e.details.data.message||"Business logic error occurred":e.isAuthError()?o="authentication failed":e.isNetworkError()?o="network error":!e.isFileError()&&!e.isValidationError()&&!e.isClientError()&&(o="server error");let n=f.opts();n.json?(console.error(JSON.stringify({error:o,...e.details?{details:e.details}:{}},null,2)),console.error()):D(o,void 0,n.noColor),process.exit(1)}function E(e,t){return async(...o)=>{try{let n=Te(),s=await e(n,...o),i=t?{operation:t.operation,resourceType:t.resourceType,resourceId:t.getResourceId?t.getResourceId(...o):void 0}:void 0;je(s,i)}catch(n){let s=t?{operation:t.operation,resourceType:t.resourceType,resourceId:t.getResourceId?t.getResourceId(...o):void 0}:void 0;Ie(n,s)}}}function Te(){let e=f.opts(),t={};return e.config!==void 0&&(t.configFile=e.config),e.apiUrl!==void 0&&(t.apiUrl=e.apiUrl),e.apiKey!==void 0&&(t.apiKey=e.apiKey),new V(t)}var ot={deployments:(e,t,o,n)=>{if(!e.deployments||e.deployments.length===0){_("no deployments found",o,n);return}let s=["deployment","url","created"];console.log(re(e.deployments,s,n))},aliases:(e,t,o,n)=>{if(!e.aliases||e.aliases.length===0){_("no aliases found",o,n);return}let s=["alias","deployment","url","created"];console.log(re(e.aliases,s,n))},alias:(e,t,o,n)=>{if(e.alias){let s=e.isCreate?"created":"updated";P(`${e.alias} alias ${s}`,o,n)}console.log(q(e,n))},deployment:(e,t,o,n)=>{e.status&&t?.operation==="create"&&P(`${e.deployment} deployment created`,o,n),console.log(q(e,n))},email:(e,t,o,n)=>{console.log(q(e,n))}};function je(e,t){let o=f.opts();if(e===void 0){t?.operation==="remove"&&t.resourceType&&t.resourceId?P(`${t.resourceId} ${t.resourceType.toLowerCase()} removed`,o.json,o.noColor):P("removed successfully",o.json,o.noColor);return}if(e===!0||e&&typeof e=="object"&&e.hasOwnProperty("success")){e===!0||e.success?P("api reachable",o.json,o.noColor):D("api unreachable",o.json,o.noColor);return}if(o.json){console.log(JSON.stringify(e,null,2)),console.log();return}for(let[n,s]of Object.entries(ot))if(e[n]){s(e,t,o.json,o.noColor);return}P("success",o.json,o.noColor)}async function Le(e,t){try{if(!(0,O.existsSync)(e))throw T.ShipError.file(`${e} path does not exist`,e);let o=(0,O.statSync)(e);if(!o.isDirectory()&&!o.isFile())throw T.ShipError.file(`${e} path must be a file or directory`,e);let n=Te(),s={};t?.preserveDirs&&(s.preserveDirs=!0);let i=new AbortController;s.signal=i.signal;let a=f.opts(),l=null;if(!a.json){let{default:r}=await import("yocto-spinner");l=r({text:"uploading\u2026"}).start()}let p=()=>{i.abort(),l&&l.stop(),process.exit(130)};process.on("SIGINT",p);let c=await n.deployments.create([e],s);process.removeListener("SIGINT",p),l&&l.stop(),je(c,{operation:"create"})}catch(o){if(!f.opts().json)try{let{default:n}=await import("yocto-spinner");n({text:""}).stop()}catch{}Ie(o)}}f.name("ship").description("\u{1F680} Deploy static sites with simplicity").version(ae.version,"-v, --version","Show version information").option("-k, --api-key <key>","API key for authentication").option("-c, --config <file>","Custom config file path").option("-u, --api-url <url>","API URL (for development)").option("-p, --preserve-dirs","Preserve directory structure in deployment").option("-j, --json","Output results in JSON format").option("--no-color","Disable colored output");f.command("ping").description("Check API connectivity").action(E(e=>e.ping()));f.command("whoami").description("Get current account information").action(E(e=>e.whoami()));var W=f.command("deployments").description("Manage deployments");W.command("list").description("List all deployments").action(E(e=>e.deployments.list()));W.command("create <path>").description("Deploy project from path").action(Le);W.command("get <deployment>").description("Get deployment details").action(E((e,t)=>e.deployments.get(t)));W.command("remove <deployment>").description("Remove deployment").action(E((e,t)=>e.deployments.remove(t),{operation:"remove",resourceType:"Deployment",getResourceId:e=>e}));var Z=f.command("aliases").description("Manage aliases");Z.command("list").description("List all aliases").action(E(e=>e.aliases.list()));Z.command("get <name>").description("Get alias details").action(E((e,t)=>e.aliases.get(t)));Z.command("set <name> <deployment>").description("Set alias to deployment").action(E((e,t,o)=>e.aliases.set(t,o),{operation:"set"}));Z.command("remove <name>").description("Remove alias").action(E((e,t)=>e.aliases.remove(t),{operation:"remove",resourceType:"Alias",getResourceId:e=>e}));var nt=f.command("account").description("Manage account");nt.command("get").description("Get account details").action(E(e=>e.whoami()));var Ne=f.command("completion").description("Setup shell completion");Ne.command("install").description("Install shell completion script").action(async()=>{let e=process.env.SHELL||"",t=le.homedir(),o,n,s,i=h.resolve(__dirname,"completions/ship.bash"),a=h.resolve(__dirname,"completions/ship.zsh"),l=h.resolve(__dirname,"completions/ship.fish");try{if(e.includes("bash"))o=h.join(t,".ship_completion.bash"),n=h.join(t,".bash_profile"),s=`
|
|
17
|
+
# Ship CLI completion
|
|
18
|
+
source '${o}'
|
|
19
|
+
`,u.copyFileSync(i,o);else if(e.includes("zsh"))o=h.join(t,".ship_completion.zsh"),n=h.join(t,".zshrc"),s=`
|
|
20
|
+
# Ship CLI completion
|
|
21
|
+
source '${o}'
|
|
22
|
+
`,u.copyFileSync(a,o);else if(e.includes("fish")){let r=h.join(t,".config/fish/completions");u.existsSync(r)||u.mkdirSync(r,{recursive:!0}),o=h.join(r,"ship.fish"),u.copyFileSync(l,o);let m=f.opts();P("fish completion installed successfully",m.json,m.noColor),_("please restart your shell to apply the changes",m.json,m.noColor);return}else{let r=f.opts();D(`unsupported shell: ${e}. could not install completion script`,r.json,r.noColor);return}u.existsSync(n)?u.readFileSync(n,"utf-8").includes("ship_completion")||u.appendFileSync(n,s):u.writeFileSync(n,s);let c=f.opts();P(`completion script installed for ${e.split("/").pop()}`,c.json,c.noColor),k(`run "source ${n}" or restart your shell`,c.json,c.noColor)}catch(p){let c=f.opts();D(`could not install completion script: ${p.message}`,c.json,c.noColor),(e.includes("bash")||e.includes("zsh"))&&k(`add the following line to your profile file manually
|
|
23
|
+
${s}`,c.json,c.noColor)}});Ne.command("uninstall").description("Uninstall shell completion script").action(async()=>{let e=process.env.SHELL||"",t=le.homedir(),o,n;try{if(e.includes("bash"))o=h.join(t,".ship_completion.bash"),n=h.join(t,".bash_profile");else if(e.includes("zsh"))o=h.join(t,".ship_completion.zsh"),n=h.join(t,".zshrc");else if(e.includes("fish")){let s=h.join(t,".config/fish/completions");o=h.join(s,"ship.fish");let i=f.opts();u.existsSync(o)?(u.unlinkSync(o),P("fish completion uninstalled successfully",i.json,i.noColor)):k("fish completion was not installed",i.json,i.noColor),_("please restart your shell to apply the changes",i.json,i.noColor);return}else{let s=f.opts();D(`unsupported shell: ${e}. could not uninstall completion script`,s.json,s.noColor);return}if(u.existsSync(o)&&u.unlinkSync(o),u.existsSync(n)){let i=u.readFileSync(n,"utf-8").split(`
|
|
24
|
+
`),a=i.filter(p=>!p.includes("ship_completion")&&!p.includes("Ship CLI completion")),l=f.opts();a.length!==i.length?(u.writeFileSync(n,a.join(`
|
|
25
|
+
`)),P(`completion script uninstalled for ${e.split("/").pop()}`,l.json,l.noColor),k(`run "source ${n}" or restart your shell`,l.json,l.noColor)):D("completion was not found in profile",l.json,l.noColor)}else{let s=f.opts();D("profile file not found",s.json,s.noColor)}}catch(s){let i=f.opts();D(`could not uninstall completion script: ${s.message}`,i.json,i.noColor)}});f.argument("[path]","Path to deploy").action(async(e,t)=>{if(!e){f.help();return}if(!e.includes("/")&&!e.startsWith(".")&&!e.startsWith("~")){let o=f.opts();o.json?console.error(JSON.stringify({error:`unknown command '${e}'`},null,2)):D(`unknown command '${e}'`,void 0,o.noColor),process.exit(1)}await Le(e,t)});function st(){let e=process.argv,t=e.includes("--compbash"),o=e.includes("--compzsh"),n=e.includes("--compfish");if(!t&&!o&&!n)return;console.log(["ping","whoami","deployments","aliases","account","completion"].join(n?`
|
|
26
|
+
`:" ")),process.exit(0)}process.env.NODE_ENV!=="test"&&(process.argv.includes("--compbash")||process.argv.includes("--compzsh")||process.argv.includes("--compfish"))&&st();if(process.env.NODE_ENV!=="test")try{f.parse(process.argv)}catch(e){throw e.code&&e.code.startsWith("commander.")&&process.exit(e.exitCode||1),e}
|
|
20
27
|
//# sourceMappingURL=cli.cjs.map
|