Last active
September 19, 2023 14:50
-
-
Save autotel/703d33f8704e9d34f7587713ad60683d to your computer and use it in GitHub Desktop.
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
const { readdirSync, readdir, stat, statSync, rm, rmSync, readFileSync, renameSync, copyFileSync } = require("fs"); | |
const path = require("path"); | |
const process = require("process"); | |
const projectsPath = path.resolve("./PRESETS MKII"); | |
const confirm = async (question) => { | |
console.log(question, `type "yes" or "no"`); | |
return new Promise((resolve, reject) => process.stdin.once('data', data => { | |
if(data[0] === "y".charCodeAt(0)){ | |
resolve(true); | |
} | |
resolve(false); | |
})) | |
} | |
/** | |
* @typedef {string} ReloadableProject | |
*/ | |
/** | |
* @returns {Promise<Array<ReloadableProject>>} | |
*/ | |
const getReloadableProjects = async() => { | |
const projects = readdirSync(projectsPath); | |
return projects.filter((dir)=>{ | |
const pPath = path.resolve(projectsPath,dir); | |
const isFolder = statSync(pPath).isDirectory; | |
// I have my own idiosyncratic way of organizing projects, here you have to customize which | |
// project names need to be prevented from reloading | |
const isIdea = dir.match(/\bidea/i); | |
if(isIdea) return false; | |
const isSketch = dir.match(/\bPROJECT/i); | |
if(isSketch) return false; | |
if(isFolder){ | |
const containsStrdFiles = readdirSync(pPath).find((fname)=>{ | |
return fname.split(/\./gi).pop() === "strd"; | |
}); | |
if(containsStrdFiles){ | |
console.log(`path ${dir} is reloadable.`); | |
}else{ | |
console.log(`path ${dir} is not reloadable.`); | |
} | |
return containsStrdFiles; | |
} | |
return false; | |
}); | |
} | |
/** | |
* @param {ReloadableProject} dir | |
*/ | |
const reloadProject = async (dir) => { | |
console.log(`project ${dir}`); | |
const pPath = path.resolve(projectsPath,dir); | |
readdirSync(pPath).forEach((fname)=>{ | |
console.log(` file ${fname}`); | |
const { | |
ext, name | |
} = path.parse(fname); | |
const basename = name; | |
let fullPath = path.resolve(projectsPath,dir,fname); | |
let basenamePath = path.resolve(projectsPath,dir,basename); | |
if(ext===".strd"){ | |
console.log(` Rename + replace ${fname} >> ${basename}.work`); | |
copyFileSync(fullPath,basenamePath+".work"); | |
} | |
}); | |
} | |
const runtime = async () => { | |
const reloadable = await getReloadableProjects(); | |
console.log("\n\n-----------------\nwould reload the following projects:"); | |
console.log(reloadable.join('\n')); | |
let make = await confirm("did you backup the octatrack projects?").catch((string) => { | |
console.log(string); | |
}) | |
if(make) make &= await confirm("are you sure?").catch((string) => { | |
console.log(string); | |
}); | |
if (!make) return; | |
reloadable.forEach(reloadProject); | |
console.log(reloadable); | |
console.log("Reload ready!"); | |
} | |
runtime().then(() => { | |
console.log("finished"); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment