@nexrender/core 1.49.3 → 1.49.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexrender/core",
3
- "version": "1.49.3",
3
+ "version": "1.49.4",
4
4
  "main": "src/index.js",
5
5
  "author": "Inlife",
6
6
  "homepage": "https://www.nexrender.com",
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "06db22fa02101417e0e6574d97a07b950c5ac3c4"
41
+ "gitHead": "7dfa1bf539d3a9d006a987ca7dbb59e4454bbaba"
42
42
  }
@@ -1,12 +1,60 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
3
  const mkdirp = require('mkdirp')
4
+
4
5
  const patchedDefault = require('../assets/commandLineRenderer-default.jsx')
5
6
  const patched2022 = require('../assets/commandLineRenderer-2022.jsx')
6
7
 
7
8
  const writeTo = (data, dst) => fs.writeFileSync(dst, data)
8
9
  const copyTo = (src, dst) => fs.writeFileSync(dst, fs.readFileSync(src))
9
10
 
11
+ const PATCH_STATUS = {
12
+ NOT_PATCHED: 0,
13
+ PATCHED: 1,
14
+ OUTDATED: 2,
15
+ }
16
+
17
+ /**
18
+ * Get the correct patched content for the After Effects command line renderer
19
+ * @param {string} binary
20
+ * @returns {string}
21
+ */
22
+ const getContentForPatch = (binary) => {
23
+ const afterEffects = path.dirname(binary)
24
+ const afterEffectsYearMatch = afterEffects.match(/(20[0-9]{2})/);
25
+
26
+ if (afterEffectsYearMatch && afterEffectsYearMatch[0] >= "2022") {
27
+ return patched2022;
28
+ }
29
+
30
+ return patchedDefault;
31
+ }
32
+
33
+ /**
34
+ * Get the status of the patch for the After Effects command line renderer
35
+ * @param {string} binary
36
+ * @returns {number} PATCH_STATUS
37
+ */
38
+ const getPatchStatus = (binary) => {
39
+ const afterEffects = path.dirname(binary)
40
+ const targetScript = 'commandLineRenderer.jsx'
41
+ const originalFile = path.join(afterEffects, 'Scripts', 'Startup', targetScript)
42
+ const data = fs.readFileSync(originalFile, 'utf8')
43
+
44
+ if (data.indexOf('nexrender-patch') === -1) {
45
+ return PATCH_STATUS.NOT_PATCHED
46
+ }
47
+
48
+ const patchedMatch = data.match(/nexrender-patch-v([0-9.]+)/)
49
+ const existingMatch = getContentForPatch(binary).match(/nexrender-patch-v([0-9.]+)/)
50
+
51
+ if (patchedMatch[1] !== existingMatch[1]) {
52
+ return PATCH_STATUS.OUTDATED
53
+ }
54
+
55
+ return PATCH_STATUS.PATCHED
56
+ }
57
+
10
58
  /**
11
59
  * Attempt to patch the After Effect's command line renderer
12
60
  * @type {Object}
@@ -14,31 +62,57 @@ const copyTo = (src, dst) => fs.writeFileSync(dst, fs.readFileSync(src))
14
62
  module.exports = (settings) => {
15
63
  const targetScript = 'commandLineRenderer.jsx';
16
64
 
65
+ const patched = getContentForPatch(settings.binary)
17
66
  const afterEffects = path.dirname(settings.binary)
18
- const afterEffectsYearMatch = afterEffects.match(/(20[0-9]{2})/);
19
-
20
- let patched = patchedDefault;
21
- if (afterEffectsYearMatch && afterEffectsYearMatch[0] >= "2022") {
22
- patched = patched2022;
23
- }
24
-
25
67
  const originalFile = path.join(afterEffects, 'Scripts', 'Startup', targetScript)
26
68
  const backupFile = path.join(afterEffects, 'Backup.Scripts', 'Startup', targetScript)
27
69
 
28
- const data = fs.readFileSync(originalFile, 'utf8')
29
- settings.logger.log('checking After Effects command line renderer patch...')
30
-
31
70
  /* check if file has been patched already */
32
71
  /* by looking for 'nexrender' in the text anywhere */
