-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
I created a grunt task from this api to integrate it with my Gruntfile:
grunt.registerMultiTask('neocities', 'Upload files to the Neocities web-service', function(){
'use strict';
var done = this.async();
var NeoCities = require('neocities');
var options = this.options();
if (options.username === undefined || options.password === undefined){
grunt.log.writeln(options);
grunt.log.error('options.username and options.password are mandatory !');
done(false);
return;
}
var api = new NeoCities(options.username, options.password);
var uploads = [];
this.files.forEach(function(filePair) {
if (filePair.src.length != 1 && filePair.dest !== undefined){
grunt.log.error('Same destination for multiple sources ?!');
done(false);
return;
}
filePair.src.forEach(function(src) {
var pair = {path: src};
if (filePair.dest !== undefined){
pair.name = filePair.dest;
} else {
pair.name = src.split(/[\\/]/).pop();
}
uploads.push(pair);
});
});
api.upload(uploads, function(resp) {
if (resp.result == 'error'){
grunt.log.error(resp.message);
done(false);
return;
}
grunt.log.writeln(resp.message);
done(true);
})
});I use the task as follow:
grunt.initConfig({
neo: grunt.file.readYAML('neocities_credentials.yaml'),
neocities: {
options: {
username: '<%= neo.username %>',
password: '<%= neo.password %>'
},
dist: {
src: 'dist/*',
}
},
});Some more flexibility is allowed (src ->dest mapping), see the code.
I thought maybe you're interested in publishing it.
It is the first time I wrote a grunt task, so there are probably lots of improvements to do.
Cheers !
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels