Browse Source

Add registration script skeleton

master
Tony Kovanen 9 years ago
parent
commit
ab2ef874f2
  1. 18
      gulpfile.js
  2. 2
      package.json
  3. 65
      scripts/post-install.js

18
gulpfile.js

@ -9,7 +9,8 @@ gulp.task('help', help);
gulp.task('compile', [
'compile-lib',
'compile-bin'
'compile-bin',
'compile-scripts'
]);
gulp.task('compile-lib', function () {
@ -39,6 +40,21 @@ gulp.task('compile-bin', function () {
.pipe(gulp.dest('build/bin'));
});
gulp.task('compile-scripts', function () {
return gulp.src('scripts/*')
.pipe(babel({
presets: ['es2015'],
plugins: [
'syntax-async-functions',
'transform-async-to-generator',
'transform-runtime'
]
}))
.pipe(ext.crop())
.pipe(gulp.dest('build/scripts'));
});
gulp.task('lint', function () {
return gulp.src([
'gulpfile.js',

2
package.json

@ -12,12 +12,14 @@
"now": "./build/bin/now"
},
"dependencies": {
"babel-runtime": "6.5.0",
"arr-flatten": "1.0.1",
"array-unique": "0.2.1",
"commander": "2.9.0",
"copy-paste": "1.1.4",
"fs-promise": "0.4.1",
"http2": "3.3.2",
"isomorphic-fetch": "2.2.1",
"ms": "0.7.1"
},
"devDependencies": {

65
scripts/post-install.js

@ -0,0 +1,65 @@
import readline from 'readline';
import fetch from 'isomorphic-fetch';
import { stringify as stringifyQuery } from 'querystring';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function readEmail () {
return new Promise((reject, resolve) => {
rl.question('> Enter your email address: ', resolve);
});
}
async function getVerificationToken (email) {
const res = await fetch('http://localhost:3001/', {
method: 'POST',
body: { email }
});
const body = await res.json();
return body.token;
}
async function verify (email, verificationToken) {
const query = {
email,
token: verificationToken
};
const res = await fetch('http://localhost:3001?' + stringifyQuery(query));
const body = await res.json();
return body.token;
}
function sleep (ms) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms);
});
}
async function register () {
const email = await readEmail();
const verificationToken = await getVerificationToken(email);
console.log('> Please follow the link in your email to log in.');
let final;
do {
await sleep(5000);
try {
const res = await verify(email, verificationToken);
final = res.token;
} catch (e) {}
} while (!final);
return { email, token: final };
}
register().then(({ email, token }) => {
console.log('got email', email);
console.log('got final token', token);
});
Loading…
Cancel
Save