*: docs
add some jsdoc
This commit is contained in:
parent
a9571b7ca5
commit
a5c2d158a2
2 changed files with 78 additions and 37 deletions
113
extension.js
113
extension.js
|
@ -27,53 +27,100 @@ function activate(context) {
|
||||||
|
|
||||||
|
|
||||||
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenCurrentWeek', function () {
|
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenCurrentWeek', function () {
|
||||||
var basedir = process.env["NOTEDIR"];
|
|
||||||
|
|
||||||
if (!basedir) {
|
|
||||||
basedir = process.env["HOME"]+"/Notes";
|
|
||||||
console.log("next-note: no basedir. Using "+basedir);
|
|
||||||
console.log("next-note: set NOTEDIR to use a diferent basedir");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
fs.statSync(basedir);
|
var basedir = getBasedir();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
try {
|
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
|
||||||
fs.mkdirSync(basedir);
|
return;
|
||||||
} catch(e) {
|
|
||||||
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var notepath = basedir +"/"+ currentWeekFilename();
|
var notepath = basedir +"/"+ currentWeekFilename();
|
||||||
fs.access(notepath, fs.constants.R_OK | fs.constants.W_OK, (err) => {
|
|
||||||
if (err) {
|
openNote(notepath);
|
||||||
try {
|
|
||||||
fs.writeFileSync(notepath, dateLine());
|
|
||||||
} catch (e) {
|
|
||||||
vscode.window.showErrorMessage("next-note: failed to create "+ notepath);
|
|
||||||
console.error(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
vscode.workspace.openTextDocument(notepath).then(doc => {
|
|
||||||
vscode.window.showTextDocument(doc);
|
|
||||||
vscode.window.activeTextEditor.selection.active.line += 1;
|
|
||||||
});
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
exports.activate = activate;
|
exports.activate = activate;
|
||||||
|
|
||||||
|
|
||||||
|
// this method is called when your extension is deactivated
|
||||||
|
function deactivate() {
|
||||||
|
console.log("next-note: deactivated")
|
||||||
|
}
|
||||||
|
exports.deactivate = deactivate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* opens filepath in the current window, creating the file if needed
|
||||||
|
*
|
||||||
|
* @param {String} filepath is the path of the new note file
|
||||||
|
* @return {undefined}
|
||||||
|
*/
|
||||||
|
function openNote(filepath) {
|
||||||
|
fs.access(filepath, fs.constants.R_OK | fs.constants.W_OK, (err) => {
|
||||||
|
if (err) {
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(filepath, dateLine());
|
||||||
|
} catch (e) {
|
||||||
|
vscode.window.showErrorMessage("next-note: failed to create "+ filepath);
|
||||||
|
console.error(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
vscode.workspace.openTextDocument(filepath).then(doc => {
|
||||||
|
vscode.window.showTextDocument(doc);
|
||||||
|
vscode.window.activeTextEditor.selection.active.line += 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return a best guess at the directory path to store notes in
|
||||||
|
*
|
||||||
|
* @returns {String}
|
||||||
|
*/
|
||||||
|
function getBasedir() {
|
||||||
|
var basedir = process.env["NOTEDIR"];
|
||||||
|
|
||||||
|
if (!basedir) {
|
||||||
|
basedir = process.env["HOME"]+"/Notes";
|
||||||
|
console.log("next-note: no basedir. Using "+basedir);
|
||||||
|
console.log("next-note: set NOTEDIR to use a diferent basedir");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
fs.statSync(basedir);
|
||||||
|
} catch(e) {
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(basedir);
|
||||||
|
} catch(e) {
|
||||||
|
throw(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return basedir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the markdown style heading for the current datetime stamp
|
||||||
|
*
|
||||||
|
* @returns {String} (i.e. `## ...`)
|
||||||
|
*/
|
||||||
function dateLine() {
|
function dateLine() {
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
return "## "+ dateFormat(d,"ddd mmm dd HH:MM:ss Z yyyy") +"\n";
|
return "## "+ dateFormat(d,"ddd mmm dd HH:MM:ss Z yyyy") +"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the base file name of the current week
|
||||||
|
*
|
||||||
|
* @returns {String} (i.e. "Tasks-20170219-20170225.md")
|
||||||
|
*/
|
||||||
function currentWeekFilename() {
|
function currentWeekFilename() {
|
||||||
return "Tasks-"+currentWeek()+".md";
|
return "Tasks-"+currentWeek()+".md";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the string of the current week's date, sunday-saturday
|
||||||
|
*
|
||||||
|
* @return {String} (i.e. "20170219-20170225")
|
||||||
|
*/
|
||||||
function currentWeek() {
|
function currentWeek() {
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
var beginDate = new Date();
|
var beginDate = new Date();
|
||||||
|
@ -82,10 +129,4 @@ function currentWeek() {
|
||||||
|
|
||||||
return dateFormat(beginDate, "yyyymmdd")+"-"+dateFormat(d,"yyyymmdd");
|
return dateFormat(beginDate, "yyyymmdd")+"-"+dateFormat(d,"yyyymmdd");
|
||||||
//return String(beginDate.getFullYear())+String(beginDate.getMonth())+String(beginDate.getDate()) +"-"+ String(d.getFullYear())+String(d.getMonth())+String(d.getDate());
|
//return String(beginDate.getFullYear())+String(beginDate.getMonth())+String(beginDate.getDate()) +"-"+ String(d.getFullYear())+String(d.getMonth())+String(d.getDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
// this method is called when your extension is deactivated
|
|
||||||
function deactivate() {
|
|
||||||
console.log("next-note: deactivated")
|
|
||||||
}
|
|
||||||
exports.deactivate = deactivate;
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "next-note",
|
"name": "next-note",
|
||||||
"displayName": "next-note",
|
"displayName": "next-note",
|
||||||
"description": "Helpers for daily notes",
|
"description": "Helpers for daily notes",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"publisher": "vbatts",
|
"publisher": "vbatts",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
Loading…
Reference in a new issue