Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Sync change #8

Merged
merged 29 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1ed7b81
adding new features to compose
janithcooray Jun 28, 2022
5c83fed
adding yml support
janithcooray Jun 28, 2022
b46c9b4
adding yml support
janithcooray Jun 28, 2022
bed4c39
adding yml support
janithcooray Jun 28, 2022
6fde05b
adding yml support
janithcooray Jun 28, 2022
36dde24
adding yml support
janithcooray Jun 28, 2022
deef162
adding yml support
janithcooray Jun 28, 2022
d3a1d14
adding yml support
janithcooray Jun 28, 2022
d14a431
adding yml support
janithcooray Jun 28, 2022
2290861
adding yml support
janithcooray Jun 28, 2022
684d01d
adding yml support
janithcooray Jun 28, 2022
e19cac3
adding yml support
janithcooray Jun 28, 2022
1a15d9d
adding yml support
janithcooray Jun 28, 2022
11bf611
yml build
janithcooray Jun 29, 2022
1dea5d8
yml build
janithcooray Jun 29, 2022
4e34664
yml build - containers listing
janithcooray Jun 29, 2022
f466324
yml build - containers listing
janithcooray Jun 29, 2022
5549772
yml build - containers listing
janithcooray Jun 29, 2022
89a9cdc
yml build - containers listing
janithcooray Jun 29, 2022
49e1f7a
yml build - containers listing
janithcooray Jun 29, 2022
9063fd5
yml build - containers & volume listding functional
janithcooray Jun 29, 2022
1bd3049
yml build - containers & volume listding functional
janithcooray Jun 29, 2022
f1942ec
yml build - containers & volume listding functional
janithcooray Jun 29, 2022
f147f1e
yml build - containers & volume listding functional
janithcooray Jun 29, 2022
d3cee52
yml build - containers & volume listding functional
janithcooray Jun 29, 2022
a8396bb
yml build sync funational
janithcooray Jun 29, 2022
aae4b3a
webupdate
janithcooray Jun 29, 2022
c5be926
webupdate
janithcooray Jun 29, 2022
50bc2be
working yaml
janithcooray Jun 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /usr/bin/env node
import Init from "../src/init.js";
new Init();
6 changes: 0 additions & 6 deletions index.js

This file was deleted.

