Skip to content

Commit

Permalink
Allow local directories to be passed to --template as relative paths. (
Browse files Browse the repository at this point in the history
…#35645)

* Check if passed template is a directory and resolve it.

* Linting fixes.
  • Loading branch information
ryanwelcher authored Oct 14, 2021
1 parent 89deab1 commit 13a6043
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 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 @@ -124,6 +126,9 @@ const getBlockTemplate = async ( templateName ) => {
}

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

0 comments on commit 13a6043

Please sign in to comment.