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

Allow local directories to be passed to --template as relative paths. #35645

Merged
merged 2 commits into from
Oct 14, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Check if passed template is a directory and resolve it.
  • Loading branch information
ryanwelcher committed Oct 14, 2021
commit d41d502ef0b9f52ee61d8842f7f2249a65081768
9 changes: 8 additions & 1 deletion packages/create-block/lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
const { command } = require( 'execa' );
const glob = require( 'fast-glob' );
const { resolve } = require('path');
const { existsSync } = require('fs');
const { mkdtemp, readFile } = require( 'fs' ).promises;
const { fromPairs, isObject } = require( 'lodash' );
const npmPackageArg = require( 'npm-package-arg' );
Expand Down Expand Up @@ -117,14 +119,19 @@ const configToTemplate = async ( {
};

const getBlockTemplate = async ( templateName ) => {

if ( predefinedBlockTemplates[ templateName ] ) {
return await configToTemplate(
predefinedBlockTemplates[ templateName ]
);
}

try {
return await configToTemplate( require( templateName ) );
if ( existsSync( resolve( templateName ) ) ) {
return await configToTemplate( require( resolve( templateName ) ) )
} else {
return await configToTemplate( require( templateName ) );
}
} catch ( error ) {
if ( error instanceof CLIError ) {
throw error;
Expand Down