Skip to content
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

Create Block: Adds --target-dir flag to allow the tool to target where to scaffold #53781

Merged
merged 12 commits into from
Oct 28, 2024
Merged
Prev Previous commit
Next Next commit
Add a new parameter to allow passing the path once rather than genera…
…ting it in the function.
  • Loading branch information
ryanwelcher committed Oct 25, 2024
commit d5bb7565da3eedada79671d4cfbc3a68aa7bc5d7
18 changes: 7 additions & 11 deletions packages/create-block/lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@ const { render } = require( 'mustache' );
const { writeFile } = require( 'fs' ).promises;

const writeOutputAsset = async ( inputFile, outputFile, view ) => {
const outputFilePath = join( view.slug, 'assets', outputFile );
const outputFilePath = join( view.rootDirectory, 'assets', outputFile );
await makeDir( dirname( outputFilePath ) );
writeFile( outputFilePath, inputFile );
};

const writeOutputTemplate = async ( inputFile, outputFile, view ) => {
const outputFilePath = view.plugin
? join(
view.targetDir,
view.slug,
outputFile.replace( /\$slug/g, view.slug )
)
: outputFile;
await makeDir( dirname( outputFilePath ) );
const writeOutputTemplate = async ( inputFile, outputFile, view, path ) => {
await makeDir( path );
// If the rendered template is empty, don't write it. This is how we can conditionally add template files.
const renderedFile = render( inputFile, view );
if ( renderedFile.trim().length ) {
writeFile( outputFilePath, renderedFile );
writeFile(
join( path, outputFile.replace( /\$slug/g, view.slug ) ),
renderedFile
);
}
};

Expand Down