Skip to content

Commit

Permalink
Merge pull request #124 from rolldone/working
Browse files Browse the repository at this point in the history
Working
  • Loading branch information
rolldone authored Jun 22, 2022
2 parents 64cc0a4 + 345399d commit c7aa4ab
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 39 deletions.
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
15 changes: 9 additions & 6 deletions src/app/devsync2/compute/HttpEvent.ts
Original file line number Diff line number Diff line change
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 @@ -424,13 +427,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
4 changes: 2 additions & 2 deletions src/app/devsync2/services/DevSync2Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({
this._httpEvent = this.returnHttpEvent(this._cli, this._currentConf);
this._httpEvent.setOnChangeListener(async (action, props) => {
process.stdout.write(chalk.green('Ngi-sync Agent | '));
process.stdout.write(chalk.green('Action :: ') + action + " - " + props + '\n');
process.stdout.write(chalk.green('Action :: ') + action + " - " + (props || "HTTP") + '\n');
await this._download.startSftp();
let _pendingWaitingONSftp = () => {
if (this._download._client == null) {
Expand Down Expand Up @@ -372,7 +372,7 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({
case 'CLIENT_REQUEST':
process.stdout.write(chalk.green('Devsync | '));
process.stdout.write(chalk.green('CLIENT_REQUEST :: '));
process.stdout.write('Remote success trying request' + '\n');
process.stdout.write('Access the host is success' + '\n');
break;
case 'LISTEN_PORT':
process.stdout.write(chalk.green('Devsync | '));
Expand Down
74 changes: 44 additions & 30 deletions src/app/init/services/InitConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { CliInterface } from "./CliService";
import YAML from 'yaml';
import { MasterDataInterface } from "@root/bootstrap/StartMasterData";
import path from 'path';
import { homedir } from "os";

declare var masterData: MasterDataInterface;

export interface InitConfigInterface extends BaseServiceInterface {
returnConfigModel: { (cli: CliInterface): ConfigInterface }
currentConf?: ConfigInterface
generateTemplate?: { (silent?: boolean): void }
generateTemplate?: { (silent?: boolean, sync_collection_src?: string): void }
generateRandomString?: { (length: number): string }
}

Expand All @@ -36,13 +37,14 @@ const InitConfigService = BaseService.extend<InitConfigInterface>({
}
return result;
},
generateTemplate: function (silent = true) {
generateTemplate: function (silent = true, sync_collection_src) {
let basePathFolder = upath.normalizeSafe(path.join(__dirname));
let test: any = existsSync(upath.normalizeSafe(basePathFolder + '/example.yaml'));
if (test == false) {
test = {};
} else {
test = YAML.parse(readFileSync(upath.normalizeSafe(basePathFolder + '/example.yaml'), 'utf8'));
test.sync_collection.src = sync_collection_src || upath.normalize(homedir() + "/sync_collections");
}
if (existsSync(path.resolve('sync-config.yaml')) == false) {
writeFileSync(CONFIG_FILE_NAME, YAML.stringify(test, null), 'utf8');
Expand All @@ -52,43 +54,55 @@ const InitConfigService = BaseService.extend<InitConfigInterface>({
console.log('---------------------------------------------------')
}
} else {
writeFileSync(this.generateRandomString(5) + '_' + CONFIG_FILE_NAME, YAML.stringify(test, null), 'utf8');
console.log('---------------------------------------------------')
console.log(' Replace xxx_sync-config.yaml to sync-config.yaml');
console.log('---------------------------------------------------')
if (silent == false) {
writeFileSync(this.generateRandomString(5) + '_' + CONFIG_FILE_NAME, YAML.stringify(test, null), 'utf8');
console.log('---------------------------------------------------')
console.log(' Replace xxx_sync-config.yaml to sync-config.yaml');
console.log('---------------------------------------------------')
}
}
if (existsSync('.sync_ignore') == false) {
writeFileSync('.sync_ignore', '.sync_collections\n.sync_ignore\nsync-config.yaml\nsync-config.yml\n.sync_temp\nnode_modules\n**/node_modules\nvendor\n**/vendor\n.git\nngi-sync-*', 'utf8');
writeFileSync('.sync_ignore', '.sync_collections\n.sync_ignore\nsync-config.yaml\nsync-config.yml\n.sync_temp\nnode_modules\n**/node_modules\nvendor\n**/vendor\n.git\nngi-sync-*\n.sync_agents', 'utf8');
}
},
construct: function (cli: CliInterface) {
if (existsSync(path.resolve(".sync_collections"))) {
let currentConf = this.returnConfigModel(cli);
let questions: inquirer.QuestionCollection = [
{
type: "rawlist",
name: "action",
message: "You have sync collection config data :",
choices: [
EXIT_CONFIG_ACTION.LOAD,
EXIT_CONFIG_ACTION.NEW
// if (existsSync(path.resolve(".sync_collections"))) {
let currentConf = this.returnConfigModel(cli);
let questions: inquirer.QuestionCollection = [
{
type: "rawlist",
name: "action",
message: "You have sync collection config data :",
choices: [
EXIT_CONFIG_ACTION.LOAD,
EXIT_CONFIG_ACTION.NEW
]
}
]
inquirer.prompt(questions)['then']((answers) => {
switch (answers.action) {
case EXIT_CONFIG_ACTION.NEW:
return this.generateTemplate(false);
case EXIT_CONFIG_ACTION.LOAD:
questions = [
{
type: "input",
name: "path",
message: "Where src path your sync collections to link it?",
default: upath.normalize(homedir() + "/sync_collections")
}
]
}
]
inquirer.prompt(questions)['then']((answers) => {
switch (answers.action) {
case EXIT_CONFIG_ACTION.NEW:
return this.generateTemplate();
case EXIT_CONFIG_ACTION.LOAD:
this.generateTemplate(true);
inquirer.prompt(questions)['then']((answers) => {
this.generateTemplate(true, upath.normalize(answers.path));
setTimeout(() => {
masterData.saveData('command.load_save.data', {});
}, 1000);
return;
}
});
return;
}
})
return;
}
});
return;
// }
this.generateTemplate();
return;
},
Expand Down

0 comments on commit c7aa4ab

Please sign in to comment.