This repository has been archived by the owner on Feb 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from janithcooray/sync-change
Sync change
- Loading branch information
Showing
17 changed files
with
877 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} | ||
} |
Oops, something went wrong.