@nexrender/core 1.42.2 → 1.43.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/tasks/render.js +25 -11
- package/src/tasks/script.js +180 -221
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexrender/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.43.1",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"author": "Inlife",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"pkg-prelink": "node ../../misc/prelink.js"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@nexrender/types": "^1.
|
|
10
|
+
"@nexrender/types": "^1.43.1",
|
|
11
11
|
"data-uri-to-buffer": "^3.0.0",
|
|
12
12
|
"file-uri-to-path": "^2.0.0",
|
|
13
13
|
"is-wsl": "^2.2.0",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "02d0fdfa2224a28799c79628cf74ded632fa27c0"
|
|
34
34
|
}
|
package/src/tasks/render.js
CHANGED
|
@@ -7,7 +7,7 @@ const progressRegex = /([\d]{1,2}:[\d]{2}:[\d]{2}:[\d]{2})\s+(\(\d+\))/gi;
|
|
|
7
7
|
const durationRegex = /Duration:\s+([\d]{1,2}:[\d]{2}:[\d]{2}:[\d]{2})/gi;
|
|
8
8
|
const startRegex = /Start:\s+([\d]{1,2}:[\d]{2}:[\d]{2}:[\d]{2})/gi;
|
|
9
9
|
const nexrenderErrorRegex = /Error:\s+(nexrender:.*)$/gim;
|
|
10
|
-
const errorRegex =
|
|
10
|
+
const errorRegex = /aerender Error:\s*(.*)$/gis;
|
|
11
11
|
|
|
12
12
|
const option = (params, name, ...values) => {
|
|
13
13
|
if (values !== undefined) {
|
|
@@ -29,12 +29,30 @@ module.exports = (job, settings) => {
|
|
|
29
29
|
let params = [];
|
|
30
30
|
let outputFile = expandEnvironmentVariables(job.output)
|
|
31
31
|
let projectFile = expandEnvironmentVariables(job.template.dest)
|
|
32
|
+
let logPath = path.resolve(job.workpath, `../aerender-${job.uid}.log`)
|
|
33
|
+
|
|
34
|
+
if (process.env.NEXRENDER_ENABLE_AELOG_PROJECT_FOLDER) {
|
|
35
|
+
logPath = path.join(job.workpath, `aerender.log`)
|
|
36
|
+
settings.logger.log(`[${job.uid}] setting aerender log path to project folder: ${logPath}`);
|
|
37
|
+
} else if (process.env.NEXRENDER_ENABLE_AELOG_LEGACY_TEMP_FOLDER) {
|
|
38
|
+
settings.logger.log(`[${job.uid}] setting aerender log path to temp folder: ${logPath}`);
|
|
39
|
+
} else {
|
|
40
|
+
settings.logger.log(`[${job.uid}] -- D E P R E C A T I O N: --
|
|
41
|
+
|
|
42
|
+
nexrender is changing the default aerender log path to the project folder.
|
|
43
|
+
This is done to streamline the log management and enable efficient log cleanup.
|
|
44
|
+
|
|
45
|
+
If you want to keep the old behavior and mute this message, please set the environment variable NEXRENDER_ENABLE_AELOG_LEGACY_TEMP_FOLDER to true.
|
|
46
|
+
If you want to switch to the new behavior, please set the environment variable NEXRENDER_ENABLE_AELOG_PROJECT_FOLDER to true.
|
|
47
|
+
|
|
48
|
+
Right now, the old behavior is still the default, but this will change in the next minor releases.
|
|
49
|
+
Estimated date of change to the new behavior: 2023-06-01.\n`);
|
|
50
|
+
}
|
|
32
51
|
|
|
33
52
|
const outputFileAE = checkForWSL(outputFile, settings)
|
|
34
53
|
projectFile = checkForWSL(projectFile, settings)
|
|
35
54
|
let jobScriptFile = checkForWSL(job.scriptfile, settings)
|
|
36
55
|
|
|
37
|
-
|
|
38
56
|
// setup parameters
|
|
39
57
|
params.push('-project', projectFile);
|
|
40
58
|
params.push('-comp', job.template.composition);
|
|
@@ -44,6 +62,9 @@ module.exports = (job, settings) => {
|
|
|
44
62
|
option(params, '-OMtemplate', job.template.outputModule);
|
|
45
63
|
option(params, '-RStemplate', job.template.settingsTemplate);
|
|
46
64
|
|
|
65
|
+
option(params, '-renderSettings', job.template.renderSettings);
|
|
66
|
+
option(params, '-outputSettings', job.template.outputSettings);
|
|
67
|
+
|
|
47
68
|
option(params, '-s', job.template.frameStart);
|
|
48
69
|
option(params, '-e', job.template.frameEnd);
|
|
49
70
|
option(params, '-i', job.template.incrementFrame);
|
|
@@ -140,7 +161,6 @@ module.exports = (job, settings) => {
|
|
|
140
161
|
}
|
|
141
162
|
|
|
142
163
|
const output = [];
|
|
143
|
-
const logPath = path.resolve(job.workpath, `../aerender-${job.uid}.log`)
|
|
144
164
|
const instance = spawn(settings.binary, params, {
|
|
145
165
|
windowsHide: true
|
|
146
166
|
// NOTE: disabled PATH for now, there were a few
|
|
@@ -218,14 +238,7 @@ module.exports = (job, settings) => {
|
|
|
218
238
|
defaultOutputs.shift();
|
|
219
239
|
}
|
|
220
240
|
|
|
221
|
-
if (defaultOutputs.length === 0) {
|
|
222
|
-
clearTimeout(timeoutID);
|
|
223
|
-
return reject(new Error(`Output file not found: ${job.output}`));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
job.output = defaultOutputs[0];
|
|
227
|
-
|
|
228
|
-
if (!fs.existsSync(job.output)) {
|
|
241
|
+
if (defaultOutputs.length === 0 || !fs.existsSync(defaultOutputs[0])) {
|
|
229
242
|
if (fs.existsSync(logPath)) {
|
|
230
243
|
settings.logger.log(`[${job.uid}] dumping aerender log:`)
|
|
231
244
|
settings.logger.log(fs.readFileSync(logPath, 'utf8'))
|
|
@@ -235,6 +248,7 @@ module.exports = (job, settings) => {
|
|
|
235
248
|
return reject(new Error(`Couldn't find a result file: ${outputFile}`))
|
|
236
249
|
}
|
|
237
250
|
|
|
251
|
+
job.output = defaultOutputs[0];
|
|
238
252
|
const stats = fs.statSync(job.output)
|
|
239
253
|
|
|
240
254
|
/* file smaller than 1000 bytes */
|
package/src/tasks/script.js
CHANGED
|
@@ -12,11 +12,11 @@ const escape = str => {
|
|
|
12
12
|
return str
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const selectLayers = ({ composition, layerName, layerIndex
|
|
15
|
+
const selectLayers = (job, settings, { composition, layerName, layerIndex }, callbackString) => {
|
|
16
16
|
const method = layerName ? 'selectLayersByName' : 'selectLayersByIndex';
|
|
17
17
|
const compo = composition === undefined ? 'null' : escape(composition);
|
|
18
18
|
const value = layerName ? escape(layerName) : layerIndex;
|
|
19
|
-
return (`nexrender.${method}(${compo}, ${value}, ${callbackString},null
|
|
19
|
+
return (`nexrender.${method}(${compo}, ${value}, ${callbackString}, null, ${job.template.continueOnMissing});`);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const renderIf = (value, string) => {
|
|
@@ -30,150 +30,124 @@ const partsOfKeypath = (keypath) => {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/* scripting wrappers */
|
|
33
|
-
const wrapFootage = ({ dest, ...asset }
|
|
34
|
-
${selectLayers(asset, `function(layer) {
|
|
33
|
+
const wrapFootage = (job, settings, { dest, ...asset }) => (`(function() {
|
|
34
|
+
${selectLayers(job, settings, asset, `function(layer) {
|
|
35
35
|
nexrender.replaceFootage(layer, '${checkForWSL(dest.replace(/\\/g, "\\\\"), settings)}')
|
|
36
36
|
}`)}
|
|
37
37
|
})();\n`)
|
|
38
38
|
|
|
39
|
-
const wrapData = ({ property, value, expression, ...asset }) => (`(function() {
|
|
40
|
-
${selectLayers(
|
|
41
|
-
|
|
39
|
+
const wrapData = (job, settings, { property, value, expression, ...asset }) => (`(function() {
|
|
40
|
+
${selectLayers(job, settings, asset, `function(layer) {
|
|
42
41
|
var parts = ${JSON.stringify(partsOfKeypath(property))};
|
|
43
42
|
${renderIf(value, `var value = { "value": $value }`)}
|
|
44
43
|
${renderIf(expression, `var value = { "expression": $value }`)}
|
|
45
44
|
nexrender.changeValueForKeypath(layer, parts, value);
|
|
46
|
-
|
|
47
|
-
return true;
|
|
48
45
|
}`)}
|
|
49
46
|
})();\n`)
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
@param defaults.null (Any) The default value in case the user setted key name on any given `parameter` child object. Defaults to `null`
|
|
71
|
-
|
|
72
|
-
@return string (String) The compiled script with parameter injection outside its original scope to avoid user-defined defaults collision.
|
|
73
|
-
*/
|
|
74
|
-
const wrapEnhancedScript = ({ dest, src, parameters = [], keyword, defaults, /* ...asset */ }, jobID, settings) => {
|
|
48
|
+
/**
|
|
49
|
+
* Wrap Enhanced Script
|
|
50
|
+
* ====================
|
|
51
|
+
* @author Dilip Ramírez (https://github.com/dukuo | https://notimetoexplain.co)
|
|
52
|
+
* @autor Based on the work of Potat (https://github.com/dukuo/potat)
|
|
53
|
+
* @description Parse a script from a source, and injects a configuration object named ${keyword} based on the "parameters" array of the script asset if any.
|
|
54
|
+
*
|
|
55
|
+
* If parameters or functions deriving from the configuration object are being used in the script, but no parameters are set, then it succeeds but
|
|
56
|
+
* displays a warning with the missing JSX/JSON matches, and sets all the missing ones to null for a soft fault tolerance at runtime.
|
|
57
|
+
*
|
|
58
|
+
* @param src The JSX script
|
|
59
|
+
* @param parameters (Array<Object>) Argument array described in the Asset JSON object inside the Job description
|
|
60
|
+
* @param keyword (String) Name for the exported variable holding configuration parameters. Defaults to NX as in NeXrender.
|
|
61
|
+
* @param defaults.null (Any) The default value in case the user setted key name on any given `parameter` child object. Defaults to `null`
|
|
62
|
+
*
|
|
63
|
+
* @return string (String) The compiled script with parameter injection outside its original scope to avoid user-defined defaults collision.
|
|
64
|
+
*/
|
|
65
|
+
const wrapEnhancedScript = (job, settings, { dest, src, parameters = [], keyword, defaults, /* ...asset */ }) => {
|
|
66
|
+
const jobID = job.uid;
|
|
75
67
|
let arg, fullMatch;
|
|
76
68
|
|
|
77
69
|
function EnhancedScript (
|
|
78
70
|
dest,
|
|
79
71
|
src,
|
|
80
|
-
parameters
|
|
81
|
-
keyword
|
|
82
|
-
defaults
|
|
83
|
-
global
|
|
84
|
-
string
|
|
72
|
+
parameters = [],
|
|
73
|
+
keyword = "NX",
|
|
74
|
+
defaults = {
|
|
75
|
+
global: "null",
|
|
76
|
+
string: "",
|
|
85
77
|
number: 0,
|
|
86
78
|
array: [],
|
|
87
79
|
boolean: false,
|
|
88
80
|
object: {},
|
|
89
|
-
function
|
|
81
|
+
function: function (){},
|
|
90
82
|
null: null
|
|
91
83
|
},
|
|
92
84
|
jobID,
|
|
93
85
|
logger
|
|
94
86
|
) {
|
|
95
|
-
this.scriptPath
|
|
96
|
-
this.script
|
|
97
|
-
this.keyword
|
|
98
|
-
this.defaults
|
|
99
|
-
this.jobID
|
|
100
|
-
this.logger
|
|
101
|
-
this.jsonParameters
|
|
102
|
-
|
|
103
|
-
this.regexes
|
|
87
|
+
this.scriptPath = src;
|
|
88
|
+
this.script = fs.readFileSync(dest, 'utf8');
|
|
89
|
+
this.keyword = keyword;
|
|
90
|
+
this.defaults = defaults;
|
|
91
|
+
this.jobID = jobID;
|
|
92
|
+
this.logger = logger;
|
|
93
|
+
this.jsonParameters = parameters;
|
|
94
|
+
|
|
95
|
+
this.regexes = {
|
|
104
96
|
keywordUsage: null,
|
|
105
97
|
keywordInit: null,
|
|
106
98
|
fnDetect: null
|
|
107
99
|
};
|
|
108
100
|
|
|
109
|
-
this.missingJSONParams
|
|
110
|
-
|
|
111
|
-
|
|
101
|
+
this.missingJSONParams = [];
|
|
112
102
|
|
|
113
103
|
// Setup
|
|
114
104
|
this.setupRegexes();
|
|
115
|
-
|
|
116
105
|
}
|
|
117
106
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Utilities, one-liners
|
|
109
|
+
*/
|
|
122
110
|
EnhancedScript.prototype.getScriptPath = function() { return this.scriptPath; }
|
|
123
|
-
|
|
124
111
|
EnhancedScript.prototype.getGetterMethod = function () { return "get"; }
|
|
125
|
-
|
|
126
112
|
EnhancedScript.prototype.getSetterMethod = function () { return "set"; }
|
|
127
|
-
|
|
128
113
|
EnhancedScript.prototype.getLogger = function () { return this.logger; }
|
|
129
|
-
|
|
130
114
|
EnhancedScript.prototype.getJSXScript = function () { return this.script; }
|
|
131
|
-
|
|
132
115
|
EnhancedScript.prototype.getJSONParams = function () { return this.jsonParameters; }
|
|
133
|
-
|
|
134
116
|
EnhancedScript.prototype.jsonParametersCount = function () { return this.jsonParameters.length; }
|
|
135
|
-
|
|
136
117
|
EnhancedScript.prototype.getMissingJSONParams = function() { return this.missingJSONParams; }
|
|
137
|
-
|
|
138
118
|
EnhancedScript.prototype.countMissingJSONParams = function() { return this.getMissingJSONParams().length; }
|
|
139
|
-
|
|
140
119
|
EnhancedScript.prototype.getKeyword = function () { return this.keyword; }
|
|
141
|
-
|
|
142
120
|
EnhancedScript.prototype.getFnArgsKeyword = function () { return this.fnArgsKeyword; }
|
|
143
|
-
|
|
144
121
|
EnhancedScript.prototype.getRegex = function (key) { return this.regexes[key]; }
|
|
145
122
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
EnhancedScript.prototype.setupRegexes = function () {
|
|
176
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Get Default Value
|
|
125
|
+
* @description Retrieves a default value parameter based on a key.
|
|
126
|
+
* @param key (String)("string"|"number"|"array"|"object"|"null"|"function") The key to the required default parameter. Defaults to "null".
|
|
127
|
+
* @returns default The value from this.defaults array.
|
|
128
|
+
*/
|
|
129
|
+
EnhancedScript.prototype.getDefaultValue = function(key) { return key in this.defaults ? this.defaults[key] : this.defaults[this.defaults.global]; }
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Add Missing JSON Parameter
|
|
133
|
+
* =====================
|
|
134
|
+
* @description Adds an object with the key of a parameter being used in JSX code but with no default in the JSON Asset.
|
|
135
|
+
* @param nxMatch (Object) The object to add to the missing array.
|
|
136
|
+
* Required format:
|
|
137
|
+
* {
|
|
138
|
+
* key: string
|
|
139
|
+
* isVar: boolean
|
|
140
|
+
* isFn: boolean
|
|
141
|
+
* needsDefault: boolean.
|
|
142
|
+
* }
|
|
143
|
+
* @returns object The recently added object.
|
|
144
|
+
*/
|
|
145
|
+
EnhancedScript.prototype.addToMissingJsonParameter = function(nxMatch) { return this.missingJSONParams.push(nxMatch); }
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* End one-liners
|
|
149
|
+
*/
|
|
150
|
+
EnhancedScript.prototype.setupRegexes = function() {
|
|
177
151
|
this.regexes.searchUsageByMethod = (method = "set", flags = "g") => {
|
|
178
152
|
const str = `(?<!(?:[\\/\\s]))(?<!(?:[\\*\\s]))(?:\\s*${this.getKeyword()}\\s*\\.)\\s*(${method})\\s*(?:\\()(?:["']{1})([a-zA-Z0-9._-]+)(?:["']{1})(?:\\))`;
|
|
179
153
|
return this.buildRegex(str, flags);
|
|
@@ -182,59 +156,54 @@ const wrapEnhancedScript = ({ dest, src, parameters = [], keyword, defaults, /*
|
|
|
182
156
|
// Find instances of a function inside a single-line string.
|
|
183
157
|
this.regexes.fnDetect = new RegExp(/(?:(?:(?:function *(?:[a-zA-Z0-9_]+)?) *(?:\((?:.*)\)) *(?:\{(?:.*)\}))|(?:(?:.*) *(?:=>) *(?:\{)(?:.*?)?\}))/);
|
|
184
158
|
|
|
185
|
-
|
|
186
159
|
// This regex will detect a self-invoking function like (function(){})() and will catch the invoking parameters in a single string for further inspection.
|
|
187
160
|
this.regexes.selfInvokingFn = new RegExp(/(?:(?:^\() *(?:.*?)(?:} *\)))(?: *(?:\() *(.*?) *(?:\) *$))/);
|
|
188
161
|
}
|
|
189
162
|
|
|
190
|
-
EnhancedScript.prototype.escapeForRegex = function
|
|
163
|
+
EnhancedScript.prototype.escapeForRegex = function(str) {
|
|
191
164
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
192
165
|
}
|
|
193
166
|
|
|
194
|
-
EnhancedScript.prototype.stripComments = function (templateLiteral)
|
|
167
|
+
EnhancedScript.prototype.stripComments = function (templateLiteral) {
|
|
195
168
|
return templateLiteral.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm, '');
|
|
196
169
|
}
|
|
197
170
|
|
|
198
|
-
EnhancedScript.prototype.buildRegex = function(templateLiteral, flags)
|
|
171
|
+
EnhancedScript.prototype.buildRegex = function(templateLiteral, flags) {
|
|
199
172
|
return new RegExp(this.stripComments(templateLiteral).replace(/(\r\n|r\|\n|\s)/gm, ''), flags);
|
|
200
173
|
}
|
|
201
174
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Parse method from parameter
|
|
177
|
+
* @description Given a parameter detect whether it should be casted as a function in the final argument injection.
|
|
178
|
+
* @param param (string|number|boolean|null|object|array) The parameter to parse a method from.
|
|
179
|
+
* @return bool (Boolean) If a method is detected then it's stripped from String quotes, else it's returned in it's original type.
|
|
207
180
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if(typeof param == "string") {
|
|
181
|
+
EnhancedScript.prototype.isMethod = function (param) {
|
|
182
|
+
if (typeof param == "string") {
|
|
211
183
|
return (param.match(this.getRegex("fnDetect")) ? true : false);
|
|
212
184
|
}
|
|
213
185
|
return false
|
|
214
186
|
}
|
|
215
187
|
|
|
216
|
-
EnhancedScript.prototype.parseMethod = function (parameter)
|
|
188
|
+
EnhancedScript.prototype.parseMethod = function (parameter) {
|
|
217
189
|
const selfInvokingFn = matchAll(parameter.value, this.getRegex('selfInvokingFn'));
|
|
218
|
-
if (
|
|
190
|
+
if (selfInvokingFn ) {
|
|
219
191
|
this.getLogger().log(Array.from(selfInvokingFn));
|
|
220
192
|
return this.parseMethodWithArgs(parameter);
|
|
221
193
|
}
|
|
222
194
|
return parameter.value;
|
|
223
195
|
}
|
|
224
196
|
|
|
225
|
-
EnhancedScript.prototype.matchAsJSONParameterKey = function
|
|
197
|
+
EnhancedScript.prototype.matchAsJSONParameterKey = function( key ) {
|
|
226
198
|
const parameterMatch = this.getJSONParams().find(o => o.key == key);
|
|
227
|
-
|
|
228
199
|
return parameterMatch ? parameterMatch.value : key;
|
|
229
200
|
}
|
|
230
201
|
|
|
231
|
-
EnhancedScript.prototype.parseMethodWithArgs = function (parameter)
|
|
202
|
+
EnhancedScript.prototype.parseMethodWithArgs = function (parameter) {
|
|
232
203
|
let value = parameter.value;
|
|
233
|
-
|
|
234
204
|
const methodArgs = matchAll(parameter.value, this.getRegex('searchUsageByMethod')('arg', "gm")).toArray();
|
|
235
205
|
|
|
236
|
-
if(
|
|
237
|
-
|
|
206
|
+
if (methodArgs.length > 0 ) {
|
|
238
207
|
this.getLogger().log("We found a self-invoking method with arguments!");
|
|
239
208
|
this.getLogger().log(JSON.stringify(methodArgs));
|
|
240
209
|
const foundArgument = methodArgs.filter( argMatch => {
|
|
@@ -245,14 +214,11 @@ const wrapEnhancedScript = ({ dest, src, parameters = [], keyword, defaults, /*
|
|
|
245
214
|
});
|
|
246
215
|
|
|
247
216
|
|
|
248
|
-
if(
|
|
217
|
+
if (foundArgument) {
|
|
249
218
|
// Search if argument is present in JSON and has `arguments` array to match against the results.
|
|
250
219
|
// And do a replacement with either the found argument on the array or a global default value.
|
|
251
|
-
|
|
252
220
|
let argReplacement = parameter.arguments && parameter.arguments.find(o => o.key == arg).value || this.getStringifiedDefaultValue(this.defaults.global);
|
|
253
|
-
|
|
254
221
|
const fullMatchRegex = this.buildRegex(this.escapeForRegex(fullMatch), "gm");
|
|
255
|
-
|
|
256
222
|
value = parameter.value.replace(fullMatchRegex, argReplacement);
|
|
257
223
|
}
|
|
258
224
|
}
|
|
@@ -260,29 +226,28 @@ const wrapEnhancedScript = ({ dest, src, parameters = [], keyword, defaults, /*
|
|
|
260
226
|
return value;
|
|
261
227
|
}
|
|
262
228
|
|
|
263
|
-
EnhancedScript.prototype.detectValueType = function (parameter)
|
|
229
|
+
EnhancedScript.prototype.detectValueType = function (parameter) {
|
|
264
230
|
return this.isMethod(parameter.value) ? this.parseMethod(parameter) : JSON.stringify(parameter.value);
|
|
265
231
|
}
|
|
266
232
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
EnhancedScript.prototype.getStringifiedDefaultValue = function (key)
|
|
233
|
+
/**
|
|
234
|
+
* Get Default Value as String
|
|
235
|
+
* @description Retrieves a default value parameter based on a key.
|
|
236
|
+
* @param key (String)("string"|"number"|"array"|"object"|"null"|"function") The key to the required default parameter. Defaults to "null".
|
|
237
|
+
* @returns default (String) A template literal string with the embedded default parameter. If it's a string then it's wrapped with quotes.
|
|
238
|
+
*/
|
|
239
|
+
EnhancedScript.prototype.getStringifiedDefaultValue = function (key) {
|
|
274
240
|
return JSON.stringify(this.getDefaultValue(key))
|
|
275
241
|
}
|
|
276
242
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
EnhancedScript.prototype.stripCommentsFromScript = function (script) {
|
|
243
|
+
/**
|
|
244
|
+
* Strip comment blocks from Script [EXPERIMENTAL]
|
|
245
|
+
* ================================
|
|
246
|
+
* @description Removes /* * / comments from script to avoid mismatching occurrences.
|
|
247
|
+
* @param script (String) The target script to strip.
|
|
248
|
+
* @returns string (String) A one-line version of the original script without comment blocks.
|
|
249
|
+
*/
|
|
250
|
+
EnhancedScript.prototype.stripCommentsFromScript = function (script) {
|
|
286
251
|
// https://levelup.gitconnected.com/advanced-regex-find-and-remove-multi-line-comments-in-your-code-c162ba6e5811
|
|
287
252
|
return script
|
|
288
253
|
.replace(/\n/g, " ")
|
|
@@ -292,29 +257,25 @@ const wrapEnhancedScript = ({ dest, src, parameters = [], keyword, defaults, /*
|
|
|
292
257
|
}
|
|
293
258
|
|
|
294
259
|
/*
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
EnhancedScript.prototype.findMissingMatchesInJSX = function () {
|
|
309
|
-
|
|
260
|
+
* End Utilities
|
|
261
|
+
*/
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Find Missing Matches in JSX Script
|
|
265
|
+
* ====================
|
|
266
|
+
* @description RegEx Searches a given JSX script to find occurences and saves an object with keys
|
|
267
|
+
* @param script (String) JSX script to find occurences in.
|
|
268
|
+
* @param regex (Object) RegEx object to match against JSX script.
|
|
269
|
+
* @param parameters (Array<Object>) Array with the parameters to compare against the matches.
|
|
270
|
+
* @return bool (Boolean) Whether or not there are any variables to inject. Defaults to false.
|
|
271
|
+
*/
|
|
272
|
+
EnhancedScript.prototype.findMissingMatchesInJSX = function () {
|
|
310
273
|
const script = this.stripCommentsFromScript(this.getJSXScript());
|
|
311
274
|
|
|
312
275
|
// Parse all occurrences of the usage of NX on the provided script.
|
|
313
|
-
|
|
314
276
|
const nxMatches = matchAll(script, this.getRegex("searchUsageByMethod")("get", "gm")).toArray();
|
|
315
277
|
|
|
316
278
|
if (nxMatches && nxMatches.length > 0 ) {
|
|
317
|
-
|
|
318
279
|
nxMatches.forEach( match => {
|
|
319
280
|
const keyword = match[2];
|
|
320
281
|
|
|
@@ -324,28 +285,28 @@ const wrapEnhancedScript = ({ dest, src, parameters = [], keyword, defaults, /*
|
|
|
324
285
|
isFn: false,
|
|
325
286
|
value: this.getDefaultValue(match.default ? match.default : this.defaults.global)
|
|
326
287
|
};
|
|
327
|
-
if (
|
|
288
|
+
if (this.getJSONParams().filter( o => o.key == nxMatch.key ).length == 0) { // If the parameter doesn't have a value defined in JSON
|
|
328
289
|
this.addToMissingJsonParameter(nxMatch);
|
|
329
290
|
}
|
|
330
|
-
|
|
331
291
|
});
|
|
332
292
|
}
|
|
293
|
+
|
|
333
294
|
const missingJSONParameters = this.countMissingJSONParams();
|
|
334
|
-
if(
|
|
295
|
+
if (missingJSONParameters > 0) {
|
|
335
296
|
this.getLogger().log(`[${jobID}] ${this.displayAlert()}`);
|
|
336
297
|
}
|
|
337
298
|
return missingJSONParameters > 0;
|
|
338
299
|
}
|
|
339
300
|
|
|
340
301
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
302
|
+
/**
|
|
303
|
+
* Generated Placeholder Parameters
|
|
304
|
+
* ================================
|
|
305
|
+
* @description Generates placeholder for "parameters" JSON Object based on keys from an array.
|
|
306
|
+
* @param keys (Array) Array of strings. These should be the occurences of `keyword` variable use on the JSX script.
|
|
307
|
+
*
|
|
308
|
+
* @return string (String) JSON "parameters" object.
|
|
309
|
+
*/
|
|
349
310
|
EnhancedScript.prototype.generatePlaceholderParameters = function ( ) {
|
|
350
311
|
const missingParams = this.getMissingJSONParams();
|
|
351
312
|
|
|
@@ -363,19 +324,19 @@ const wrapEnhancedScript = ({ dest, src, parameters = [], keyword, defaults, /*
|
|
|
363
324
|
`
|
|
364
325
|
}
|
|
365
326
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
327
|
+
/**
|
|
328
|
+
* Display Missing Alert
|
|
329
|
+
* =====================
|
|
330
|
+
* @description Display a log message if theres any missing parameter set on the JSON configuration but is being referred in the script.
|
|
331
|
+
*
|
|
332
|
+
* @param missingParam (Object) Missing Parameters object. See below for its construction. Must have child objects `fn` and `vars`
|
|
333
|
+
* @param showJSXWarning (Boolean) Flag for whether or not to display warning about not initializing variable in JSX script. Defaults to false.
|
|
334
|
+
* @param injectionVar (String) Variable initialized with placeholder values. Defaults to "".
|
|
335
|
+
*
|
|
336
|
+
* @return string (String) The template literal string displaying all the occurences if any.
|
|
376
337
|
*/
|
|
377
|
-
EnhancedScript.prototype.displayAlert = function ()
|
|
378
|
-
const keyword
|
|
338
|
+
EnhancedScript.prototype.displayAlert = function () {
|
|
339
|
+
const keyword = this.getKeyword();
|
|
379
340
|
|
|
380
341
|
return ` -- W A R N I N G --
|
|
381
342
|
The following parameters used in the script were NOT found on the JSON "parameters" object of your script asset ${this.getScriptPath() }
|
|
@@ -392,11 +353,11 @@ const wrapEnhancedScript = ({ dest, src, parameters = [], keyword, defaults, /*
|
|
|
392
353
|
`
|
|
393
354
|
}
|
|
394
355
|
|
|
395
|
-
EnhancedScript.prototype.injectParameters = function ()
|
|
356
|
+
EnhancedScript.prototype.injectParameters = function () {
|
|
396
357
|
return [...this.getJSONParams(), ...this.getMissingJSONParams()].map( param => {
|
|
397
358
|
let value = param.type ? this.getStringifiedDefaultValue(param.type) : this.getDefaultValue(this.defaults.global);
|
|
398
359
|
|
|
399
|
-
if(
|
|
360
|
+
if (param.value ) {
|
|
400
361
|
value = this.detectValueType(param);
|
|
401
362
|
}
|
|
402
363
|
|
|
@@ -404,65 +365,63 @@ const wrapEnhancedScript = ({ dest, src, parameters = [], keyword, defaults, /*
|
|
|
404
365
|
}).join("\n");
|
|
405
366
|
}
|
|
406
367
|
|
|
407
|
-
EnhancedScript.prototype.buildParameterConfigurator = function ()
|
|
408
|
-
|
|
368
|
+
EnhancedScript.prototype.buildParameterConfigurator = function () {
|
|
409
369
|
const defaultGlobalValue = this.getStringifiedDefaultValue( this.defaults.global );
|
|
410
370
|
// const defaultFnValue = this.getDefaultValue( this.defaults.function );
|
|
411
371
|
const createParameterConfigurator = () => `
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
372
|
+
function ParameterConfigurator () {
|
|
373
|
+
this.params = [];
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
ParameterConfigurator.prototype.set = function (k, v) {
|
|
377
|
+
this.params.push({
|
|
378
|
+
key: k,
|
|
379
|
+
value: v
|
|
380
|
+
});
|
|
381
|
+
};
|
|
415
382
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
ParameterConfigurator.prototype.call = function ( key, args ) {
|
|
424
|
-
for (var i = 0; i < this.params.length; i++) {
|
|
425
|
-
if (this.params[i].key == key) {
|
|
426
|
-
if (typeof this.params[i].value == "function") return this.params[i].value.apply(this, args && args.length > 0 ? args : []);
|
|
383
|
+
ParameterConfigurator.prototype.call = function ( key, args ) {
|
|
384
|
+
for (var i = 0; i < this.params.length; i++) {
|
|
385
|
+
if (this.params[i].key == key) {
|
|
386
|
+
if (typeof this.params[i].value == "function") return this.params[i].value.apply(this, args && args.length > 0 ? args : []);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return null;
|
|
427
390
|
}
|
|
428
|
-
}
|
|
429
|
-
return null;
|
|
430
|
-
}
|
|
431
391
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
392
|
+
ParameterConfigurator.prototype.get = function ( key, args ) {
|
|
393
|
+
for (var i = 0; i < this.params.length; i++) {
|
|
394
|
+
if (this.params[i].key == key) {
|
|
395
|
+
if (typeof this.params[i].value == "function") return this.call(key, args || []);
|
|
396
|
+
return this.params[i].value;
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
return ${ defaultGlobalValue }
|
|
437
400
|
};
|
|
438
|
-
|
|
439
|
-
return ${ defaultGlobalValue }
|
|
440
|
-
};
|
|
441
|
-
var ${ this.getKeyword() } = new ParameterConfigurator();
|
|
401
|
+
var ${ this.getKeyword() } = new ParameterConfigurator();
|
|
442
402
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
`;
|
|
403
|
+
// Parameter injection from job configuration
|
|
404
|
+
${ this.injectParameters() }
|
|
405
|
+
`;
|
|
446
406
|
|
|
447
407
|
return createParameterConfigurator();
|
|
448
408
|
}
|
|
449
409
|
|
|
450
|
-
EnhancedScript.prototype.build = function ()
|
|
410
|
+
EnhancedScript.prototype.build = function () {
|
|
451
411
|
this.findMissingMatchesInJSX();
|
|
452
412
|
|
|
453
413
|
// Et voilà!
|
|
454
414
|
const enhancedScript = `(function() {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
415
|
+
${this.buildParameterConfigurator()}
|
|
416
|
+
${this.getJSXScript()}
|
|
417
|
+
})();\n`;
|
|
418
|
+
|
|
458
419
|
// do not log the script (can be uncommented for debugging)
|
|
459
420
|
// this.getLogger().log(enhancedScript);
|
|
460
|
-
|
|
461
421
|
return enhancedScript;
|
|
462
422
|
}
|
|
463
423
|
|
|
464
424
|
const enhancedScript = new EnhancedScript(dest, src, parameters, keyword, defaults, jobID, settings.logger);
|
|
465
|
-
|
|
466
425
|
return enhancedScript.build();
|
|
467
426
|
}
|
|
468
427
|
|
|
@@ -477,15 +436,15 @@ module.exports = (job, settings) => {
|
|
|
477
436
|
case 'video':
|
|
478
437
|
case 'audio':
|
|
479
438
|
case 'image':
|
|
480
|
-
data.push(wrapFootage(
|
|
439
|
+
data.push(wrapFootage(job, settings, asset));
|
|
481
440
|
break;
|
|
482
441
|
|
|
483
442
|
case 'data':
|
|
484
|
-
data.push(wrapData(asset));
|
|
443
|
+
data.push(wrapData(job, settings, asset));
|
|
485
444
|
break;
|
|
486
445
|
|
|
487
446
|
case 'script':
|
|
488
|
-
data.push(wrapEnhancedScript(
|
|
447
|
+
data.push(wrapEnhancedScript(job, settings, asset));
|
|
489
448
|
break;
|
|
490
449
|
}
|
|
491
450
|
});
|