Comparing version 0.1.1 to 0.2.1
@@ -7,2 +7,3 @@ 'use strict'; | ||
exports.readFile = readFile; | ||
exports.writeFile = writeFile; | ||
@@ -22,2 +23,11 @@ var _fs = require('fs'); | ||
}); | ||
} | ||
function writeFile(path, content) { | ||
return new Promise((resolve, reject) => { | ||
_fs2.default.writeFile(path, content, err => { | ||
if (err) return reject(err); | ||
resolve(); | ||
}); | ||
}); | ||
} |
@@ -45,2 +45,6 @@ 'use strict'; | ||
getGist(content) { | ||
return this.request(`/gists/${ content.id }`, 'get'); | ||
} | ||
createGist(content) { | ||
@@ -47,0 +51,0 @@ return this.request('/gists', 'post', content); |
@@ -42,2 +42,3 @@ 'use strict'; | ||
this.validateOptions(options); | ||
this.directory = directory; | ||
this.pattern = this.getPattern(directory); | ||
@@ -77,6 +78,10 @@ this.pollInterval = options.pollInterval; | ||
getPattern(directory) { | ||
const dir = _path2.default.resolve(process.cwd(), directory); | ||
const dir = this.getDir(directory); | ||
return `${ dir }/`; | ||
} | ||
getDir(directory) { | ||
return _path2.default.resolve(process.cwd(), directory); | ||
} | ||
hasFileUpdated(filename, content, existing) { | ||
@@ -157,2 +162,3 @@ if (!existing) return true; | ||
setDirectory(directory) { | ||
this.directory = directory; | ||
this.pattern = this.getPattern(directory); | ||
@@ -261,7 +267,18 @@ this.watcher.setPattern(this.pattern); | ||
onFileRemoved() { | ||
// TODO: Possibly do this? | ||
return _asyncToGenerator(function* () {})(); | ||
} | ||
// TODO: Possibly do this? | ||
downloadFile({ id }) { | ||
var _this7 = this; | ||
return _asyncToGenerator(function* () { | ||
const gist = _this7.getGist(id); | ||
const { filename, content } = (0, _gistSerializer.parseSingleFileFromGist)(gist); | ||
const filepath = _path2.default.resolve(_this7.getDir(_this7.directory), filename); | ||
return yield (0, _fsPromise.writeFile)(filepath, content); | ||
})(); | ||
} | ||
/* | ||
@@ -272,9 +289,9 @@ methods dealing with fetching more data | ||
getUser() { | ||
var _this7 = this; | ||
var _this8 = this; | ||
return _asyncToGenerator(function* () { | ||
const { getCache, applicationToken, setCache } = _this7.options; | ||
const { getCache, applicationToken, setCache } = _this8.options; | ||
let user = yield getCache(applicationToken); | ||
if (!user) { | ||
const { body } = yield _this7.api.getUser(); | ||
const { body } = yield _this8.api.getUser(); | ||
user = body; | ||
@@ -288,13 +305,13 @@ yield setCache(applicationToken, user); | ||
getAllGist() { | ||
var _this8 = this; | ||
var _this9 = this; | ||
return _asyncToGenerator(function* () { | ||
const { setCache, getCache } = _this8.options; | ||
const { login } = yield _this8.getUser(); | ||
const { setCache, getCache } = _this9.options; | ||
const { login } = yield _this9.getUser(); | ||
let gists = yield getCache(`${ login }:gists`); | ||
if (!gists) { | ||
const { body } = yield _this8.api.getAllGists({ login }); | ||
const { body } = yield _this9.api.getAllGists({ login }); | ||
gists = body; | ||
yield setCache(`${ login }:gists`, gists); | ||
_this8.getGistByFileName = (0, _gistSerializer.getGistByFileName)(gists); | ||
_this9.getGistByFileName = (0, _gistSerializer.getGistByFileName)(gists); | ||
} | ||
@@ -304,4 +321,13 @@ return gists; | ||
} | ||
getGist(id) { | ||
var _this10 = this; | ||
return _asyncToGenerator(function* () { | ||
// dont hit cache for single gist | ||
return yield _this10.api.getGist({ id }); | ||
})(); | ||
} | ||
} | ||
module.exports = GistsSync; |
{ | ||
"name": "gist-sync", | ||
"version": "0.1.1", | ||
"version": "0.2.1", | ||
"description": "a lib to help sync a directory to your gist", | ||
@@ -5,0 +5,0 @@ "main": "dist/gists-sync.js", |
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
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
16531
408