Skip to content

Instantly share code, notes, and snippets.

@toodooleedoo
Last active September 25, 2017 16:02
Show Gist options
  • Save toodooleedoo/fe0b2b83c4d5faf9ac92c82c224d506d to your computer and use it in GitHub Desktop.
Save toodooleedoo/fe0b2b83c4d5faf9ac92c82c224d506d to your computer and use it in GitHub Desktop.
node_modules

Boostrap and Simplenote Syncronization tool.

sync-notes.js will keep Simplenote and Boostrap in sync allowing you to continue using whichever app meets your needs at that time. For instance i like updating Boostnote and then editing on my Android in Simplenote or updating notes in vim. I also find nvALT to be a speady way to delete and reorganize in bulk. They each have there pros and cons for me.

sync-notes.js also comes with a couple of utility scripts like search and interactively cleanup duplicates. See instructions at the top of the script for more.

Description

While wanting to switch from a Simplenote workflow and using nvALT to Boostrap I realized a manually import was going to be too complicated so i started a utility script.

Then i realized I could use this tool to continue parts of my note taking workflow in Simplenote including Cloud Syncronization, multiple device editing and there Android app which Boostrap still lacks.

The final script is sync-notes.js and probably all you need to run. The other scripts are for reference in case you want to do some migration and changes like i did.

Instructions

Read the comment block at the top of sync-notes.js TL;DR You will have to have nvALT setup as Plain Text Storage, update storage paths and foldername from Boostnote. Then run $ node sync-notes.js sync

