Skip to content

Commit

Permalink
Merge pull request #130 from rolldone/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rolldone authored Aug 11, 2022
2 parents 210ec9e + e7ad992 commit 5497624
Show file tree
Hide file tree
Showing 15 changed files with 526 additions and 113 deletions.
69 changes: 69 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"dotenv": "^8.2.0",
"eventemitter2": "^6.4.4",
"filendir": "^2.0.1",
"folder-encrypt": "^1.1.7",
"gulp": "^4.0.2",
"ignore": "^5.1.8",
"inquirer": "^8.2.0",
Expand Down
3 changes: 2 additions & 1 deletion src/app/console/services/OpenConsoleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import rl, { ReadLine } from 'readline';
import { CliInterface } from "./CliService";
import Config, { ConfigInterface } from "../compute/Config";
import path from "path";
import upath from 'upath';
var size = require('window-size');

export interface OpenConsoleServiceInterface extends BaseServiceInterface {
Expand Down Expand Up @@ -76,7 +77,7 @@ const OpenConsoleService = BaseService.extend<OpenConsoleServiceInterface>({

let execPathFileName = path.basename(process.execPath);
execPathFileName = (execPathFileName == "node" || execPathFileName == "node.exe") ? "ngi-sync" : process.execPath;
_ptyProcess.write(`${execPathFileName}\r`);
_ptyProcess.write(`${upath.normalize(execPathFileName)}\r`);

return _ptyProcess;
},
Expand Down
18 changes: 17 additions & 1 deletion src/app/devsync/compute/Uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,12 @@ export default class Uploader {
// debug: true
});
this.client.on('close', () => {
this.connect(callback);
setTimeout(()=>{
if(this.client == null){
return;
}
this.connect(callback);
},1000);
})
callback(null, 'Connected');
} catch (ex) {
Expand All @@ -573,6 +578,7 @@ export default class Uploader {
_exeHandlePush: Function = null;
clientClose(): void {
this.client.end();
this.client = null;
}
async _executeCommand(whatCommand: string, callback?: Function) {
try {
Expand Down Expand Up @@ -654,6 +660,12 @@ export default class Uploader {
debounceClose();
}
return (entry: any, first_time_out: number) => {

if(this.client == null){
this._pendingQueue = {};
return;
}

this._orders[entry.queue_no] = Object.create({
...entry,
queue_no: entry.queue_no
Expand Down Expand Up @@ -689,6 +701,10 @@ export default class Uploader {
var fileName = entry.fileName;
var action = entry.action;

if(this.client == null){
return;
}

switch (action) {
case 'add_change':
/* Check the size of file first */
Expand Down
9 changes: 7 additions & 2 deletions src/app/devsync/compute/Watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export default class Watcher {

gitIgnore = [
...gitIgnore,
...defaultIgnores
...defaultIgnores,
this.config.privateKey
]

let resCHeckGItIgnores = (() => {
Expand Down Expand Up @@ -399,7 +400,11 @@ export default class Watcher {
}

async close(): Promise<void> {
this.uploader.client.end();
try {
this.uploader.client.end();
} catch (ex) {
console.log("this.uploader.client.end - ex :: ", ex);
}
for (var a = 0; a < this._unwatch.length; a++) {
await this._unwatch[a].close();
}
Expand Down
55 changes: 41 additions & 14 deletions src/app/devsync/services/DevSyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export const COMMAND_TARGET = {


var cache_command: Array<string> = [];
var questions_command = null;
var _readLine: ReadLine = null;

const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
returnConfig: function (cli) {
Expand Down Expand Up @@ -368,14 +370,14 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
});

/* Define readline nodejs for listen CTRL + R */
this._readLine = rl.createInterface({
_readLine = rl.createInterface({
input: process.stdin,
output: process.stdout,
terminal: true
});


let questions_command = [
questions_command = [
{
type: "rawlist",
name: "remote",
Expand Down Expand Up @@ -408,6 +410,10 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
}
]

masterData.setOnListener("listen_from_outside", async (val) => {
this.construct(this._cli);
})

let remoteFuncKeypress = async (key: any, data: any) => {
let total_tab = 9;
switch (data.sequence) {
Expand All @@ -432,7 +438,7 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
this._actionMode = "devsync";
this.watcher.actionMode = this._actionMode;

this._readLine = rl.createInterface({
_readLine = rl.createInterface({
input: process.stdin,
output: process.stdout,
// terminal: true
Expand All @@ -442,7 +448,10 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
break;
case '\u001b2':
console.clear();
this._readLine.close();
try {
_readLine.close();
_readLine = null;
} catch (ex) { }
process.stdin.removeListener('keypress', remoteFuncKeypress);
process.stdout.write(chalk.green('Console | ') + 'Start Console' + '\r');
for (var i = 0; i < total_tab; i++) {
Expand Down Expand Up @@ -473,7 +482,10 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({

for (var i = 0; i < total_tab; i++) {
if (data.sequence == '\u001b' + (i + 3)) {
this._readLine.close();
try {
_readLine.close();
_readLine = null;
} catch (ex) { }
process.stdin.removeListener('keypress', remoteFuncKeypress);
console.clear();
this.uploader.setConsoleAction("pending first");
Expand Down Expand Up @@ -614,27 +626,42 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
case '\x12':
this._is_stop = true;
let stop = async () => {
this._readLine.close();
this._readLine.removeAllListeners();
try {
_readLine.close();
_readLine = null;
} catch (ex) { }
_startWatchingWithTimeOut(true);
syncPull.stopSubmitWatch();
syncPull = null;

try {
if (syncPull != null) {
syncPull.stopSubmitWatch();
}
syncPull = null;
} catch (ex) {
console.log("syncPull - ex :: ", ex);
}

await this.watcher.close();
this.watcher = null;

/* Restart the syncronize */
this.uploader.onListener('RESTART', {});
this.uploader = null;
try {
if (this.uploader != null) {
this.uploader.clientClose();
this.uploader.onListener('RESTART', {});
}
this.uploader = null;
} catch (ex) {
console.log("this.uploader - ex :: ", ex);
}

process.stdin.off('keypress', remoteFuncKeypress);
process.stdin.removeAllListeners('keypress');
this.task.done();
console.clear();
process.stdout.write(chalk.green('Remote | ') + 'Restarting...' + '\r');

setTimeout(() => {
this.construct(this._cli);
}, 3000);
masterData.saveData("listen_from_outside", {});
}
var closeRemote = () => {
if (this._currentConf.devsync.script.remote.on_stop != "" && this._currentConf.devsync.script.remote.on_stop != null) {
Expand Down
26 changes: 17 additions & 9 deletions src/app/devsync2/compute/HttpEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CliInterface } from "../services/CliService";
var size = require('window-size');
import os from 'os';
import { ConfigInterface } from "./Config";
import { fstatSync, readFileSync, Stats, statSync, writeFileSync } from "fs";
import { existsSync, fstatSync, readFileSync, Stats, statSync, writeFileSync } from "fs";
import parseGitIgnore from '@root/tool/parse-gitignore'
import ignore from 'ignore'
import { uniq } from "lodash";
Expand Down Expand Up @@ -271,7 +271,7 @@ const HttpEvent = BaseModel.extend<Omit<HttpEventInterface, 'model'>>({
const isLocal = typeof process.pkg === 'undefined';

let localFilePath = isLocal ? upath.normalizeSafe(path.join(__dirname, "") + '/' + tarFile) : path.dirname(process.execPath) + `/${tarFile}`;
let remoteFilePath = upath.normalizeSafe(this._config.remotePath + '/' + tarFile);
let remoteFilePath = upath.normalizeSafe(this._config.remotePath + '/.sync_agents/' + tarFile);
let exists = await this._client.exists(remoteFilePath);
let curretnFileStat = statSync(isLocal ? upath.normalizeSafe(path.join(__dirname, "")) + '/' + tarFile : path.dirname(process.execPath) + `/${tarFile}`, {});
let executeFile = upath.normalizeSafe(this._config.remotePath + '/' + fileName);
Expand Down Expand Up @@ -315,7 +315,7 @@ const HttpEvent = BaseModel.extend<Omit<HttpEventInterface, 'model'>>({
case 'darwin':
case 'linux':
let rawSSH = await this._client.getRawSSH2();
rawSSH.exec('tar -zxf ' + remoteFilePath + " --directory " + this._config.remotePath, async (err: any, stream: any) => {
rawSSH.exec('tar -zxf ' + remoteFilePath + " --directory " + path.dirname(remoteFilePath), async (err: any, stream: any) => {
process.stdout.write(chalk.green('Devsync | '));
process.stdout.write(chalk.green('Install Agent :: Extrating.' + '\n'));
resolve();
Expand All @@ -335,7 +335,10 @@ const HttpEvent = BaseModel.extend<Omit<HttpEventInterface, 'model'>>({
process.stdout.write('Copy file agent -> ' + localFilePath + ' - ' + remoteFilePath + '\n');
try {
// await this._client.delete(remoteFilePath);
} catch (ex) { }
await this._client.mkdir(path.dirname(remoteFilePath));
} catch (ex) {
console.log(ex);
}
try {
await this._client.mkdir(path.dirname(localFilePath), false);
await this._client.chmod(path.dirname(localFilePath), this._config.pathMode);
Expand Down Expand Up @@ -368,14 +371,19 @@ const HttpEvent = BaseModel.extend<Omit<HttpEventInterface, 'model'>>({
generateSSHConfig() {
let _direct_access: DirectAccessType = this._config.direct_access as any;
let _configFilePath = upath.normalizeSafe(os.homedir() + '/.ssh/config');

let _privateKey = null;
if (existsSync(upath.normalize(process.cwd() + "/" + this._config.privateKey)) == true) {
_privateKey = upath.normalize(process.cwd() + "/" + this._config.privateKey);
} else {
_privateKey = this._config.privateKey
}
/* Persisten ssh_config */
let ssh_confi = {
Host: "temp_reverse_port_ssh",
HostName: this._config.host,
User: this._config.username,
Port: this._config.port,
IdentityFile: this._config.privateKey,
IdentityFile: _privateKey,
RequestTTY: "force",
StrictHostKeyChecking: "no"
}
Expand Down Expand Up @@ -424,13 +432,13 @@ const HttpEvent = BaseModel.extend<Omit<HttpEventInterface, 'model'>>({
_ptyProcess.write(`cd ${this._config.remotePath} \r`);
switch (this._config.devsync.os_target) {
case 'windows':
_ptyProcess.write(`ngi-sync-agent-win.exe devsync_remote ${this._randomPort}` + "\r");
_ptyProcess.write(`./sync_agents/ngi-sync-agent-win.exe devsync_remote ${this._randomPort}` + "\r");
break;
case 'darwin':
case 'linux':
default:
_ptyProcess.write("chmod +x ngi-sync-agent-linux" + '\r');
_ptyProcess.write(`./ngi-sync-agent-linux devsync_remote ${this._randomPort}` + "\r");
_ptyProcess.write("chmod +x ./.sync_agents/ngi-sync-agent-linux" + '\r');
_ptyProcess.write(`./.sync_agents/ngi-sync-agent-linux devsync_remote ${this._randomPort}` + "\r");
break;
}
isLoginFinish = true;
Expand Down
Loading

0 comments on commit 5497624

Please sign in to comment.