*: docs
add some jsdoc
This commit is contained in:
parent
a9571b7ca5
commit
a5c2d158a2
2 changed files with 78 additions and 37 deletions
97
extension.js
97
extension.js
|
@ -27,6 +27,57 @@ function activate(context) {
|
||||||
|
|
||||||
|
|
||||||
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenCurrentWeek', function () {
|
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenCurrentWeek', function () {
|
||||||
|
try {
|
||||||
|
var basedir = getBasedir();
|
||||||
|
} catch(e) {
|
||||||
|
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var notepath = basedir +"/"+ currentWeekFilename();
|
||||||
|
|
||||||
|
openNote(notepath);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
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"];
|
var basedir = process.env["NOTEDIR"];
|
||||||
|
|
||||||
if (!basedir) {
|
if (!basedir) {
|
||||||
|
@ -40,40 +91,36 @@ function activate(context) {
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(basedir);
|
fs.mkdirSync(basedir);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
|
throw(e);
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return basedir;
|
||||||
|
}
|
||||||
|
|
||||||
var notepath = basedir +"/"+ currentWeekFilename();
|
/**
|
||||||
fs.access(notepath, fs.constants.R_OK | fs.constants.W_OK, (err) => {
|
* get the markdown style heading for the current datetime stamp
|
||||||
if (err) {
|
*
|
||||||
try {
|
* @returns {String} (i.e. `## ...`)
|
||||||
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;
|
|
||||||
|
|
||||||
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();
|
||||||
|
@ -83,9 +130,3 @@ 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