@creek/sync-lib v0.0.4
Creek Sync API
Node.js API for Creek's Sync capabilities.
⚠ This README is a working draft for the future client. Please do not expect any of the following to work yet ⚠
Install
$ npm install @creek/sync-lib
Usage
Require and create a new instance of the client:
// Import the library
const Sync = require('@creek/sync-lib);
// Read settings from the filesystem
const settings = Sync.helpers.settings.get();
// Create a Sync instance
const sync = new Sync(settings);
// Receive updates on status changes summarising the client activity
// Should contain all information required for providing a user interface.
sync.on('status', () => {
});
// Start up
sync.start()
Events
An instance of Sync provides an EventEmitter interface to catch the following events:
next-sync-time
debug
upload-running
upload-finished
Settings helper
Read settings:
const settings = Sync.helpers.settings.get()
Save settings:
Sync.helpers.settings.save(settings)
Recordings helper
List local recordings:
const localRecordings = await Sync.helpers.recordings.listLocalRecordings();
Retrieve missing recordings list:
const domain = 'beepboop.creek.fm';
const missingRecordings = await Sync.helpers.recordings.listMissingRecordings(domain);
Match missing recordings:
const matchedRecordings = Sync.helpers.recordings.matchMissingRecordings(localRecordings, missingRecordings);
S3 helper
Retrieve S3 Credentials:
const credentials = await Sync.helpers.s3.getCredentials();
Upload a file with progress reports:
const upload = Sync.helpers.s3.transferFile(credentials, {
full_path: path.resolve(__dirname, 'track.mp3'),
s3_object_name: '/my-track.mp3'
});
upload.onProgress(console.log);
await upload;
console.log('uploaded')
Testing
The test suite can be run by executing npm test
, the output is in TAP which can then be piped into your favorite report generator. To quickly run with a human readable output the following is suggested.
$ npm install --global tap-spec
# Ensure you've downloaded the test recordings (only needs to be done once)
$ npm run download-recordings
$ npm test | tap-spec
Coverage
In an attempt to remove dead code and ensure all code is passed through on the tests you can visualise the current code coverage by running the following.
$ npm run coverage
Afterwhich a HTML report will be generated at coverage/index.html.
Code Style
This projects adopts the xo style guide with spaces. The linting tool can be run with the following.
$ npm run lint