Skip to content

Commit

Permalink
merging eval remove branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mayarajan3 committed Jun 23, 2024
2 parents 9c9c81b + e6c957f commit c201231
Show file tree
Hide file tree
Showing 6 changed files with 936 additions and 11 deletions.
59 changes: 50 additions & 9 deletions extensions/scripts/bundles/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { setAuxiliaryInfoForExtension } from "./auxiliaryInfo";
import { getAppInventorGenerator } from "scripts/utils/interop";
import { createFilter, FilterPattern } from '@rollup/pluginutils';
import { vmDeclarations } from "scripts/utils/generate";
import { chromium } from 'playwright';

export const clearDestinationDirectories = (): Plugin => {
const runner = runOncePerBundling();
Expand Down Expand Up @@ -186,27 +187,67 @@ export const mp3Bundler = (info: BundleInfo): Plugin => {
};
}

async function playwrightTest(framework, bundledJsPath) {
console.log("LAUNCHING PLAYWRIGHT TEST");
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
var detailsJSON = {};
await page.goto('about:blank');

page.on('console', async (msg) => {
const args = await Promise.all(msg.args().map(arg => arg.jsonValue()));
console.log(`Console Log from page:`, ...args);
for (const arg of args) {
if (arg.includes("DETAILS: ")) {
let prefix = "DETAILS: ";
let jsonVal = arg.substring(prefix.length).trim();
jsonVal = JSON.parse(jsonVal.trim());
detailsJSON = jsonVal;
}
}
});

const bundledJs = fs.readFileSync(bundledJsPath, 'utf8');
await page.evaluate(`
${framework}
${bundledJs}`)
await page.waitForTimeout(1000);
await browser.close();
return detailsJSON;
}

export const finalizeConfigurableExtensionBundle = (info: BundleInfo): Plugin => {
const { bundleDestination, menuDetails, name, directory } = info;

const executeBundleAndExtractMenuDetails = async () => {
const framework = await frameworkBundle.content;
let success = false;

extensionBundleEvent.registerCallback(function (extensionInfo, removeSelf) {
const { details } = extensionInfo;
for (const key in menuDetails) delete menuDetails[key];
for (const key in details) menuDetails[key] = details[key];
success = true;
removeSelf();
});
// extensionBundleEvent.registerCallback(function (extensionInfo, removeSelf) {
// const { details } = extensionInfo;
// for (const key in menuDetails) delete menuDetails[key];
// for (const key in details) menuDetails[key] = details[key];
// console.log("DETAILS GOT ADDED");
// console.log(details);
// success = true;
// removeSelf();
// });

const generateAppInventor = getAppInventorGenerator(info);

eval(framework + "\n" + fs.readFileSync(bundleDestination, "utf-8"));
if (!success) throw new Error(`No extension registered for '${name}'. Check your usage of the 'extension(...)' factory function.`);
const detailsJSON: any = await playwrightTest(framework, bundleDestination);
for (const key in menuDetails) delete menuDetails[key];
for (const key in detailsJSON) menuDetails[key] = detailsJSON[key];
console.log("DETAILS GOT ADDED");
console.log(detailsJSON);

generateAppInventor();

// eval(framework + "\n" + fs.readFileSync(bundleDestination, "utf-8"));



}

const runner = runOncePerBundling();
Expand Down
6 changes: 5 additions & 1 deletion extensions/src/common/extension/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export const extension = <const TSupported extends readonly MixinName[]>(
...addOns: Writeable<TSupported>
): ExtensionWithFunctionality<[...TSupported]> & typeof ExtensionBase => {

if (details) extensionBundleEvent?.fire({ details, addOns });
if (details) {
let detailStr = `DETAILS: ${JSON.stringify(details)}`;
console.log(detailStr);
extensionBundleEvent?.fire({ details, addOns });
}

const Base = scratchInfo(supported(ExtensionBase, addOns)) as ExtensionWithFunctionality<[...TSupported]>;

Expand Down
157 changes: 157 additions & 0 deletions extensions/src/poseBody/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extensions/src/poseBody/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"@tensorflow-models/posenet": "^2.2.1"
"@tensorflow-models/posenet": "2.2.1"
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
"ts-node": {
"typescript": "$typescript"
}
},
"dependencies": {
"playwright": "^1.44.1"
}
}
Loading

0 comments on commit c201231

Please sign in to comment.