/*********************************************************
*
* @TITLE: Boostrap Duplicate Records
* @DESCRIPTION: Uses String Similiarity to compare note
* titles and contents to determine similiar records.
* Upon intelligently determining records which are safe
* to delete automatically if entries are close it will
* prompt you per entry if it is safe to delete.
*
* @AUTHOR: Eric Soukenka
* @DATE: April 20th 2017
*
* @NOTE: Created due to learning too late I had to restart
* Boostrap after manually editing .cson files if I was
* going to start using the application to modify entries.
*
* @NOTE: NOT YET POLISHED it was wrote during anger of
* learning I had hundreds of duplicates and regex'ing toe
* fix was too complicated.
*
********************************************************* */
var parseJson = require('parse-json');
var fs = require('fs');
var path = require('path');
var CSON = require('cson');
var crypto = require('crypto');
var stringSimilarity = require('string-similarity');
//var globals = require('globals');
var _ = require('underscore');
var query = require('cli-interact').getYesNo;
var readDir = '/Users/esouke/Boostnote/notes';
var writeDir = '/Users/esouke/Documents/Notes';
var separator = '\n=========================================================\n'
var cleanupFiles = [];
var maybeCleanupFiles = [];
files = fs.readdirSync(readDir);
/*
files = files.sort(function(a, b) {
return a < b ? -1 : 1;
})
*/
files.forEach(function(readfile) {
try {
if (path.extname(readfile) == '.cson') {
var txt = fs.readFileSync(readDir + '/' + readfile).toString();
var obj = CSON.parse(txt);
if (obj.title) {
files.forEach(readfile2 => {
var answer = false;
var txt2 = fs.readFileSync(readDir + '/' + readfile2).toString();
var obj2 = CSON.parse(txt + txt2)
if (obj2.title) {
x = stringSimilarity.compareTwoStrings(obj.title, obj2.title);
if (x > 03 && x != 1) {
y = stringSimilarity.compareTwoStrings(obj.content, obj2.content);
if (y > 0.9) {
console.log(`GOING: --------------- ${x} - ${y}`)
console.log(`OLD: ${obj.title}`);
console.log(`NEW: ${obj2.title}`);
console.log(`KEE: ${readDir}/${readfile}`)
console.log(`DEL: ${readDir}/${readfile2}`)
cleanupFiles.push(readDir + '/' + readfile2);
} else {
if (y > 0.5) {
console.log(`ASKING: ----------- ${x} - ${y}`)
console.log(`OLD: ${obj.title}`);
console.log(`NEW: ${obj2.title}`);
console.log(`KEE: ${readDir}/${readfile}`)
console.log(`DEL: ${readDir}/${readfile2}`)
maybeCleanupFiles.push(readDir + '/' + readfile2);
} else {
console.log(`SKIPPING: ${y} ${obj.title} - ${obj2.title} - ${x}`)
}
}
}
}
})
}
}
} catch (e) {
console.log(`ERROR: ${readfile}`);
}
})
for (index = 0; index < cleanupFiles.length; ++index) {
console.log(`Deleting: ${cleanupFiles[index]}`);
try {
fs.unlinkSync(cleanupFiles[index]);
} catch (e) {
console.log(`ERROR deleting: ${cleanupFiles[index]}`);
}
}
for (index = 0; index < maybeCleanupFiles.length; ++index) {
console.log("--------------------------------------");
try {
txt = fs.readFileSync(maybeCleanupFiles[index]).toString();
obj = CSON.parse(txt);
console.log(`Info: ${obj.title}`)
answer = query('delete');
if (answer) {
console.log(`Deleting: ${maybeCleanupFiles[index]}`);
try {
fs.unlinkSync(cleanupFiles[index]);
} catch (e) {
console.log(`ERROR deleting: ${cleanupFiles[index]}`);
}
} else {
console.log(`Skipping: ${maybeCleanupFiles[index]}`);
}
} catch (e) {
console.log('error');
}
}
//export.tsv
//Querybuilder search for multiple properties
{
"name": "sync-notes",
"version": "1.0.0",
"description": "Syncs Simplenote to boostnote and vice versa",
"main": "sync-notes.js",
"dependencies": {
"cli-interact": "^0.1.9",
"chokidar": "^1.6.1",
"cson": "^4.1.0",
"parse-json": "^2.2.0",
"sanitize-filename": "^1.6.1",
"string-similarity": "^1.1.0"
},
"devDependencies": {
"moment": "^2.18.1"
},
"scripts": {
"test": "node sync-notes.js sync-both"
},
"repository": {
"type": "git",
"url": "git+https://gist.github.com/fe0b2b83c4d5faf9ac92c82c224d506d.git"
},
"author": "eric soukenka",
"license": "ISC",
"bugs": {
"url": "https://gist.github.com/fe0b2b83c4d5faf9ac92c82c224d506d"
},
"homepage": "https://gist.github.com/fe0b2b83c4d5faf9ac92c82c224d506d"
}
/*********************************************************
*
* @TITLE: Simplenote and Boostrap Note Syncronization
*
* @DESCRIPTION: Supports two modes one which exports
* Boostrap notes and exports them to nvAlt .txt files.
* The other will export nvALT txt files to Boostrap .cson files
*
* @INSTRUCTIONS: Change readDir's and writeDir's at the top of
* both functions appropriately then run with no parameters for
* insrtructions.
*
* @AUTHOR: Eric Soukenka
* @DATE: April 20th 2017
*
* @NOTE: nvALT must have syncronization setting set to Plain
* Text files.
*
* @NOTE: Ensure you restart Boostrap after import to avoid
* duplicate entries.
*
* @NOTE: NOT YET POLISHED meaning it has a lot of my specific
* requirements and even the code is relatively embarrising :)
*
* !!! #################### !!!
* ####### IMPORTANT ##### !!!
* !!! Restart Boostrap after import!!!!!
*
********************************************************* */
var parseJson = require('parse-json');
var fs = require('fs');
var path = require('path');
var CSON = require('cson');
var crypto = require('crypto');
// TXT --> CSON
convertCsonToTxt = () => {
var skeleton = CSON.parseCSONFile('skeleton.cson');
var readDir = '/Users/esouke/Boostnote/notes';
var writeDir = '/Users/esouke/Documents/Notes';
var separator = '\n=========================================================\n'
fs.readdirSync(writeDir).forEach(function(file) {
if (path.extname(file) == '.txt') {
fs.unlink(writeDir + '/' + file)
}
})
files = fs.readdirSync(readDir);
filelist = [];
files.forEach(function(readfile) {
console.log(readfile)
if (path.extname(readfile) == '.cson') {
var txt = fs.readFileSync(readDir + '/' + readfile).toString();
var obj = CSON.parse(txt);
var writeFile = writeDir + '/' + obj.title + '.txt';
var writeBody = obj.content.replace(obj.title, '').replace(/\s+.*====/, '').replace(obj.title, '').replace(/^\s+|\s+$/g, '');
fs.writeFileSync(writeFile, obj.title + separator + writeBody);
}
})
console.log("IMPORTANT! Restart Boostrap if it is running!!!");
}
// CSON --> TXT
convertTxtToCson = () => {
var skeleton = CSON.parseCSONFile('skeleton.cson');
var readDir = '/Users/esouke/Documents/Notes';
var writeDir = '/Users/esouke/Boostnote/notes';
var separator = '\n=========================================================\n'
fs.readdirSync(writeDir).forEach(function(file) {
if (path.extname(file) == '.cson') {
fs.unlink(writeDir + '/' + file)
}
})
files = fs.readdirSync(readDir);
filelist = [];
files.forEach(function(readfile) {
if (path.extname(readfile) == '.txt') {
var txt = fs.readFileSync(readDir + '/' + readfile).toString();
var writeFile = writeDir + '/' + crypto.randomBytes(10).toString('hex') + '.cson';
readfile = readfile.replace(/\.[^/.]+$/, "");
skeleton.title = readfile;
var writeBody = txt.replace(readfile, '').replace(/\s+.*====/, '').replace(readfile, '').replace(/^\s+|\s+$/g, '')
skeleton.content = skeleton.title + separator + writeBody;
fs.writeFileSync(writeFile, CSON.stringify(skeleton));
skeleton.title = 'unknown';
skeleton.content = 'unknown';
}
});
}
var mode = process.argv[2];
if(mode == '-h' || mode == undefined) {
console.log('This will syncronize Boostrap and Simplenote');
console.log(`node ${process.argv[1]} simple-to-boost`);
console.log(`node ${process.argv[1]} boost-to-simple`);
} else if (mode == 'simple-to-boost') {
console.log('Syncing Simplenote to Boostrap');
convertTxtToCson();
} else if (mode == 'boost-to-simple') {
console.log('Syncing Boostrap to Simplenote');
convertCsonToTxt();
}
/*********************************************************
*
* @TITLE: Simplenote and Boostrap Note Syncronization
*
* @DESCRIPTION: Supports two modes one which exports
* Boostrap notes and exports them to nvAlt .txt files.
* The other will export nvALT txt files to Boostrap .cson files
*
* @INSTRUCTIONS: Change readDir's and writeDir's at the top of
* both functions appropriately then run with no parameters for
* insrtructions.
*
* I recommend changing the folder id in skeleton.js. It may
* even be required.
*
* @AUTHOR: Eric Soukenka
* @DATE: April 20th 2017
*
* @NOTE: nvALT must have syncronization setting set to Plain
* Text files.
*
* @NOTE: Ensure you restart Boostrap after import to avoid
* duplicate entries.
*
* @NOTE: NOT YET POLISHED meaning it has a lot of my specific
* requirements and even the code is relatively embarrising :)
*
* !!! #################### !!!
* ####### IMPORTANT ##### !!!
* !!! Restart Boostrap after import!!!!!
*
********************************************************* */
var parseJson = require('parse-json');
var fs = require('fs');
var path = require('path');
var CSON = require('cson');
var crypto = require('crypto');
var sanitize = require("sanitize-filename");
noteCounter = () => {
var csonDir = '/Users/esouke/Boostnote/notes';
var txtDir= '/Users/esouke/Documents/Notes';
var csonCount = 0;
var txtCount = 0;
fs.readdirSync(csonDir).forEach(function(readfile) {
if (path.extname(readfile) == '.cson') {
csonCount++;
}
});
fs.readdirSync(txtDir).forEach(function(readfile) {
if (path.extname(readfile) == '.txt') {
txtCount++;
}
});
console.log(`.cson = ${csonCount}`);
console.log(`.txt = ${txtCount}`);
}
// CSON --> TXT
convertCsonToTxt = () => {
var skeleton = CSON.parseCSONFile('skeleton.cson');
var readDir = '/Users/esouke/Boostnote/notes';
var writeDir = '/Users/esouke/Documents/Notes';
var separator = '\n=========================================================\n'
fs.readdirSync(writeDir).forEach(function(file) {
if (path.extname(file) == '.txt') {
fs.unlink(writeDir + '/' + file)
}
})
fs.readdirSync(readDir).forEach(function(readfile) {
if (path.extname(readfile) == '.cson') {
var txt = fs.readFileSync(readDir + '/' + readfile).toString();
var obj = CSON.parse(txt);
if(obj.title.substring(0,1) == '#') {
obj.title = obj.title.substr(1);
}
if(obj.title.substring(0,1) == ' ') {
obj.title = obj.title.substr(1);
}
if(obj.content.substring(0,1) != '#') {
obj.content = '# ' + obj.content
}
var writeFile = writeDir + '/' + obj.title + '-' + crypto.randomBytes(1).toString('hex') + '.txt';
//var writeBody = obj.content.replace(obj.title, '').replace(/\s+.*====/, '').replace(obj.title, '').replace(/^\s+|\s+$/g, '');
//fs.writeFileSync(writeFile, sanitize(obj.title + separator + writeBody));
fs.writeFileSync(writeFile, obj.content);
}
})
console.log("Finished Export from Boostrap to Simplenote Import (cson->txt)");
noteCounter();
}
// TXT --> CSON
convertTxtToCson = () => {
var skeleton = CSON.parseCSONFile('skeleton.cson');
var readDir = '/Users/esouke/Documents/Notes';
var writeDir = '/Users/esouke/Boostnote/notes';
var separator = '\n=========================================================\n'
fs.readdirSync(writeDir).forEach(function(file) {
if (path.extname(file) == '.cson') {
fs.unlink(writeDir + '/' + file)
}
})
fs.readdirSync(readDir).forEach(function(readfile) {
if (path.extname(readfile) == '.txt') {
var txt = fs.readFileSync(readDir + '/' + readfile).toString();
var writeFile = writeDir + '/' + crypto.randomBytes(10).toString('hex') + '.cson';
readfile = readfile.replace(/\.[^/.]+$/, "");
var lines = txt.split('\n');
intCounter = 0;
lines.forEach(function(line) {
if(intCounter == 0) {
skeleton.title = line.substring(1).trim();
skeleton.content = line.replace(/#(\s\s)+/,'# ') + '\n';
} else {
skeleton.content += line + '\n';
}
intCounter++;
})
fs.writeFileSync(writeFile,CSON.stringify(skeleton));
}
});
console.log("Finished Export from Simplenote to Boostnote (txt->cson)");
noteCounter();
console.log("IMPORTANT! Restart Boostrap if it is running!!!");
}
adhoc = () => {
console.log('adhoc')
var skeleton = CSON.parseCSONFile('skeleton.cson');
var readDir = '/Users/esouke/Boostnote/notes';
var writeDir = '/Users/esouke/Boostnote/notes';
var separator = '\n=========================================================\n'
fs.readdirSync(readDir).forEach(function(readfile) {
if (path.extname(readfile) == '.cson') {
var txt = fs.readFileSync(readDir + '/' + readfile).toString();
var obj = CSON.parse(txt);
obj.title = obj.title.trim();
var firstLine = obj.content.split('\n')[0];
//console.log(obj.title)
var lines = obj.content.split('\n');
obj.content = '';
intCounter = 0;
lines.forEach(function(line) {
if(intCounter == 0) {
//x = '# DTM:SSJS: test'
//console.log(x.replace(/(\s\s)+/,' ') + '\n');
obj.title = line.substring(1).trim();
obj.content = line.replace(/(\s\s)+/,' ') + '\n';
} else {
obj.content += line + '\n';
}
intCounter++;
})
console.log(writeDir + '/' + readfile)
fs.writeFileSync(writeDir + '/' + readfile,CSON.stringify(obj));
}
})
console.log("IMPORTANT! Restart Boostrap if it is running!!!");
}
var mode = process.argv[2];
if (mode == '-h' || mode == undefined) {
console.log('This will syncronize Boostrap and Simplenote');
console.log(`node ${process.argv[1]} simple-to-boost`);
console.log(`node ${process.argv[1]} boost-to-simple`);
console.log(`node ${process.argv[1]} count`);
} else if (mode == 'simple-to-boost') {
convertTxtToCson();
} else if (mode == 'boost-to-simple') {
convertCsonToTxt();
} else if (mode == 'count') {
noteCounter();
} else if (mode == 'adhoc') {
adhoc();
}
/*********************************************************
*
* @TITLE: Simplenote and Boostrap Note Syncronization
*
* @DESCRIPTION: Keeps Simplenote and Boostnote insync
*
* @INSTRUCTIONS:
* - Set Resophnotes to save as Plain Text.
* - Change csonDir and txtDir accordingly
* - Change csonObj.folder = '94b8c2e8acf3448698d7' with
* foldername determined by a sample cson on your system.
* - Run npm install
*
* Run in sync mode and make changes and watch output.
*
* You can run duplicates mode which will use
* formulas to determine duplicate Boostnote notes and
* ask if you want to delete.
*
* counter mode just shows how many notes each application has
*
*
* @TODO:
* - Allow adding of new txt notes without restart of program
* - Remove resophnotes dependency by using Simplenote directly.
* - Cleanup duplicate reduntant code
*
* !!!WARNING!!! Boostrap stores references and notes in memory
* after making external changes you should do a cmd+r to reload
* boostrap or you may encounter note loss and/or duplication.
*
* @AUTHOR: Eric Soukenka
* @DATE: April 20th 2017
*
********************************************************* */
var parseJson = require('parse-json');
var fs = require('fs');
var path = require('path');
var CSON = require('cson');
var crypto = require('crypto');
var sanitize = require("sanitize-filename");
var chokidar = require('chokidar');
var stringSimilarity = require('string-similarity');
var query = require('cli-interact').getYesNo;
var readlineSync = require('readline-sync');
var exec = require("child_process").exec
var spawn = require("child_process").spawn
var moment = require("moment")
duplicates = () => {
noteCounter();
dupCounter = 0;
answer = '';
fs.readdirSync(csonDir).forEach(function(csonFile1) {
if (path.extname(csonFile1) == '.cson') {
status = 'false';
try {
csonObj1 = CSON.parse(fs.readFileSync(csonDir + '/' + csonFile1).toString());
loop = true;
fs.readdirSync(csonDir).forEach(function(csonFile2) {
if (loop) {
if (path.extname(csonFile2) == '.cson') {
csonObj2 = CSON.parse(fs.readFileSync(csonDir + '/' + csonFile2).toString());
x = stringSimilarity.compareTwoStrings(csonObj1.content, csonObj2.content);
if (x > 0.9) {
if (status == 'false') {
status = 'checking';
} else if (status = 'checking') {
status = 'duplicate';
if (answer != 'a') {
answer = readlineSync.question(`Rating: ${x}\n(1) ${csonObj1.title}\n(2) ${csonObj2.title}\n(3) skip\n(a) all\n(l) log\nChoose 1 | 2 | 3 | a | l\n`);
}
if (answer == 1) {
fs.unlink(`${csonDir}/${csonFile1}`);
console.log(`DELETING: ${csonDir}/${csonFile1} ${csonObj1.title}`);
} else if (answer == 2) {
fs.unlink(`${csonDir}/${csonFile2}`);
console.log(`DELETING: ${csonDir}/${csonFile2} ${csonObj2.title}`);
} else if (answer == 3) {
console.log(`SKIPPING`);
} else if (answer == 'a') {
console.log(`DELETING: ${csonDir}/${csonFile2} ${csonObj2.title}`);
fs.unlink(`${csonDir}/${csonFile2}`);
} else if (answer == 'l') {
console.log(`LOGGING: ${csonDir}/${csonFile2} ${csonObj2.title}`);
}
loop = false;
dupCounter++;
}
}
}
}
})
} catch (e) {
console.log('ERROR');
}
}
})
console.log(`Duplicates: ${dupCounter}`)
noteCounter();
}
similiar = (file) => {
if (path.extname(file) == '.cson' && fs.existsSync(file)) {
status = 'new';
csonObj = CSON.parse(fs.readFileSync(file).toString());
fs.readdirSync(txtDir).forEach(function(txtFile) {
if (path.extname(txtFile) == '.txt') {
txtContent = fs.readFileSync(txtDir + '/' + txtFile).toString()
x = stringSimilarity.compareTwoStrings(csonObj.content, txtContent);
if (x > 0.9) {
if (status == 'new') {
status = 'existing';
} else if (status = 'existing') {
console.log(`DUPLICATE: "${csonObj.title.trim()}" "${txtContent.split('\n')[0]}" - ${x}`);
}
}
}
})
}
}
processor = (file) => {
if (path.extname(file) == '.cson') {
readFile = path.basename(file);
filename = readFile.replace(/\.[^/.]+$/, "");
writeFile = txtDir + '/' + filename + '.txt';
csonObj = CSON.parse(fs.readFileSync(file).toString())
if(csonObj.content) {
if (fs.existsSync(writeFile)) {
if (fs.readFileSync(writeFile).toString().trim() != csonObj.content.trim()) {
console.log(`MODIFED: cson ${csonObj.title.trim()}`)
fs.writeFileSync(writeFile, csonObj.content.trim() + '\n');
}
} else {
console.log(`ADDED: cson ${csonObj.title.trim()}`)
fs.writeFileSync(writeFile, csonObj.content.trim() + '\n');
}
} else {
console.log(`ERROR: ${file} does not have content and we do not support snippets yet2`)
}
}
if (path.extname(file) == '.txt') {
readFile = path.basename(file);
filename = readFile.replace(/\.[^/.]+$/, "");
writeFile = csonDir + '/' + filename + '.cson';
if (fs.existsSync(writeFile)) {
csonObj = CSON.parse(fs.readFileSync(writeFile).toString())
if (fs.readFileSync(file).toString().trim() != csonObj.content.trim()) {
csonObj.content = fs.readFileSync(file).toString().trim()
csonObj.title = fs.readFileSync(file).toString().trim().split('\n')[0] + '\n';
csonObj.updatedAt = moment().toISOString()
if (csonObj.title.substring(0, 1) == '#') {
csonObj.title = csonObj.title.substring(1)
}
console.log(`MODIFIED: txt ${fs.readFileSync(file).toString().trim().split('\n')[0]}`);
fs.writeFileSync(writeFile, CSON.stringify(csonObj));
}
} else {
console.log(`SKIPPING: NEW NOTE: ${writeFile}`);
console.log(`NOTE: will be created upon restart of this program`);
}
}
}
noteCounter = () => {
var csonCount = 0;
var txtCount = 0;
fs.readdirSync(csonDir).forEach(function(readfile) {
if (path.extname(readfile) == '.cson') {
csonCount++;
}
});
fs.readdirSync(txtDir).forEach(function(readfile2) {
if (path.extname(readfile2) == '.txt') {
txtCount++;
}
});
console.log(`COUNTER: Boostnote: ${csonCount}`);
console.log(`COUNTER: Simplenote: ${txtCount}`);
}
clean = () => {
noteCounter();
console.log("Running clean mode to ensure clean start");
fs.readdirSync(txtDir).forEach(function(readfile) {
filename = readfile.split('.').shift()
extension = readfile.split('.').pop()
if (extension == 'txt') {
if (!fs.existsSync(csonDir + '/' + filename + '.cson')) {
csonObj = {}
csonObj.type = 'MARKDOWN_NOTE'
csonObj.folder = '94b8c2e8acf3448698d7'
csonObj.tags = []
csonObj.isStarred = false
csonObj.createdAt = moment().toISOString()
csonObj.updatedAt = moment().toISOString()
csonObj.title = fs.readFileSync(txtDir + '/' + readfile).toString().trim().split('\n')[0];
csonObj.content = fs.readFileSync(txtDir + '/' + readfile).toString().trim();
if(csonObj.title && csonObj.content) {
filename = crypto.randomBytes(10).toString('hex');
writeFile = csonDir + '/' + filename + '.cson';
fs.writeFileSync(writeFile, CSON.stringify(csonObj))
fs.renameSync(txtDir + '/' + readfile, txtDir + '/' + filename + '.txt');
console.log(`WROTE: ${writeFile} - ${csonObj.title}`);
console.log(`RENAMED: ${txtDir + '/' + readfile} --> ${txtDir + '/' + filename + '.txt'}`);
} else {
fs.unlink(`${txtDir}/${readfile}`);
console.log(`Removed invalid/empty note found at ${txtDir}/${readfile}`);
}
}
}
});
fs.readdirSync(csonDir).forEach(function(readfile) {
filename = readfile.split('.').shift()
extension = readfile.split('.').pop()
if (extension == 'cson') {
if (!fs.existsSync(txtDir + '/' + filename + '.txt')) {
csonObj = CSON.parse(fs.readFileSync(csonDir + '/' + readfile))
if(csonObj.content) {
writeFile = txtDir + '/' + filename + '.txt';
fs.writeFileSync(writeFile, csonObj.content.trim() + '\n');
console.log(`WROTE: ${writeFile} - ${csonObj.title}`);
} else {
console.log(`ERROR: ${csonDir}/${readfile} does not have content and we do not support snippets yet`)
}
}
}
});
noteCounter();
}
var mode = process.argv[2];
var txtDir = '/Users/esouke/Documents/Notes';
var csonDir = '/Users/esouke/Boostnote/notes';
if (mode == '-h' || mode == undefined) {
console.log('This will syncronize Boostrap and Simplenote');
console.log(`node ${process.argv[1]} sync`);
console.log(`node ${process.argv[1]} duplicates`);
console.log(`node ${process.argv[1]} counter`);
console.log(`node ${process.argv[1]} clean`);
} else if (mode == 'counter') {
noteCounter();
} else if (mode == 'clean') {
clean();
} else if (mode == 'duplicates') {
duplicates();
} else if (mode == 'sync') {
//boost-to-simple
csonWatcherReady = false;
//var csonWatcher = chokidar.watch(csonDir).on('all', (event, path) => {
var csonWatcher = chokidar.watch(csonDir, {
alwaysState: true,
awaitWriteFinish: {
stabilityThreshold: 5000,
pollInterval: 100
},
}).on('all', (event, path) => {
if (csonWatcherReady) {
noteCounter();
similiar(path);
}
if (event != 'unlink') {
processor(path)
} else {
filename = path.replace(/.*\//, '');
filename = filename.replace(/\.[^/.]+$/, "");
filename = txtDir + '/' + filename + '.txt'
if (fs.existsSync(filename)) {
console.log(`DELETING: ${fs.readFileSync(filename).toString().trim().split('\n')[0]}`);
fs.unlink(filename);
}
}
});
csonWatcher.on('ready', () => csonWatcherReady = true);
//end boost-to-simple
//simple-to-boost
txtWatcherReady = false;
var txtWatcher = chokidar.watch(txtDir, {
alwaysState: true,
awaitWriteFinish: {
stabilityThreshold: 2000,
pollInterval: 100
},
}).on('all', (event, path) => {
if (txtWatcherReady) {
similiar(path);
noteCounter();
}
if (event != 'unlink') {
processor(path)
} else {
filename = path.replace(/.*\//, '');
filename = filename.replace(/\.[^/.]+$/, "");
filename = csonDir + '/' + filename + '.cson'
if (fs.existsSync(filename)) {
console.log(`DELETING: ${filename}`);
fs.unlink(filename);
}
}
});
txtWatcher.on('ready', () => txtWatcherReady = true);
//end simple-to-boost
clean();
console.log(`Watching ${txtDir} and ${csonDir}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment