Clean master commit

This commit is contained in:
Lachlan Kermode
2018-10-31 19:35:15 +00:00
commit 2cbfbc33ef
24 changed files with 5400 additions and 0 deletions

46
src/initialize.js Executable file
View File

@@ -0,0 +1,46 @@
import StoreJson from "./models/StoreJson";
import Fetcher from "./lib/Fetcher";
import Controller from "./lib/Controller";
import config from "./config";
const {googleSheets} = config;
const {sheets, privateKey, email} = googleSheets;
function authenticate(_fetcher) {
return _fetcher.fetcher.authenticate(email, privateKey).then(msg => {
console.log(msg);
return true;
});
}
export default callback => {
const fetchers = sheets.map(sheet => {
return {
name: sheet.name,
fetcher: new Fetcher(new StoreJson(), sheet.name, sheet.id, sheet.tabs)
};
});
Promise.all(fetchers.map(authenticate))
.then(() => {
console.log(`===================`);
console.log(`grant access to: ${email}`);
console.log(`===================`);
// NB: reformat fetchers as config for controller
const config = {};
fetchers.forEach(fetcher => {
config[fetcher.name] = fetcher.fetcher;
});
const controller = new Controller(config);
callback(controller);
})
.catch(err => {
console.log(err);
console.log(
`ERROR: the server couldn't connect to all of the sheets you provided. Ensure you have granted access to ${
serviceAccount.email
} on ALL listed sheets.`
);
});
};