Skip to content

Instantly share code, notes, and snippets.

@juliantheberge
Created May 3, 2018 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliantheberge/afbd60429b0f4fad2803ecd61b3e7f72 to your computer and use it in GitHub Desktop.
Save juliantheberge/afbd60429b0f4fad2803ecd61b3e7f72 to your computer and use it in GitHub Desktop.
// concatinates file names
function stringOfFiles(dir:string, array:[string], version:number, rev:boolean) {
let finalArr = [];
if (rev) {
for (let i = array.length-1; i >= version;i--) {
finalArr.push("-f " + dir + '/' + array[i])
}
return " -a " + finalArr.join(' ')
} else {
for (let i = 0; i < version;i++) {
finalArr.push("-f " + dir + '/' + array[i])
}
return " -a " + finalArr.join(' ')
}
}
// this function is called in this section of the db build script
...
func.filesInDir('./database-builds/up', function(err:Error, files:[string]){
if (err) {
console.log(err)
} else {
let fileString = func.stringOfFiles('./database-builds/up', files, result.version, false);
console.log(fileString);
func.childProcess(dbConnect + fileString, function(err:Error, stdout:string, stderr:string) {
if (err) {
console.error(`exec error: ${err}`);
cb(err);
} else {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
console.log('tables added');
func.makeJSONfromObj('./sdist/config/connect-config.json', jsonConfig, function(err:string) { // store that information in a JSON
if(err) {
console.log(err)
cb(err);
} else {
console.log('successfuly made config JSON')
cb();
}
});
}
})
}
})
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment