style: tab -> 2 spaces in all typescript files

This commit is contained in:
Levi Yan
2024-11-12 19:07:30 +08:00
parent 97a22b4deb
commit 27a09a49ab
4 changed files with 291 additions and 291 deletions

View File

@@ -9,40 +9,40 @@ import * as utils from './utils';
import User from './user';
export default class RemoteContainer {
private user:User;
private user: User;
constructor(user:User) {
constructor(user: User) {
this.user = user
}
async firstConnect(host: string, username: string, port: number): Promise<string>; // connect with key
// deprecated
async firstConnect(host: string, username: string, port: number, password: string): Promise<string>;
async firstConnect(host: string, username: string, port: number, password: string): Promise<string>;
async firstConnect(host: string, username: string, port: number, password?: string): Promise<string> {
return new Promise(async (resolve, reject) => {
const ssh = new NodeSSH();
vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: "正在容器中安装vscode-server及devstar插件",
cancellable: false
location: vscode.ProgressLocation.Notification,
title: "正在容器中安装vscode-server及devstar插件",
cancellable: false
}, async (progress) => {
try {
try {
if (password === undefined) {
// connect with key
await ssh.connect({
host: host,
username: username,
port: port,
privateKeyPath: this.user.getUserPrivateKeyPath()
});
progress.report({ message: "连接成功,开始安装" });
if (password === undefined) {
// connect with key
await ssh.connect({
host: host,
username: username,
port: port,
privateKeyPath: this.user.getUserPrivateKeyPath()
});
progress.report({ message: "连接成功,开始安装" });
// install vscode-server and devstar extension
const vscodeCommitId = await utils.getVsCodeCommitId();
const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz`
const installVscodeServerScript = `
// install vscode-server and devstar extension
const vscodeCommitId = await utils.getVsCodeCommitId();
const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz`
const installVscodeServerScript = `
mkdir -p ~/.vscode-server/bin/${vscodeCommitId} && \\
if [ "$(ls -A ~/.vscode-server/bin/${vscodeCommitId})" ]; then
~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar
@@ -55,25 +55,25 @@ export default class RemoteContainer {
~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar
fi
`;
await ssh.execCommand(installVscodeServerScript);
console.log("vscode-server and extension installed");
vscode.window.showInformationMessage('安装完成!');
await ssh.execCommand(installVscodeServerScript);
console.log("vscode-server and extension installed");
vscode.window.showInformationMessage('安装完成!');
await ssh.dispose();
} else {
// connect with password (deprecate in future)
await ssh.connect({
host: host,
username: username,
password: password,
port: port
});
progress.report({ message: "连接成功,开始安装" });
await ssh.dispose();
} else {
// connect with password (deprecate in future)
await ssh.connect({
host: host,
username: username,
password: password,
port: port
});
progress.report({ message: "连接成功,开始安装" });
// install vscode-server and devstar extension
const vscodeCommitId = await utils.getVsCodeCommitId();
const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz`
const installVscodeServerScript = `
// install vscode-server and devstar extension
const vscodeCommitId = await utils.getVsCodeCommitId();
const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz`
const installVscodeServerScript = `
mkdir -p ~/.vscode-server/bin/${vscodeCommitId} && \\
if [ "$(ls -A ~/.vscode-server/bin/${vscodeCommitId})" ]; then
~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar
@@ -86,63 +86,63 @@ export default class RemoteContainer {
~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar
fi
`;
await ssh.execCommand(installVscodeServerScript);
console.log("vscode-server and extension installed");
vscode.window.showInformationMessage('安装完成!');
await ssh.execCommand(installVscodeServerScript);
console.log("vscode-server and extension installed");
vscode.window.showInformationMessage('安装完成!');
// add the public key to the remote authorized_keys
if (!utils.existDefaultPublicKey() || !utils.existDefaultPrivateKey()) {
// if there is no public key, generate one
utils.createSSHKey()
// add the public key to the remote authorized_keys
if (!utils.existDefaultPublicKey() || !utils.existDefaultPrivateKey()) {
// if there is no public key, generate one
utils.createSSHKey()
}
const publicKey = utils.getDefaultPublicKey();
await ssh.execCommand(`mkdir -p ~/.ssh && echo '${publicKey}' >> ~/.ssh/authorized_keys`);
console.log('Public key added to remote authorized_keys');
await ssh.dispose();
}
const publicKey = utils.getDefaultPublicKey();
await ssh.execCommand(`mkdir -p ~/.ssh && echo '${publicKey}' >> ~/.ssh/authorized_keys`);
console.log('Public key added to remote authorized_keys');
} catch (error) {
console.error('Failed to install vscode-server and extension: ', error);
await ssh.dispose();
reject(error);
}
} catch (error) {
console.error('Failed to install vscode-server and extension: ', error);
await ssh.dispose();
reject(error);
}
// only connect successfully then save the host info
const sshConfigPath = path.join(os.homedir(), '.ssh', 'config');
// check if the host and related info exist in local ssh config file before saving
var canAppendSSHConfig = true
if (fs.existsSync(sshConfigPath)) {
var reader = rd.createInterface(fs.createReadStream(sshConfigPath))
// only connect successfully then save the host info
const sshConfigPath = path.join(os.homedir(), '.ssh', 'config');
// check if the host and related info exist in local ssh config file before saving
var canAppendSSHConfig = true
if (fs.existsSync(sshConfigPath)) {
var reader = rd.createInterface(fs.createReadStream(sshConfigPath))
for await (const line of reader) {
// host format: hostname:port
if (line.includes(`Host ${host}-${port}`)) {
// the container ssh info exists
canAppendSSHConfig = false
break;
for await (const line of reader) {
// host format: hostname:port
if (line.includes(`Host ${host}-${port}`)) {
// the container ssh info exists
canAppendSSHConfig = false
break;
}
}
}
}
if (canAppendSSHConfig) {
// save the host to the local ssh config file
const hostInConfig = `${host}-${port}` // host format: hostname-port
const privateKeyPath = this.user.getUserPrivateKeyPath();
const newSShConfigContent =
`\nHost ${hostInConfig}\n HostName ${host}\n Port ${port}\n User ${username}\n PreferredAuthentications publickey\n IdentityFile ${privateKeyPath}\n `;
fs.writeFileSync(sshConfigPath, newSShConfigContent, { encoding: 'utf8', flag: 'a' });
console.log('Host registered in local ssh config');
}
if (canAppendSSHConfig) {
// save the host to the local ssh config file
const hostInConfig = `${host}-${port}` // host format: hostname-port
const privateKeyPath = this.user.getUserPrivateKeyPath();
const newSShConfigContent =
`\nHost ${hostInConfig}\n HostName ${host}\n Port ${port}\n User ${username}\n PreferredAuthentications publickey\n IdentityFile ${privateKeyPath}\n `;
fs.writeFileSync(sshConfigPath, newSShConfigContent, { encoding: 'utf8', flag: 'a' });
console.log('Host registered in local ssh config');
}
resolve("success");
});
resolve("success");
});
});
}
openRemoteFolder(host: string, username:string ,port:number, path: string): void {
openRemoteFolder(host: string, username: string, port: number, path: string): void {
var host = `${host}-${port}`
const command = `code --remote ssh-remote+${username}@${host} ${path} --reuse-window`
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);