Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
WIP non-linting fake api. Build is now very very very tangled
Browse files Browse the repository at this point in the history
  • Loading branch information
gregglind committed Apr 10, 2018
1 parent 587d5a9 commit 74a4a9b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ package-lock.json
!.eslintrc.js
# don't lint/format package.json since npm install formats it differently by default
package.json
webExtensionApis/study/fakeApi.js
44 changes: 44 additions & 0 deletions bin/schemaToInterface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
this.prefs = class extends ExtensionAPI {
getAPI(context) {
return {
prefs: {
async get(prefName) {
return "getting";
},
async set(prefName, value) {
return "set";
}
}
};
}
}
*/

function schema2shim(schemaApiJSON) {
for (var i in schemaApiJSON) {
let part = schemaApiJSON[i];
let ns = part.namespace;
let functionStrings = [];
for (var j in part.functions) {
let fn = part.functions[j];
let args = (fn.parameters || []).map(x => x.name).join(", ");
functionStrings.push(`
async ${fn.name} ( ${args} ) {
return ${JSON.stringify(fn.defaultReturn)};
}`);
}
console.log(`
/* eslint-disable */
this.${ns} = class extends ExtensionAPI {
getAPI(context) {
return {
${functionStrings.join("\n")}
}
}
}`);
}
}
const path = require("path");
schema2shim(require(path.resolve(process.argv[2])));
2 changes: 2 additions & 0 deletions webExtensionApis/study/fakeApi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

/* eslint-disable */

this.study = class extends ExtensionAPI {
getAPI(context) {
return {
Expand Down

0 comments on commit 74a4a9b

Please sign in to comment.