33
- if (data.indexOf('nexrender-patch') !== -1) {
34
- settings.logger.log('command line patch already is in place')
72
+ settings.logger.log('checking After Effects command line renderer patch...')
73
+ const patchStatus = getPatchStatus(settings.binary)
74
+
75
+ switch (patchStatus) {
76
+ // if not patched, then we need to patch it
77
+ case PATCH_STATUS.NOT_PATCHED:
78
+ settings.logger.log('backing up original command line script to:')
79
+ settings.logger.log(' - ' + backupFile)
80
+
81
+ try {
82
+ mkdirp.sync(path.join(afterEffects, 'Backup.Scripts', 'Startup'))
83
+ copyTo(originalFile, backupFile)
84
+
85
+ settings.logger.log('patching the command line script')
86
+ fs.chmodSync(originalFile, '755');
87
+ writeTo(patched, originalFile)
88
+
89
+ settings.track('Init Patch Install Succeeded')
90
+ } catch (err) {
91
+ settings.trackSync('Init Patch Install Failed')
92
+
93
+ if (err.code == 'EPERM') {
94
+ settings.logger.log('\n\n -- E R R O R --\n');
95
+ settings.logger.log('you need to run application with admin priviledges once');
96
+ settings.logger.log('to install Adobe After Effects commandLineRenderer.jsx patch\n');
97
+
98
+ if (process.platform == 'win32') {
99
+ settings.logger.log('reading/writing inside Program Files folder on windows is blocked')
100
+ settings.logger.log('please run nexrender with Administrator Privilidges only ONE TIME, to install the patch\n\n')
101
+ } else {
102
+ settings.logger.log('you might need to try to run nexrender with "sudo" only ONE TIME to install the patch\n\n')
103
+ }
35
104
 
36
- const patchedMatch = patched.match(/nexrender-patch-v([0-9.]+)/)
37
- const existingMatch = data.match(/nexrender-patch-v([0-9.]+)/)
105
+ process.exit(2);
106
+ } else {
107
+ throw err
108
+ }
109
+ }
110
+ break;
38
111
 
39
- if (patchedMatch[1] !== existingMatch[1]) {
112
+ // if patched, then we need to check if it's outdated
113
+ case PATCH_STATUS.OUTDATED:
114
+ settings.logger.log('out-of-date version of the commandLineRenderer.jsx patch is detected, attepmting to update')
40
115
  try {
41
- settings.logger.log('out-of-date version of the commandLineRenderer.jsx patch is detected, attepmting to update')
42
116
  settings.track('Init Patch Update Succeeded')
43
117
  writeTo(patched, originalFile)
44
118
  } catch (err) {
@@ -61,45 +135,22 @@ module.exports = (settings) => {
61
135
  throw err
62
136
  }
63
137
  }
64
- }
65
-
66
- if (settings.forceCommandLinePatch) {
67
- settings.logger.log('forced rewrite of command line patch')
68
- settings.track('Init Patch Forced')
69
- writeTo(patched, originalFile)
70
- }
71
- } else {
72
- settings.logger.log('backing up original command line script to:')
73
- settings.logger.log(' - ' + backupFile)
74
-
75
- try {
76
- mkdirp.sync(path.join(afterEffects, 'Backup.Scripts', 'Startup'))
77
- copyTo(originalFile, backupFile)
78
-
79
- settings.logger.log('patching the command line script')
80
- fs.chmodSync(originalFile, '755');
81
- writeTo(patched, originalFile)
82
-
83
- settings.track('Init Patch Install Succeeded')
84
- } catch (err) {
85
- settings.trackSync('Init Patch Install Failed')
86
-
87
- if (err.code == 'EPERM') {
88
- settings.logger.log('\n\n -- E R R O R --\n');
89
- settings.logger.log('you need to run application with admin priviledges once');
90
- settings.logger.log('to install Adobe After Effects commandLineRenderer.jsx patch\n');
91
-
92
- if (process.platform == 'win32') {
93
- settings.logger.log('reading/writing inside Program Files folder on windows is blocked')
94
- settings.logger.log('please run nexrender with Administrator Privilidges only ONE TIME, to install the patch\n\n')
95
- } else {
96
- settings.logger.log('you might need to try to run nexrender with "sudo" only ONE TIME to install the patch\n\n')
97
- }
138
+ break;
139
+
140
+ // if patched and up-to-date, then we're good, unless forced
141
+ case PATCH_STATUS.PATCHED:
142
+ settings.logger.log('command line patch already is in place')
98
143
 
99
- process.exit(2);
100
- } else {
101
- throw err
144
+ if (settings.forceCommandLinePatch) {
145
+ settings.logger.log('forced rewrite of command line patch')
146
+ settings.track('Init Patch Forced')
147
+ writeTo(patched, originalFile)
102
148
  }
103
- }
149
+
150
+ break;
104
151
  }
105
152
  }
153
+
154
+ module.exports.PATCH_STATUS = PATCH_STATUS
155
+ module.exports.getPatchStatus = getPatchStatus
156
+ module.exports.getContentForPatch = getContentForPatch
@@ -24,7 +24,7 @@ describe('tasks/script/EnhancedScript', () => {
24
24
  key: 'unittest_defined_parameter',
25
25
  value: 'VALUE'
26
26
  },
27
- ], 'NX', {}, 'unittest', console);
27
+ ], 'NX', {}, 'unittest', { log: () => {} });
28
28
 
29
29
  const anyMissing = enhancedScript.findMissingMatchesInJSX();
30
30
  expect(anyMissing).true;
@@ -94,7 +94,7 @@ describe('tasks/script/EnhancedScript', () => {
94
94
  }
95
95
  ]
96
96
  }
97
- ], 'NX', {}, 'unittest', console);
97
+ ], 'NX', {}, 'unittest', { log: () => {} });
98
98
 
99
99
  const anyMissing = enhancedScript.findMissingMatchesInJSX();
100
100
  expect(anyMissing).false;
@@ -0,0 +1,66 @@
1
+ const fs = require('fs')
2
+ const assert = require('assert').strict;
3
+ const patch = require('../src/helpers/patch')
4
+
5
+ describe('helpers/patch', function() {
6
+ // mock the after effects binary path
7
+ let mockSettings = { logger: { log: () => {} }, trackSync: () => {}, track: () => {} }
8
+ let mockBinaryDir = __dirname + '/patch-test'
9
+ let mockBinaryPath = mockBinaryDir + '/After Effects 2022'
10
+ let mockBinaryFile = mockBinaryPath + '/aerender'
11
+ let mockBinaryScript = mockBinaryPath + '/Scripts/Startup/commandLineRenderer.jsx'
12
+ let mockBackupDir = mockBinaryPath + '/Backup.Scripts/Startup/'
13
+ let mockBinaryPatched = mockBackupDir + 'commandLineRenderer.jsx'
14
+
15
+ // prepare after effects binary directory
16
+ fs.mkdirSync(mockBinaryDir, { recursive: true })
17
+ fs.mkdirSync(mockBinaryPath, { recursive: true })
18
+ fs.mkdirSync(mockBinaryPath + '/Scripts', { recursive: true })
19
+ fs.mkdirSync(mockBinaryPath + '/Scripts/Startup', { recursive: true })
20
+ fs.writeFileSync(mockBinaryFile, 'binary')
21
+ fs.writeFileSync(mockBinaryScript, 'original')
22
+
23
+ it('should choose the correct patched content for different AE versions', function(done) {
24
+ assert(patch.getContentForPatch('2022/bin').indexOf('in_mfr_enable') !== -1)
25
+ assert(patch.getContentForPatch('2021/bin').indexOf('in_mfr_enable') === -1)
26
+ done()
27
+ })
28
+
29
+ it('should correctly return NOT_PATCHED', function(done) {
30
+ assert.strictEqual(patch.getPatchStatus(mockBinaryFile), patch.PATCH_STATUS.NOT_PATCHED)
31
+ done()
32
+ })
33
+
34
+ it('should apply the patch correctly', function(done) {
35
+ patch({ binary: mockBinaryFile, ...mockSettings })
36
+ assert.strictEqual(patch.getPatchStatus(mockBinaryFile), patch.PATCH_STATUS.PATCHED)
37
+ assert.strictEqual(fs.readFileSync(mockBinaryScript, 'utf8').indexOf('nexrender-patch-v') !== -1, true)
38
+ // check backup exists
39
+ assert.strictEqual(fs.existsSync(mockBinaryPatched), true)
40
+ assert.strictEqual(fs.readFileSync(mockBinaryPatched, 'utf8').indexOf('nexrender-patch-v') === -1, true)
41
+ done()
42
+ })
43
+
44
+ it('should correctly return PATCHED', function(done) {
45
+ assert.strictEqual(patch.getPatchStatus(mockBinaryFile), patch.PATCH_STATUS.PATCHED)
46
+ done()
47
+ })
48
+
49
+ it('should correctly return OUTDATED', function(done) {
50
+ fs.writeFileSync(mockBinaryScript, 'nexrender-patch-v0.0.0\n' + fs.readFileSync(mockBinaryScript, 'utf8'))
51
+ assert.strictEqual(patch.getPatchStatus(mockBinaryFile), patch.PATCH_STATUS.OUTDATED)
52
+ done()
53
+ })
54
+
55
+ // Cleanup after tests
56
+ after(function() {
57
+ // Remove created files and directories
58
+ fs.unlinkSync(mockBinaryScript)
59
+ fs.unlinkSync(mockBinaryFile)
60
+ fs.rmdirSync(mockBinaryPath + '/Scripts/Startup', { recursive: true })
61
+ fs.rmdirSync(mockBinaryPath + '/Scripts', { recursive: true })
62
+ fs.rmdirSync(mockBinaryPath, { recursive: true })
63
+ fs.rmdirSync(mockBinaryDir, { recursive: true })
64
+
65
+ })
66
+ });
package/test.js ADDED
@@ -0,0 +1 @@
1
+ require('./test/unit-patch')