@penskemediacorp/twig-to-php-parser 1.66.4 → 1.68.0
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/index.js +37 -31
- package/lib/getConfig.js +1 -0
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -11,7 +11,7 @@ const config = getAppConfiguration( 'parser' );
|
|
|
11
11
|
* package README for supported configuration.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
function twigToPhpParser(
|
|
14
|
+
function twigToPhpParser( thisConfig = {} ) {
|
|
15
15
|
// TODO: We need some kind of wrapper here for config...or better:
|
|
16
16
|
// move this to pmc-plugins/pmc-larva and scrap this awkward JS
|
|
17
17
|
// execPhp wrapper situation, and use Larva\Config for this config.
|
|
@@ -19,33 +19,36 @@ function twigToPhpParser( config = {} ) {
|
|
|
19
19
|
let phpDir = path.join( process.cwd(), '../template-parts/patterns' );
|
|
20
20
|
let isUsingPlugin = false;
|
|
21
21
|
|
|
22
|
-
if ( 'undefined' !== typeof
|
|
23
|
-
if (
|
|
24
|
-
twigDir = path.join( process.cwd(),
|
|
22
|
+
if ( 'undefined' !== typeof thisConfig.twigDir ) {
|
|
23
|
+
if ( thisConfig.twigDir.startsWith( '.' ) ) {
|
|
24
|
+
twigDir = path.join( process.cwd(), thisConfig.twigDir );
|
|
25
25
|
} else {
|
|
26
|
-
twigDir =
|
|
26
|
+
twigDir = thisConfig.twigDir;
|
|
27
27
|
}
|
|
28
|
-
} else if ( 'undefined' !== typeof
|
|
29
|
-
if (
|
|
30
|
-
twigDir =
|
|
28
|
+
} else if ( 'undefined' !== typeof thisConfig.relativeSrcOverride ) {
|
|
29
|
+
if ( thisConfig.relativeSrcOverride.startsWith( '/' ) ) {
|
|
30
|
+
twigDir = thisConfig.relativeSrcOverride;
|
|
31
31
|
} else {
|
|
32
|
-
twigDir = path.join(
|
|
32
|
+
twigDir = path.join(
|
|
33
|
+
process.cwd(),
|
|
34
|
+
thisConfig.relativeSrcOverride
|
|
35
|
+
);
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
if ( 'undefined' !== typeof
|
|
37
|
-
isUsingPlugin =
|
|
39
|
+
if ( 'undefined' !== typeof thisConfig.isUsingPlugin ) {
|
|
40
|
+
isUsingPlugin = thisConfig.isUsingPlugin;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
if ( 'undefined' !== typeof
|
|
41
|
-
phpDir =
|
|
43
|
+
if ( 'undefined' !== typeof thisConfig.phpDir ) {
|
|
44
|
+
phpDir = thisConfig.phpDir;
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
return new Promise( ( resolve, reject ) => {
|
|
45
48
|
execPhp(
|
|
46
49
|
path.resolve( __dirname, './lib/twig-to-php-parser.php' ),
|
|
47
|
-
|
|
48
|
-
function ( error, php
|
|
50
|
+
thisConfig.phpBinaryPath,
|
|
51
|
+
function ( error, php ) {
|
|
49
52
|
if ( error ) {
|
|
50
53
|
reject( error );
|
|
51
54
|
}
|
|
@@ -54,9 +57,9 @@ function twigToPhpParser( config = {} ) {
|
|
|
54
57
|
twigDir,
|
|
55
58
|
phpDir,
|
|
56
59
|
isUsingPlugin,
|
|
57
|
-
function (
|
|
58
|
-
if (
|
|
59
|
-
reject(
|
|
60
|
+
function ( thisError, result ) {
|
|
61
|
+
if ( thisError ) {
|
|
62
|
+
reject( thisError );
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
resolve( result );
|
|
@@ -77,7 +80,7 @@ function parseIncludePath(
|
|
|
77
80
|
execPhp(
|
|
78
81
|
path.resolve( __dirname, './lib/twig-to-php-parser.php' ),
|
|
79
82
|
config.phpBinaryPath,
|
|
80
|
-
function ( error, php
|
|
83
|
+
function ( error, php ) {
|
|
81
84
|
if ( error ) {
|
|
82
85
|
reject( error );
|
|
83
86
|
}
|
|
@@ -87,9 +90,9 @@ function parseIncludePath(
|
|
|
87
90
|
patternName,
|
|
88
91
|
dataName,
|
|
89
92
|
isUsingPlugin,
|
|
90
|
-
function (
|
|
91
|
-
if (
|
|
92
|
-
reject(
|
|
93
|
+
function ( thisError, result ) {
|
|
94
|
+
if ( thisError ) {
|
|
95
|
+
reject( thisError );
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
resolve( result );
|
|
@@ -105,7 +108,7 @@ function parseSvgPath( twigSvgIncludeStr, svgName, isUsingPlugin = false ) {
|
|
|
105
108
|
execPhp(
|
|
106
109
|
path.resolve( __dirname, './lib/twig-to-php-parser.php' ),
|
|
107
110
|
config.phpBinaryPath,
|
|
108
|
-
function ( error, php
|
|
111
|
+
function ( error, php ) {
|
|
109
112
|
if ( error ) {
|
|
110
113
|
reject( error );
|
|
111
114
|
}
|
|
@@ -114,9 +117,9 @@ function parseSvgPath( twigSvgIncludeStr, svgName, isUsingPlugin = false ) {
|
|
|
114
117
|
twigSvgIncludeStr,
|
|
115
118
|
svgName,
|
|
116
119
|
isUsingPlugin,
|
|
117
|
-
function (
|
|
118
|
-
if (
|
|
119
|
-
reject(
|
|
120
|
+
function ( thisError, result ) {
|
|
121
|
+
if ( thisError ) {
|
|
122
|
+
reject( thisError );
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
resolve( result );
|
|
@@ -132,16 +135,16 @@ function parseWpAction( twigMarkup ) {
|
|
|
132
135
|
execPhp(
|
|
133
136
|
path.resolve( __dirname, './lib/twig-to-php-parser.php' ),
|
|
134
137
|
config.phpBinaryPath,
|
|
135
|
-
function ( error, php
|
|
138
|
+
function ( error, php ) {
|
|
136
139
|
if ( error ) {
|
|
137
140
|
reject( error );
|
|
138
141
|
}
|
|
139
142
|
|
|
140
143
|
php.parse_wp_action(
|
|
141
144
|
twigMarkup,
|
|
142
|
-
function (
|
|
143
|
-
if (
|
|
144
|
-
reject(
|
|
145
|
+
function ( thisError, result ) {
|
|
146
|
+
if ( thisError ) {
|
|
147
|
+
reject( thisError );
|
|
145
148
|
}
|
|
146
149
|
|
|
147
150
|
resolve( result );
|
|
@@ -161,12 +164,15 @@ module.exports = {
|
|
|
161
164
|
},
|
|
162
165
|
run: () => {
|
|
163
166
|
twigToPhpParser( config )
|
|
167
|
+
// eslint-disable-next-line no-console
|
|
164
168
|
.catch( ( e ) => console.log( e ) ) // PHP errors
|
|
165
|
-
.then( (
|
|
169
|
+
.then( () =>
|
|
170
|
+
// eslint-disable-next-line no-console
|
|
166
171
|
console.log(
|
|
167
172
|
chalk.green( 'Completed parsing Twig templates to PHP.' )
|
|
168
173
|
)
|
|
169
174
|
)
|
|
175
|
+
// eslint-disable-next-line no-console
|
|
170
176
|
.catch( ( e ) => console.log( e ) );
|
|
171
177
|
},
|
|
172
178
|
};
|
package/lib/getConfig.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@penskemediacorp/twig-to-php-parser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.68.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "laras126 <laras126@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/penske-media-corp/pmc-larva#readme",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"chalk": "^4",
|
|
27
27
|
"exec-php": "^0"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "e6d0aaafb0abefe1fa8a691911ae23b0bde14528"
|
|
30
30
|
}
|