cloudstudio
Version:
Run VS Code on a remote server.
52 lines (51 loc) • 6.04 kB
JavaScript
var G=Object.create;var h=Object.defineProperty,J=Object.defineProperties,L=Object.getOwnPropertyDescriptor,V=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertyNames,E=Object.getOwnPropertySymbols,z=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var T=(e,o,t)=>o in e?h(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,w=(e,o)=>{for(var t in o||(o={}))D.call(o,t)&&T(e,t,o[t]);if(E)for(var t of E(o))B.call(o,t)&&T(e,t,o[t]);return e},W=(e,o)=>J(e,V(o)),M=e=>h(e,"__esModule",{value:!0});var K=(e,o)=>{M(e);for(var t in o)h(e,t,{get:o[t],enumerable:!0})},Q=(e,o,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of q(o))!D.call(e,r)&&r!=="default"&&h(e,r,{get:()=>o[r],enumerable:!(t=L(o,r))||t.enumerable});return e},v=e=>Q(M(h(e!=null?G(z(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var b=(e,o,t)=>new Promise((r,i)=>{var l=a=>{try{m(t.next(a))}catch(u){i(u)}},p=a=>{try{m(t.throw(a))}catch(u){i(u)}},m=a=>a.done?r(a.value):Promise.resolve(a.value).then(l,p);m((t=t.apply(e,o)).next())});K(exports,{activate:()=>Y,deactivate:()=>Z});var n=v(require("vscode")),S=v(require("child_process")),y=v(require("fs")),H=v(require("fs/promises"));var c=v(require("vscode")),f=v(require("path")),X=(e,o,t="web")=>{let r=i=>o.webview.asWebviewUri(c.Uri.file(f.join(e.extensionPath,t,"dist",i)));return`
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
/>
<link rel="stylesheet" href="${r("umi.css")}" />
<style>
html, body, #root {
background-color: var(--vscode-editor-background);
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
// \u7ED9 webview \u5185\u5BB9\u52A0\u4E0A\u4E3B\u9898
body.vscode-light {
color: black;
background-color: var(--vscode-editor-background);
}
body.vscode-light h1, h2, h3, h4, h5, h6 {
color: black;
}
body.vscode-dark {
color: white;
background-color: var(--vscode-editor-background);
}
body.vscode-dark h1, h2, h3, h4, h5, h6 {
color: white;
}
body.vscode-high-contrast {
color: red;
background-color: var(--vscode-editor-background);
}
body.vscode-high-contrast h1, h2, h3, h4, h5, h6 {
color: red;
}
</style>
<script>
window.vscodeEnv = ${JSON.stringify({language:c.env.language})}
<\/script>
</head>
<body>
<div id="root"></div>
<script src="${r("umi.js")}"><\/script>
</body>
</html>
`},d,I=(e,o,t,r)=>{let i=c.window.activeTextEditor?c.window.activeTextEditor.viewColumn:void 0;return d?d.reveal(i):(d=c.window.createWebviewPanel(o,t,c.ViewColumn.One,{enableScripts:!0,localResourceRoots:[c.Uri.file(f.join(e.extensionPath,"web/dist"))],retainContextWhenHidden:!0}),d.iconPath=c.Uri.file(f.join(e.extensionPath,r)),d.webview.html=X(e,d)),d.onDidDispose(()=>{d=void 0},null,e.subscriptions),d};var O=v(require("vscode")),F,R=((F=O.extensions.getExtension("CloudStudio.common"))==null?void 0:F.exports)||{};var s,k,P,$,j=()=>{if(P=y.realpathSync(n.workspace.workspaceFolders[0].uri.fsPath),$=y.existsSync(`${n.workspace.workspaceFolders[0].uri.fsPath}/.git`),$)try{k=S.execSync('([ "$(git remote | wc -l)" -eq "1" ] && (git remote |xargs git remote get-url)) || (git remote get-url origin 2> /dev/null)',{cwd:P}).toString(),console.log("gitUrl",k)}catch(e){console.log("\u8BF7\u5148\u8FDB\u5165\u9879\u76EE\u6587\u4EF6\u5939\u518D\u53D1\u5E03"),console.log("output",e)}};function Y(e){return b(this,null,function*(){if(!R.isCloudStudio)return;j();let o=yield n.commands.executeCommand("cloudstudio.getPublicConfig");s&&n.commands.executeCommand("custom-template.start");function t(i,l){let{callbackId:p}=l,m=w({callbackId:p},i);s==null||s.webview.postMessage(m)}e.subscriptions.push(n.commands.registerCommand("custom-template.start",()=>b(this,null,function*(){if(j(),s)return s.reveal(n.ViewColumn.Active);s=I(e,"custom-template","\u81EA\u5B9A\u4E49\u6A21\u677F","assets/favicon.ico"),s.webview.onDidReceiveMessage(i=>b(this,null,function*(){var l,p;switch(i.type){case"deploy":case"reissue":let{versionControlType:m,versionControlUrl:a}=i.params;console.log({event:i.type,label:"\u6A21\u677F",params:W(w({},i.params),{versionControlUrl:k||a,versionControlType:k?"GIT":m})});let u=S.execSync("du -s .",{cwd:P}).toString().replace(/\./g,"");s==null||s.webview.postMessage({memory:u});break;case"icons-tags":console.log({event:"icons-tags",label:"\u6A21\u677F"});break;case"get template":console.log({event:"get template",label:"\u6A21\u677F"}),o&&(s==null||s.webview.postMessage({config:o}));break;case"getPath":let x=yield n.window.showOpenDialog({defaultUri:n.Uri.file(N()),canSelectFolders:!0,canSelectFiles:!1});t({result:(l=x==null?void 0:x[0])==null?void 0:l.path},i);break;case"getDefaultPath":let U=((p=process.env.IDE_SNAPSHOT_PATH)!=null?p:"").split(",");Promise.allSettled(U.map(C=>(0,H.stat)(C))).then(C=>{let _=C.map((g,A)=>g.status==="fulfilled"&&g.value.isDirectory()?U[A]:!1).filter(g=>g!==!1);t({result:{defaultPath:N(),snapshotPath:_}},i)});break;default:console.log({event:"get template",label:"\u6A21\u677F"});break}}),void 0,e.subscriptions),s.onDidDispose(()=>{s=void 0},void 0,e.subscriptions)})));let r=n.commands.registerCommand("template.messageHandler",i=>{let l=JSON.parse(JSON.stringify(i));s==null||s.webview.postMessage(w({},l))});e.subscriptions.push(r)})}function Z(){s==null||s.dispose(),s=void 0}var N=()=>{let{workspaceFolders:e}=n.workspace;return e&&e.length>0?e[0].uri.path:""};0&&(module.exports={activate,deactivate});