Commit e5333522 authored by Iván Sánchez Ortega's avatar Iván Sánchez Ortega

Scaffolding for account creation

parent 6b787ae0
......@@ -10,6 +10,7 @@
"chalk256": "^5.1.0",
"configstore": "^3.0.0",
"flatten-obj": "^3.1.0",
"inquirer": "^3.0.6",
"vorpal": "^1.11.4"
},
"scripts": {
......
......@@ -41,7 +41,6 @@ export default class Account {
}
// 🍂method listChannels(): Array
// Returns a list of *well-known* channels for this account. This doesn't
// mean that these channels are the only ones available.
......@@ -50,6 +49,14 @@ export default class Account {
}
// 🍂method listChannels(): Array
// Returns the timestamp of when the platform was last queried.
getLastUpdateTimestamp() {
// The clock runs updates real-time, so
return Date.now();
}
// 🍂section Internal methods
// 🍂method emit(data: Status data, metadata: Object): this
// Makes this `Platform` emit a status update to be printed on the CLI (after
......@@ -60,6 +67,7 @@ export default class Account {
this._callback(this, data);
return this;
}
}
/*
......
......@@ -12,7 +12,7 @@
import Account from '../abstracts/account';
import inquirer from 'inquirer';
// 🍂class ClockAccount
......@@ -48,7 +48,8 @@ class ClockAccount extends Account {
if (channel === 'day') { delay = 1000 * 3600 * 24; }
if (channel === 'hour') { delay = 1000 * 3600; }
if (channel === 'quarter') { delay = 1000 * 60 * 15; }
if (channel === 'minute') { delay = 1000 * 60; }
// if (channel === 'minute') { delay = 1000 * 60; }
if (channel === 'minute') { delay = 1000 * 5; }
if (delay <= 0) { return; }
......@@ -78,6 +79,10 @@ class ClockAccount extends Account {
return ['day', 'hour', 'quarter', 'minute'];
}
getLastUpdateTimestamp() {
// The clock runs updates real-time, so
return Date.now();
}
}
......@@ -91,12 +96,48 @@ export function signUp() {
/// TODO: Extend this with a prompt for the default channel to listen to, or a prompt for
/// the badge.
return Promise.resolve({
return inquirer.prompt([{
type: 'list',
name: 'confirm',
message: 'You are going to add a "clock" fake platform. Is this right?',
choices: ['yes', 'no']
}]).then((answer)=>{
if (answer.confirm === 'yes') {
return {};
} else {
throw new Error('Not creating the new clock account then.');
}
});
// return new Promise((resolve, reject)=>{
// });
// return Promise.resolve({
// // No options needed to initialize this platform, really.
// // Normally this would include auth tokens and such.
// });
}
// export function signUp() {
//
// // There is nothing asynchronous here, so...
//
// /// TODO: Extend this with a prompt for the default channel to listen to, or a prompt for
// /// the badge.
//
// return Promise.resolve({
// // No options needed to initialize this platform, really.
// // Normally this would include auth tokens and such.
// });
//
// }
......
// 🍂class Platform
// A base abstract class for all social platforms. It's possible to use more than
// an instance of the same `Platform`, e.g. more than one account in a social
// network.
export default class Platform {
// 🍂constructor constructor(callback: Function, opts: Object)
// Any platform will be initialized with a `callback` function, that will
// receive the emitted status updates.
constructor(callback, opts) {
if (this._opts === undefined) {
this._opts = {};
}
this._callback = callback;
}
get opts() {
return this._opts;
}
set opts(newOpts) {
return this._opts = Object.assign(this._opts, newOpts);
}
// 🍂method listen(callback: Function, channel: String): this
// Starts listening for updates at the given "channel". A "channel" is a
// string with semantics depending on the platform. A platform might have
// channels like "wall", "stream", "replies", "dms", lists, and so on.
listen(channel) {
return this;
}
// 🍂method listen(channel: String): this
// Stops listening for updates at the given channel. Corresponds to a previous
// `listen()` call.
unlisten(channel) {
return this;
}
// 🍂method listChannels(): Array
// Returns a list of *well-known* channels for this platform. This doesn't
// mean that these channels are the only ones available.
listChannels() {
return ['day', 'hour', 'quarter', 'minute'];
}
// 🍂section Internal methods
// 🍂method emit(data: Status data, metadata: Object): this
// Makes this `Platform` emit a status update to be printed on the CLI (after
// filtering/transforming by plugins). Needs some normalized data about the
// update, but can include optional metadata as given from the platform.
// This is meant to be called only from subclasses.
emit(data) {
this._callback(this, data);
return this;
}
}
/*
🍂namespace Status data
A status update is a plain object with at least the following properties:
🍂property str: String
The main text string of the status update.
* This is a template platform module.
*
* Every platform is a ES2015 module which must expose:
* - Account (a subclass of 'Account'; a bit confusing, I know)
* - name (a String)
* - signUp (a function that must return a Promise to a set of config options
* for a new configured account)
*/
🍂property author?: String
An optional string with the author of the update, relative to the platform. Can be empty.
import Account from '../abstracts/account';
🍂property channel?: String
The channel within the platform that this update came through. Might be empty
if the platform has a "default" channel, or for system messages from the platform.
🍂property realtime?: Boolean
Optionally denotes whether the update is happening in real time (the update has been received
as quick as possible), or not.
🍂property medadata?: Object
An optional dictionary or data structure with platform-specific information. e.g.
the original tweet JSON for twitter, etc.
*/
class TemplateAccount extends Account {
// ...
}
export DemoAccount as Account;
export function signUp() {
// Prompt for stuff, returning a Promise for the config opts for a new instance
return Promise.resolve({});
}
export const name = 'template';
......@@ -226,16 +226,33 @@ vorpal
.command('accounts add [platform] [alias]', 'Adds an account given its platform and alias. Most likely you want the alias to be your username in that platform.')
.action(function(args, callback) {
if (args.platform === undefined || args.alias === undefined ) {
this.log( chalk.red('>>> Specify platform and alias of the account.'));
callback();
} else {
this.log( chalk.red.bold('>>> NOT IMPLEMENTED YET.'));
if (!(args.platform in platforms)) {
this.log( chalk.red('>>> Specified platform does not exist or is not supported. Maybe you mistyped it?'));
callback();
} else {
vorpal.ui.cancel();
// vorpal.ui.redraw();
platforms[args.platform].signUp().then((opts)=>{
this.log( chalk.red.bold('>>> NOT IMPLEMENTED YET.'));
this.log( 'Should store config for a new account: ', opts);
// ui.redraw.done()
callback();
}).catch((err)=>{
this.log( chalk.red.bold('>>> Creation of new account cancelled.'));
// ui.redraw.done()
callback();
});
}
}
callback();
});
......
......@@ -95,10 +95,20 @@ cli-cursor@^1.0.1, cli-cursor@^1.0.2:
dependencies:
restore-cursor "^1.0.1"
cli-cursor@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
dependencies:
restore-cursor "^2.0.0"
cli-width@^1.0.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-1.1.1.tgz#a4d293ef67ebb7b88d4a4d42c0ccf00c4d1e366d"
cli-width@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.1.0.tgz#b234ca209b29ef66fc518d9b98d5847b00edf00a"
code-point-at@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
......@@ -144,6 +154,12 @@ exit-hook@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/exit-hook/-/exit-hook-1.1.1.tgz#f05ca233b48c05d54fff07765df8507e95c02ff8"
external-editor@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-2.0.1.tgz#4c597c6c88fa6410e41dbbaa7b1be2336aa31095"
dependencies:
tmp "^0.0.31"
figures@^1.3.5:
version "1.7.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e"
......@@ -151,6 +167,12 @@ figures@^1.3.5:
escape-string-regexp "^1.0.5"
object-assign "^4.1.0"
figures@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962"
dependencies:
escape-string-regexp "^1.0.5"
flatten-obj@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/flatten-obj/-/flatten-obj-3.1.0.tgz#54aa27d147f37891c642103b8caa8d63e48f13ed"
......@@ -196,16 +218,42 @@ inquirer@0.11.0:
strip-ansi "^3.0.0"
through "^2.3.6"
inquirer@^3.0.6:
version "3.0.6"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-3.0.6.tgz#e04aaa9d05b7a3cb9b0f407d04375f0447190347"
dependencies:
ansi-escapes "^1.1.0"
chalk "^1.0.0"
cli-cursor "^2.1.0"
cli-width "^2.0.0"
external-editor "^2.0.1"
figures "^2.0.0"
lodash "^4.3.0"
mute-stream "0.0.7"
run-async "^2.2.0"
rx "^4.1.0"
string-width "^2.0.0"
strip-ansi "^3.0.0"
through "^2.3.6"
is-fullwidth-code-point@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz#ef9e31386f031a7f0d643af82fde50c457ef00cb"
dependencies:
number-is-nan "^1.0.0"
is-fullwidth-code-point@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f"
is-obj@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-obj/-/is-obj-1.0.1.tgz#3e4729ac1f5fde025cd7d83a896dab9f4f67db0f"
is-promise@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa"
isobj@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isobj/-/isobj-1.0.0.tgz#67ba28f9c6dc98130eba1a379bdcbd1d939c73f4"
......@@ -214,7 +262,7 @@ lodash@^3.3.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
lodash@^4.5.1:
lodash@^4.3.0, lodash@^4.5.1:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
......@@ -231,6 +279,10 @@ magic-string@^0.14.0:
dependencies:
vlq "^0.2.1"
mimic-fn@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18"
minimatch@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774"
......@@ -255,6 +307,10 @@ mute-stream@0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.5.tgz#8fbfabb0a98a253d3184331f9e8deb7372fac6c0"
mute-stream@0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
node-localstorage@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/node-localstorage/-/node-localstorage-0.6.0.tgz#45a0601c6932dfde6644a23361f1be173c75d3af"
......@@ -277,10 +333,20 @@ onetime@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-1.1.0.tgz#a1f7838f8314c516f05ecefcbc4ccfe04b4ed789"
onetime@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4"
dependencies:
mimic-fn "^1.0.0"
os-homedir@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
os-tmpdir@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
readline2@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/readline2/-/readline2-1.0.1.tgz#41059608ffc154757b715d9989d199ffbf372e35"
......@@ -300,6 +366,13 @@ restore-cursor@^1.0.1:
exit-hook "^1.0.0"
onetime "^1.0.0"
restore-cursor@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf"
dependencies:
onetime "^2.0.0"
signal-exit "^3.0.2"
rollup-plugin-buble@^0.15.0:
version "0.15.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-buble/-/rollup-plugin-buble-0.15.0.tgz#83c3e89c7fd2266c7918f41ba3980313519c7fd0"
......@@ -320,10 +393,24 @@ run-async@^0.1.0:
dependencies:
once "^1.3.0"
run-async@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"
dependencies:
is-promise "^2.1.0"
rx-lite@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-3.1.2.tgz#19ce502ca572665f3b647b10939f97fd1615f102"
rx@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/rx/-/rx-4.1.0.tgz#a5f13ff79ef3b740fe30aa803fb09f98805d4782"
signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
slide@^1.1.5:
version "1.1.6"
resolved "https://registry.yarnpkg.com/slide/-/slide-1.1.6.tgz#56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707"
......@@ -336,6 +423,13 @@ string-width@^1.0.1:
is-fullwidth-code-point "^1.0.0"
strip-ansi "^3.0.0"
string-width@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.0.0.tgz#635c5436cc72a6e0c387ceca278d4e2eec52687e"
dependencies:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^3.0.0"
strip-ansi@^0.2.1:
version "0.2.2"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-0.2.2.tgz#854d290c981525fc8c397a910b025ae2d54ffc08"
......@@ -356,6 +450,12 @@ through@^2.3.6:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
tmp@^0.0.31:
version "0.0.31"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.31.tgz#8f38ab9438e17315e5dbd8b3657e8bfb277ae4a7"
dependencies:
os-tmpdir "~1.0.1"
unique-string@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unique-string/-/unique-string-1.0.0.tgz#9e1057cca851abb93398f8b33ae187b99caec11a"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment