grunt-toggl
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -57,18 +57,11 @@ /* | ||
options: { | ||
settingsFile: 'test/fixtures/valid' | ||
settingsFile: 'test/fixtures/valid', | ||
apiEnvVar: 'TOGGL_API_KEY' | ||
}, | ||
}, | ||
localSettingsFile: { | ||
options: { | ||
settingsFile: ".toggl", // this is .gitignored | ||
data: { | ||
description: 'TEST ENTRY' | ||
} | ||
}, | ||
}, | ||
localSettingsFileWithProject: { | ||
options: { | ||
settingsFile: ".toggl", // this is .gitignored | ||
settingsFile: 'test/fixtures/valid', | ||
apiEnvVar: 'TOGGL_API_KEY', | ||
project: 3337246, | ||
@@ -94,3 +87,4 @@ data: { | ||
options: { | ||
settingsFile: 'missing' | ||
settingsFile: 'missing', | ||
apiEnvVar: 'TOGGL_API_KEY' | ||
}, | ||
@@ -111,9 +105,2 @@ }, | ||
}, | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Unit tests. | ||
nodeunit: { | ||
tests: ['test/*_test.js'], | ||
}, | ||
}); | ||
@@ -120,0 +107,0 @@ |
{ | ||
"name": "grunt-toggl", | ||
"description": "Toggl API for Grunt. E.g. start time tracking with `grunt watch` or `grunt toggl`", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/davidosomething/grunt-toggl", | ||
@@ -39,4 +39,4 @@ "author": { | ||
"grunt-contrib-clean": "~0.5.0", | ||
"grunt-contrib-jshint": "~0.9.2", | ||
"grunt-contrib-nodeunit": "~0.3.3" | ||
"grunt-contrib-jshint": "^0.9.2", | ||
"grunt-contrib-nodeunit": "^0.3.3" | ||
}, | ||
@@ -43,0 +43,0 @@ "peerDependencies": { |
@@ -0,1 +1,6 @@ | ||
# <img src="http://davidosomething.com/content/uploads/grunt-toggl-logo.png" alt="grunt-toggl Logo" valign="middle" style="width: 2em; margin: 0 0.2em 0.2em 0;"> grunt-toggl | ||
> Toggl API for Grunt. E.g. start time tracking with `grunt watch` or | ||
`grunt toggl` | ||
[![Upstream](http://img.shields.io/badge/upstream-GitHub-lightgrey.svg)](https://github.com/davidosomething/grunt-toggl) | ||
[![Build Status: Linux](https://travis-ci.org/davidosomething/grunt-toggl.png?branch=master)](https://travis-ci.org/davidosomething/grunt-toggl) | ||
@@ -6,9 +11,6 @@ [![dependencies](https://david-dm.org/davidosomething/grunt-toggl.png)](https://david-dm.org/davidosomething/grunt-toggl) | ||
# grunt-toggl | ||
> Toggl API for Grunt. E.g. start time tracking with `grunt watch` or | ||
`grunt toggl` | ||
## Demo | ||
![Demo of starting a timer from the command line](http://i0.wp.com/davidosomething.com/content/uploads/grunt-toggl.gif) | ||
![Demo](http://i0.wp.com/davidosomething.com/content/uploads/grunt-toggl.gif) | ||
## Getting Started | ||
@@ -67,4 +69,11 @@ This plugin requires Grunt `~0.4.4` | ||
This is one way to specify your Toggl API key. | ||
This is one way to specify your Toggl API key. Not secure if your repo is public. | ||
#### options.apiEnvVar | ||
Type: `String` | ||
Default value: `` | ||
This is one way to specify your Toggl API key. Safe but you'll have to configure | ||
the shell env var on the machine you're using the task on. | ||
#### options.settingsFile | ||
@@ -177,2 +186,19 @@ Type: `String` | ||
#### Stop the current task | ||
Use: | ||
``` | ||
grunt toggl:MYTASK:stopCurrent | ||
``` | ||
To stop the current task timer. This will call the API to find out if there is a current timer running. If there is, another call is made to stop it. | ||
*OR* add this to your Gruntfile.js | ||
``` | ||
grunt.registerTask('toggl:stop', ['toggl:default:stopCurrent']); | ||
``` | ||
and you will be able to simply call | ||
``` | ||
grunt toggl:stop | ||
``` | ||
#### Default Options | ||
@@ -179,0 +205,0 @@ |
@@ -16,12 +16,10 @@ /* | ||
module.exports = function(grunt) { | ||
var _this; | ||
var done; | ||
var currentTaskID; | ||
var moreToDo; | ||
grunt.registerMultiTask('toggl', | ||
'Toggl API for Grunt. E.g. start time tracking with `grunt watch` or `grunt toggl`', | ||
function (listMode) { | ||
// Request is asynchronous | ||
var done = this.async(); | ||
function makeRequest (listMode) { | ||
// Merge task-specific and/or target-specific options with these defaults. | ||
var options = this.options({ | ||
var options = _this.options({ | ||
settingsFile: '.toggl', | ||
@@ -47,2 +45,3 @@ data: {} | ||
//////////////////////////////////////////////////////////////////////////////// | ||
@@ -96,2 +95,13 @@ // CALLBACKS | ||
else if (runMode === 'current' || (runMode === 'stopCurrent' && currentTaskID === undefined)) { | ||
if(runMode === 'stopCurrent') { | ||
moreToDo = true; | ||
} | ||
grunt.log.oklns('Grabbing current timer!'); | ||
} | ||
else if (runMode === 'stopCurrent') { | ||
grunt.log.oklns('Current Toggl timer (maybe) stopped!'); | ||
} | ||
else { | ||
@@ -101,4 +111,17 @@ grunt.log.oklns('New Toggl timer (maybe) started!'); | ||
// end async grunt task | ||
done(); | ||
if(moreToDo) { | ||
moreToDo = false; | ||
if(listMode === 'stopCurrent') { | ||
if(!body.data) { | ||
grunt.log.errorlns("No current timer running. Nothing to stop."); | ||
done(); | ||
} else { | ||
currentTaskID = body.data.id; | ||
makeRequest(listMode); | ||
} | ||
} | ||
} else { | ||
// end async grunt task | ||
done(); | ||
} | ||
} | ||
@@ -115,2 +138,21 @@ | ||
if (options.apiEnvVar) { | ||
settings.apiKey = process.env[options.apiEnvVar]; | ||
} | ||
var optionalDescription = grunt.option('desc'); | ||
if(!settings.data) { | ||
settings.data = {}; | ||
} | ||
if(!settings.data.description) { | ||
settings.data.description = ""; | ||
} | ||
if (optionalDescription) { | ||
if (settings.data.description) { | ||
options.data.description = settings.data.description + " " + optionalDescription; | ||
} else { | ||
options.data.description = optionalDescription; | ||
} | ||
} | ||
// Use option values, overrides file values if any, otherwise default nulls | ||
@@ -153,2 +195,16 @@ settings.apiKey = options.apiKey ? options.apiKey : settings.apiKey; | ||
// get current time entry | ||
else if (listMode === 'current' || (listMode === 'stopCurrent' && currentTaskID === undefined)) { | ||
runMode = listMode; | ||
params.url = 'https://www.toggl.com/api/v8/time_entries/current'; | ||
params.method = 'GET'; | ||
} | ||
// stop current time entry | ||
else if (listMode === 'stopCurrent') { | ||
runMode = 'stopCurrent'; | ||
params.url = 'https://www.toggl.com/api/v8/time_entries/' + currentTaskID + '/stop'; | ||
params.method = 'PUT'; | ||
} | ||
// create time entry | ||
@@ -199,4 +255,12 @@ else { | ||
}); | ||
}); | ||
} | ||
}; | ||
grunt.registerMultiTask('toggl', | ||
'Toggl API for Grunt. E.g. start time tracking with `grunt watch` or `grunt toggl`', | ||
function (listMode) { | ||
// Request is asynchronous | ||
done = this.async(); | ||
_this = this; | ||
makeRequest(listMode); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22169
369
231
1