494 changes: 493 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"main": "./bin/index.js",
"bin": {
"syncstat": "./bin/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/janithcooray/sync-stat.git"
Expand All @@ -16,7 +19,9 @@
"homepage": "https://sync-stat.nova64.xyz/",
"dependencies": {
"chokidar": "^3.5.3",
"stdio": "^2.1.1"
"js-yaml": "^4.1.0",
"stdio": "^2.1.1",
"yargs": "^17.5.1"
},
"scripts": {
"test": "node index -m test"
Expand Down
44 changes: 44 additions & 0 deletions src/abstract/ymlVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { default as Log } from "./log.js";

export default class YamlVersion extends Log {

constructor(context){
super();
this.yml = context.yml;
this.context = context;
}


/**
* will Throw an error if version is below expected
*/
checkCompatibility(){
//if (this.version > context.version) {
// this.output("ignoring error - " + this.issueMessage)
// }
}

/**
* Some Yaml functions will be limited to versions
*/
setMinVersion(version){
this.version = version;
}

getMinVersion(){
return this.version;
}

/**
* set Version Incompatibility Issue
* @param {*} text
*/
whenOnIncompatible(text){
this.issueMessage = text;
}

onIncompatible(){
return this.issueMessage;
}

}
88 changes: 28 additions & 60 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs';
import { default as stdio } from 'stdio';
import Log from "./abstract/log.js";
import Convert from './convert.js';
import ProcessLinkYml from './processYML.js';
import Sync from './sync.js';

export default class Init extends Log {
Expand All @@ -10,79 +11,46 @@ export default class Init extends Log {
/**
* Add init
*/
let ops = stdio.getopt({
'mode': {key: 'm', args: 1, description: ' GCS or Local??',required: true, default : ["run"]},
});

const args_ = process.argv.slice(2);

switch (ops.mode) {
switch (args_[0]) {
case "run":
let volumes = this.getAllVolumes();
this.assignSync(volumes);
new ProcessLinkYml();
break;
case "install":
case "convert":
new Convert();
break;
case "test":
this.output("OK")
this.output("OK");
case "help":
this.help()
case "--help":
this.help()
case "-h":
this.help()
break;
case null:
this.output("Missing Command!");
this.help()
default:
this.output(`Unknown Command "${args_[0]}"`);
this.help()
break;
}



}

/**
* retuns the state of
*
* Is it the first time this is running
*/
getState = () => {
return JSON.parse(fs.readFileSync( this.getProjectRoot() +'/package.json', 'utf8'));
}

//parse Convertdata
getCompose = () => {
return JSON.parse(fs.readFileSync( this.getProjectRoot() +'/sync-compose.json', 'utf8'));
};

getContainers = (compose) =>{
let containers = []
Object.entries(compose).forEach(([key, value]) => {
containers.push(key);
});
return containers;
};

getVolumesAttached = (compose,container) => {
let volumes = [];
Object.entries(compose[container].volumes).forEach(element => {
volumes.push(element);
});
return volumes;
};
help(){
this.output(
`Commands: [Option] <ARG1> <ARG2> ...

getAllVolumes = () => {
let compose = this.getCompose()["containers"];
let containers = this.getContainers(compose);
run - run sync compose
help,-h , --help - display this help message
convert - convert an existing docker-compose.yml
version - Display Version

let allVolumes = [];
containers.forEach(element => {
let container = element;
let volumes = this.getVolumesAttached(compose,container);
volumes.forEach(vols => {
allVolumes.push([ container,vols[0], vols[1]]);
});
});
return allVolumes;
};
`);
}

assignSync = (volumes) => {
volumes.forEach(element => {
this.output(`in ${element[0]} from ${element[2]} to ${element[1]}`);
//let sync = new Sync(element[0],element[1],element[2]);
//sync.startSync();
});
};

}
19 changes: 19 additions & 0 deletions src/process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* ProccessAction
*
* Will decide if the project uses JSON verion or YAML version
*/
import Log from "./abstract/log.js";
import ProcessJSON from "./processJSON.js";

export default class ProccessAction extends Log {

constructor(){
/**
* For now Only JSON version Will work
*/
let ProccessJSON =new ProcessJSON();
let volumes = ProccessJSON.getAllVolumes();
ProccessJSON.assignSync(volumes);
}
}
56 changes: 56 additions & 0 deletions src/processJSON.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Log from "./abstract/log.js";

export default class ProcessJSON extends Log {
/**
* retuns the state of
*
* Is it the first time this is running
*/
getState = () => {
return JSON.parse(fs.readFileSync( this.getProjectRoot() +'/package.json', 'utf8'));
}

//parse Convertdata
getCompose = () => {
return JSON.parse(fs.readFileSync( this.getProjectRoot() +'/sync-compose.json', 'utf8'));
};

getContainers = (compose) =>{
let containers = []
Object.entries(compose).forEach(([key, value]) => {
containers.push(key);
});
return containers;
};

getVolumesAttached = (compose,container) => {
let volumes = [];
Object.entries(compose[container].volumes).forEach(element => {
volumes.push(element);
});
return volumes;
};

getAllVolumes = () => {
let compose = this.getCompose()["containers"];
let containers = this.getContainers(compose);

let allVolumes = [];
containers.forEach(element => {
let container = element;
let volumes = this.getVolumesAttached(compose,container);
volumes.forEach(vols => {
allVolumes.push([ container,vols[0], vols[1]]);
});
});
return allVolumes;
};

assignSync = (volumes) => {
volumes.forEach(element => {
this.output(`in ${element[0]} from ${element[2]} to ${element[1]}`);
//let sync = new Sync(element[0],element[1],element[2]);
//sync.startSync();
});
};
}
13 changes: 13 additions & 0 deletions src/processYML.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Process YML file
*/
import Log from "./abstract/log.js";
import yaml from "js-yaml";
import ProcessYML from "./ymlProcess/yamlProcess.js";
export default class ProcessLinkYml extends Log {

constructor(){
super();
new ProcessYML();
}
}
22 changes: 22 additions & 0 deletions src/ymlProcess/getContainers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import YamlVersion from "../abstract/ymlVersion.js";

export default class GetContainers extends YamlVersion {

constructor(context){
super(context);
this.setMinVersion(1);
this.whenOnIncompatible("Cannot be under version 1, Please Update sync-compose");
this.checkCompatibility();

return this.getContainersFunction();
}

getContainersFunction = () => {
let containers = [];
this.yml.containers.forEach((key) => {
containers.push(key);
});
return containers;
}

}
27 changes: 27 additions & 0 deletions src/ymlProcess/getVolumes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import YamlVersion from "../abstract/ymlVersion.js";
import VolumeInfo from "./volumeData.js";

export default class getVolumes extends YamlVersion{

constructor(context){
super(context);
this.setMinVersion(1);
this.whenOnIncompatible("Cannot be under version 1, Please Update sync-compose");
this.checkCompatibility();

//return this.getVolumesFunction();
}

getVolumesFunction = (container) => {
let volumes = []

Object.entries(container).forEach(([key, value]) => {
Object.entries(value.volumes).forEach(([id, volume]) => {
volumes.push(new VolumeInfo({container: key,id: id, volume}));
});
});

return volumes;
}

}
27 changes: 27 additions & 0 deletions src/ymlProcess/loadYML.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import yaml from "js-yaml";
import fs from 'fs';
import Log from "../abstract/log.js";

export default class LoadYML extends Log {

constructor(){
super();
return this.getYML();
}

/**
*
* @returns yml data
*/
getYML(){
return yaml.load(this.getCompose());
}

/**
*
* @returns sync-compose.yml
*/
getCompose = () => {
return fs.readFileSync( this.getProjectRoot() +'/sync-compose.yml', 'utf8');
};
}
25 changes: 25 additions & 0 deletions src/ymlProcess/volumeData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default class VolumeInfo {
constructor(object){
return this.parse(object);
}

parse(object){
let volumeInfo = object.volume.volume;
volumeInfo.id = object.id;
volumeInfo.container = object.container;
return this.convert(volumeInfo);
}

convert(object){
this.container = object.container;
this.volumeId = object.id;
this.from= object.from,
this.to= object.to,
this.mode = object.mode,
this.owner = object.owner,
this.cmd = object.cmd,
this.ignore = object.ignore,
this.replace = object.replace

}
}
Loading