Skip to content

Commit

Permalink
wip: convert recordFrames into Typescript; stubbed out renderFrames
Browse files Browse the repository at this point in the history
  • Loading branch information
megahirt committed Dec 14, 2020
1 parent 4ddd299 commit e39eb19
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ binaries/ffmpeg
binaries/ffprobe

.eslintcache

# incrementally move to typescript. Here are ignored JS files that are compiled
/public/cli/lib/rendering/**/*.js
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"tempy",
"usfm",
"webm"
]
],
"typescript.tsdk": "node_modules\\typescript\\lib"
}
66 changes: 63 additions & 3 deletions package-lock.json

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

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"@babel/plugin-proposal-decorators": "^7.10.5",
"@blueprintjs/core": "^3.30.0",
"@blueprintjs/select": "^3.13.5",
"@types/node": "^14.14.13",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"async": "^3.2.0",
"chalk": "^2.4.2",
"chromium": "^2.1.2",
Expand Down Expand Up @@ -54,9 +57,8 @@
"cli": "node public/cli/index.js",
"electron-dev": "concurrently \"cross-env BROWSER=none npm run start\" \"wait-on http://localhost:3000 && electron . --inspect 9229\"",
"start": "ffbinaries ffmpeg ffprobe -o=binaries && rescripts start",
"build": "ffbinaries ffmpeg ffprobe -o=binaries && rescripts build",
"test": "ava --watch",
"eject": "react-scripts eject",
"build": "tsc && ffbinaries ffmpeg ffprobe -o=binaries && rescripts build",
"test": "tsc && ava",
"postinstall": "electron-builder install-app-deps",
"preelectron-pack-mac": "npm run build",
"preelectron-pack-win": "npm run build",
Expand Down Expand Up @@ -89,8 +91,10 @@
]
},
"devDependencies": {
"@ava/typescript": "^1.1.1",
"@rescripts/cli": "^0.0.13",
"@rescripts/rescript-env": "^0.0.11",
"@tsconfig/node12": "^1.0.7",
"ava": "^3.13.0",
"babel-eslint": "^10.1.0",
"concurrently": "^5.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
const test = require('ava');
const tempy = require('tempy');
const { promises: fs } = require('fs');
const { record } = require('./recordFrames');
import test from 'ava';
import tempy from 'tempy';
import fs from 'fs';
import { record } from './recordFrames';

test('recordFrames: render 5 mock frames', async (t) => {
let htmlContent = createMockHtml();
const numberOfFrames = 5;
await tempy.directory.task(async (outputLocation) => {
let files = await fs.readdir(outputLocation);
let files = fs.readdirSync(outputLocation);
t.is(files.length, 0);
await record(htmlContent, numberOfFrames, outputLocation);
files = await fs.readdir(outputLocation);
files = fs.readdirSync(outputLocation);
t.is(files.length, numberOfFrames);
});
});

/**
* @returns {string}
*/
function createMockHtml() {
function createMockHtml(): string {
return `
<html>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ const puppeteer = require('puppeteer-core');
const chromium = require('chromium');
const path = require('path');

/**
*
* @param {string} htmlContent
* @param {number} numberOfFrames
* @param {string} outputLocation
* @param {boolean} logEachFrame
* @param {Function} notifyEvent TODO: I don't know what object or function this is yet
*/
module.exports.record = async function (
htmlContent,
numberOfFrames,
outputLocation,
interface NotifyEvent {
emit(state: string, options: object): void;
}
declare function renderNextFrame(): void;

export async function record(
htmlContent: string,
numberOfFrames: number,
outputLocation: string,
logEachFrame = false,
notifyEvent = false
notifyEvent: NotifyEvent | null = null
) {
// chromium.path may or may provide a path in an asar archive. If it does
// it is unusable, and we'll attempt to swap it out for the un-archived version
Expand Down Expand Up @@ -51,4 +48,4 @@ module.exports.record = async function (
notifyEvent.emit('rendered', { curr: i, total: numberOfFrames });
}
}
};
}
18 changes: 18 additions & 0 deletions public/cli/lib/rendering/renderFrames.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import test from 'ava';
import tempy from 'tempy';
import fs from 'fs';

test('renderFrames hello world', async (t) => {
/*
let htmlContent = createMockHtml();
const numberOfFrames = 5;
await tempy.directory.task(async (outputLocation) => {
let files = fs.readdirSync(outputLocation);
t.is(files.length, 0);
await record(htmlContent, numberOfFrames, outputLocation);
files = fs.readdirSync(outputLocation);
t.is(files.length, numberOfFrames);
});
*/
t.pass();
});
16 changes: 16 additions & 0 deletions public/cli/lib/rendering/renderFrames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { record } from './recordFrames';

export async function render(outputLocation: string) {
// collect UI options

// load caption/frames object
let captions = {};

// create HTMLcontent
const htmlContent = getHtml(captions);

// run record
//await record(htmlContent, numberOfFrames, outputLocation, notifyEvent);
}

function getHtml(captions: object) {}
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@tsconfig/node12/tsconfig.json",

"compilerOptions": {
"preserveConstEnums": true
},

"include": ["public/cli/lib/rendering/**/*.ts"],
"exclude": ["node_modules"]
}

0 comments on commit e39eb19

Please sign in to comment.