-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding SDK POT file generation for Gutenberg blocks. #30303
Changes from all commits
91ec6ad
c5abed1
0d13351
fe27339
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ const path = require( 'path' ); | |||||
|
||||||
const isCalypsoClient = process.env.CALYPSO_CLIENT === 'true'; | ||||||
const isBrowser = isCalypsoClient || 'true' === process.env.TARGET_BROWSER; | ||||||
const outputDir = process.env.CALYPSO_SDK_OUTPUT_DIR || false; | ||||||
|
||||||
const modules = isBrowser ? false : 'commonjs'; // Use commonjs for Node | ||||||
const codeSplit = require( './server/config' ).isEnabled( 'code-splitting' ); | ||||||
|
@@ -12,6 +13,38 @@ const targets = isBrowser | |||||
? { browsers: [ 'last 2 versions', 'Safari >= 10', 'iOS >= 10', 'ie >= 11' ] } | ||||||
: { node: 'current' }; | ||||||
|
||||||
const extensionOverrides = [ | ||||||
[ | ||||||
'@wordpress/import-jsx-pragma', | ||||||
{ | ||||||
scopeVariable: 'createElement', | ||||||
source: '@wordpress/element', | ||||||
isDefault: false, | ||||||
}, | ||||||
], | ||||||
[ | ||||||
'@babel/transform-react-jsx', | ||||||
{ | ||||||
pragma: 'createElement', | ||||||
}, | ||||||
], | ||||||
]; | ||||||
|
||||||
// The output directory is set when SDK runs, so we only set the POT generator override in that case. | ||||||
if ( outputDir ) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another (maybe easier to read since code stays in one place?) way to structure this would be by using plugins: compact( [
outputDir && [
'@wordpress/babel-plugin-makepot',
{
...
}
],
[
'@wordpress/import-jsx-pragma',
{
scopeVariable: 'createElement',
source: '@wordpress/element',
isDefault: false,
},
],
[
'@babel/transform-react-jsx',
{
pragma: 'createElement',
},
],
] ) You can see similar pattern here: Lines 312 to 313 in ecf929d
...but that's just up to code-stylistic choices. :-) |
||||||
extensionOverrides.unshift( [ | ||||||
'@wordpress/babel-plugin-makepot', | ||||||
{ | ||||||
output: path.join( outputDir, 'extensions.pot' ), | ||||||
headers: { | ||||||
'content-type': 'text/plain; charset=UTF-8', | ||||||
'x-generator': 'calypso', | ||||||
'plural-forms': 'nplurals=2; plural=n == 1 ? 0 : 1;', | ||||||
}, | ||||||
}, | ||||||
] ); | ||||||
} | ||||||
|
||||||
const config = { | ||||||
presets: [ | ||||||
[ | ||||||
|
@@ -54,22 +87,7 @@ const config = { | |||||
overrides: [ | ||||||
{ | ||||||
test: './client/gutenberg/extensions', | ||||||
plugins: [ | ||||||
[ | ||||||
'@wordpress/import-jsx-pragma', | ||||||
{ | ||||||
scopeVariable: 'createElement', | ||||||
source: '@wordpress/element', | ||||||
isDefault: false, | ||||||
}, | ||||||
], | ||||||
[ | ||||||
'@babel/transform-react-jsx', | ||||||
{ | ||||||
pragma: 'createElement', | ||||||
}, | ||||||
], | ||||||
], | ||||||
plugins: extensionOverrides, | ||||||
}, | ||||||
], | ||||||
env: { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ const path = require( 'path' ); | |
const yargsModule = require( 'yargs' ); | ||
const webpack = require( 'webpack' ); | ||
|
||
// This environment variable will be used by the Babel plugin that makes POT files, see babel.config.js. | ||
process.env.CALYPSO_SDK_OUTPUT_DIR = yargsModule.argv.outputDir; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To express #30303 (comment) in a bit more compact way, how about we move this to const output = outputDir || path.join( inputDir, 'build' );
process.env.CALYPSO_SDK_OUTPUT_DIR = output; |
||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with the comment, I would still prefer the code to tell this story better by renaming the variable something less generic. Not a biggie tho if you decide to leave it like this!
Consider someone who doesn't know anything about SDK reading this line.
Maybe
hasSdkOutputDir
?