-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
70 lines (62 loc) · 2.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const StreamZip = require('node-stream-zip');
const path = require('path');
const url = require('url');
const fs = require('fs/promises');
module.exports = async (job, settings, options, type) => {
settings.logger = settings.logger ?? console;
const jsxUrl = url.pathToFileURL(path.join(__dirname, 'applyEssentialValues.jsx')).toString();
if (type === 'predownload') {
if (typeof options.essentialParameters !== 'undefined') {
job.assets.push({
src: jsxUrl,
keyword: '_essential',
type: 'script',
parameters: [
{
key: 'essentialParameters',
value: Object.assign({}, options.essentialParameters)
}
]
})
}
// self-add this module as prerender action as well
if (!job.actions.prerender) {
job.actions.prerender = [];
}
job.actions.prerender.push({...options,
module: __filename,
automaticallyAdded: true
});
job.template.composition = '__mogrt__';
return job;
} else if (type === 'prerender' && options.automaticallyAdded) {
if(path.extname(job.template.dest).toLowerCase() !== ".mogrt"){
settings.logger.log(`[${job.uid}] [action-mogrt-template] skipping - template file should have .mogrt extension`);
return job;
}
const { Mogrt } = await import('mogrt');
const mogrt = new Mogrt(job.template.dest);
await mogrt.init();
if (!mogrt.isAfterEffects()) {
throw Error('[action-mogrt-template] ERROR - .mogrt was not made with After Effects');
}
const manifest = await mogrt.getManifest();
const compName = manifest.sourceInfoLocalized.en_US.name;
const asset = job.assets.find(a => a.src === jsxUrl);
asset.parameters.push({
key: 'composition',
value: compName
});
const filenames = await mogrt.extractTo(job.workpath);
const template = filenames.find(fn => path.extname(fn).toLowerCase() === '.aep');
if (!template) {
throw Error(`[${job.uid}] [action-mogrt-template] ERROR - no AE file found in the .mogrt (extension .aep)`);
}
settings.logger.log(`[${job.uid}] [action-mogrt-template] setting new template path to: ${template}`);
job.template.dest = template;
job.template.extension = "aep";
return job;
} else {
throw Error("'action-mogrt-template' module should be used only in 'predownload' section");
}
}