Skip to content

hrithikgautham/gitmon-npm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gitmon

Simple way to make your folders look like .git/objects folder.

USAGE:

const { folderize, gittify } = require('gitmon');
const path = require('path');
const targetFolder = path.join(__dirname, "new-folder");
/* path.join() is necessary here(because you need to specify __dirname) */
const srcFolder = path.join(__dirname, 'src-folder');
/*absolute path from root folder.*/
/* srcFolder can also be an array*/
const numOfChars = 2;
const HALG = 'sha256';
const deleteSrc = true;
const ext = '.txt';

async function func() {
await folderize(targetFolder);
/*create folder*/
await gittify(targetFolder,
{
srcFolder,
numOfChars,
HALG,
deleteSrc,
ext
});
}
/*arrange the files similar to .git/objects folder*/
func();

Explanation:

  • First things first! Import the module.
  • The parameter to the folderize function is a string, specifying the name target folder to be generated.
  • folderize just creates a folder.
  • In the above code, path module is used to create path string.
  • Now, srcFolder has the required files which has to be converted to .git/objects folder.
  • srcFolder can also have nested folders. Only the files will be considered. i.e; all the files, no matter how deep they are in srcFolder, will be considered.
  • srcFolder can also be an Array, instead of source folder path;
  • numOfChars is an interger, which indicates the number of characters from which the folder in targetFolder has to be named from the hash of the contents of each file in srcFolder.
  • The remaining characters in the hash, i.e, ((size-of-hash) - numOfChars) remaining charaters of the hash is used to name the file, whose hash is used to name the folder and the file.
  • ext is the extension of the target file.
  • HALG is a string specifying the Hashing Algorithm to be used in the process.
  • E.g, if the srcFolder/sample.txt is the file you wish to use. Let the hash of the contents of the file be "abcded639ecb4a3ac95389bbdf05c434e4df5534"(sha1), then a folder named "ab" will be generated in targetFolder, and the rest of the characters of the hash, i.e, "cded639ecb4a3ac95389bbdf05c434e4df5534" will be the name of the file with ext extension. To summarise, a file named "cded639ecb4a3ac95389bbdf05c434e4df5534" with extension ext can be found in targetFolder/ab.Hence, the relative path to the file from your working directory is targetFolder/ab/cded639ecb4a3ac95389bbdf05c434e4df5534.ext.
  • In the above example numOfChars is chosen to be 2, thats why the folder is just named with only 2 characters ab.
  • If deleteSrc is true, then srcFolder will be deleted after conversion (files inside srcFolder will also be deleted), else the files and srcFolder remains untouched.

Constraints:

HALG (string) can take values which can be found in ['sha1', 'sha256', 'sha512'].
ext (string) can take values which can be found in ['.json', '.txt', ""].
numOfChars is an integer.
deleteSrc is a boolean.
srcFolder and targetFolder must include __dirname in path.join().

THANK YOU!

For more info, visit github repo.

About

A way to create .git/objects like folders.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published