Skip to content

Commit

Permalink
updated mogrt dep tree
Browse files Browse the repository at this point in the history
  • Loading branch information
inlife committed Aug 15, 2024
1 parent f17e8f7 commit e19bd45
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/nexrender-action-mogrt/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const url = require('url');
const Mogrt = require('./mogrt');

module.exports = async (job, settings, options, type) => {
settings.logger = settings.logger ?? console;
Expand Down Expand Up @@ -38,7 +39,6 @@ module.exports = async (job, settings, options, type) => {
return job;
}

const { Mogrt } = await import('mogrt');
const mogrt = new Mogrt(job.template.dest);
await mogrt.init();

Expand Down
92 changes: 92 additions & 0 deletions packages/nexrender-action-mogrt/mogrt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const StreamZip = require("node-stream-zip")
const tempy = require("tempy");
const path = require("node:path");

function flattenStrings(obj, doNotCopy) {
if (!doNotCopy) obj = JSON.parse(JSON.stringify(obj));
for (let [k, v] of Object.entries(obj)) {
if (typeof v === 'object') {
if (!Array.isArray(v) && 'strDB' in v) {
if (v.strDB.length) {
obj[k] = Object.values(v.strDB)[0].str;
} else {
obj[k] = '';
}
} else {
obj[k] = flattenStrings(v, true);
}
}
}
return obj;
}

class Mogrt {
constructor(filename) {
this.filename = filename;
this.initialized = false;
this._manifest = null;
}

_getZip() {
return new StreamZip.async({ file: this.filename });
}

isAfterEffects() {
if (!this.initialized) throw Error('Must initialise with .init() first');
return this._manifest['authorApp'] === 'aefx';
}

isPremiere() {
if (!this.initialized) throw Error('Must initialise with .init() first');
return this._manifest['authorApp'] === 'ppro';
}

getEssentialFields(flattened) {
if (!this.initialized) throw Error('Must initialise with .init() first');
flattened = typeof flattened === 'undefined' || flattened;
let { clientControls } = this._manifest;
if (flattened) {
clientControls = flattenStrings(clientControls);
} else {
clientControls = JSON.parse(JSON.stringify(clientControls));
}
return clientControls;
}

async extractTo(toPath) {
const zip = this._getZip();
const entries = [];
await tempy.file.task(async (tempPath) => {
await zip.extract('project.aegraphic', tempPath);
const aegraphicZip = new StreamZip.async({ file: tempPath });
aegraphicZip.on('entry', entry => entries.push(path.join(toPath, entry.name)));
await aegraphicZip.extract(null, toPath);
await Promise.all([
aegraphicZip.close(),
zip.close()
]);
});
return entries;
}

async getManifest(flattened) {
flattened = typeof flattened === 'undefined' || flattened;
if (this._manifest === null) {
const zip = this._getZip();
this._manifest = JSON.parse((await zip.entryData('definition.json')).toString());
await zip.close();
}
if (flattened) {
return flattenStrings(this._manifest)
} else {
return this._manifest;
}
}

async init() {
await this.getManifest(false);
this.initialized = true;
}
}

module.exports = Mogrt;
3 changes: 2 additions & 1 deletion packages/nexrender-action-mogrt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"access": "public"
},
"dependencies": {
"mogrt": "^0.0.2"
"node-stream-zip": "^1.15.0",
"tempy": "^1.0.1"
}
}
4 changes: 2 additions & 2 deletions packages/nexrender-action-mogrt/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const extension = require('./index.js');
const url = require('node:url');
const path = require('node:path');
const assert = require('assert');
const tempy = require('tempy');

describe("action/mogrt",() => {
const defaultParameters = {
Expand All @@ -26,9 +27,8 @@ describe("action/mogrt",() => {
let parameters;

beforeEach(async () => {
const { temporaryDirectory } = await import('tempy');
parameters = JSON.parse(JSON.stringify(defaultParameters));
parameters.job.workpath = temporaryDirectory();
parameters.job.workpath = tempy.directory();
})

it('self-adds to postdownload', async () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/nexrender-action-mogrt/test/test.manual.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ process.env.NEXRENDER_ENABLE_AELOG_PROJECT_FOLDER = 1;

const path = require('path');
const url = require('node:url');
const { render } = require("@nexrender/core");
const { render } = require("../../nexrender-core");

const job = {
template: {
src: url.pathToFileURL(path.join(__dirname, '__tests__', './assets/ae.mogrt')).href,
src: url.pathToFileURL(path.join(__dirname, './assets/ae.mogrt')).href,
composition: 'ignored',
// continueOnMissing: true,
},
Expand All @@ -22,8 +22,8 @@ const job = {
actions: {
predownload: [
{
module: require.resolve('./index.js'),
essentialParameters: {
module: require.resolve('../index.js'),
params: {
'Group Test': {
'Image': 'ref-image-layer'
}
Expand Down

0 comments on commit e19bd45

Please sign in to comment.