11import { log } from '@create-figma-plugin/common'
22import fs from 'fs-extra'
3- import { join , resolve } from 'path'
3+ import { join } from 'path'
44
5- import { copyTemplateAsync } from './utilities/copy-template-async.js'
5+ import { copyPluginTemplateAsync } from './utilities/copy-plugin -template-async.js'
66import { installDependenciesAsync } from './utilities/install-dependencies-async.js'
77import { interpolateValuesIntoFilesAsync } from './utilities/interpolate-values-into-files-async.js'
8+ import { readPluginTemplateNamesAsync } from './utilities/read-template-names-async.js'
89import { resolveLatestStableVersions } from './utilities/resolve-latest-stable-versions.js'
910import { createDefaultSettings } from './utilities/settings/create-default-settings.js'
1011import { promptForUserInputAsync } from './utilities/settings/prompt-for-user-input-async.js'
@@ -20,14 +21,11 @@ export async function createFigmaPluginAsync(options: {
2021 await throwIfDirectoryExistsAsync ( join ( process . cwd ( ) , name ) )
2122 }
2223 if ( typeof template !== 'undefined' ) {
23- const templateDirectory = resolve (
24- __dirname ,
25- '..' ,
26- 'plugin-templates' ,
27- template
28- )
29- if ( ( await fs . pathExists ( templateDirectory ) ) === false ) {
30- throw new Error ( `Invalid template: ${ template } ` )
24+ const templateNames = await readPluginTemplateNamesAsync ( )
25+ if ( templateNames . indexOf ( template ) === - 1 ) {
26+ throw new Error (
27+ `Template must be one of "${ templateNames . join ( '", "' ) } "`
28+ )
3129 }
3230 }
3331 log . info ( 'Scaffolding a new plugin...' )
@@ -36,8 +34,8 @@ export async function createFigmaPluginAsync(options: {
3634 : await promptForUserInputAsync ( { name, template } )
3735 const pluginDirectoryPath = join ( process . cwd ( ) , settings . name )
3836 await throwIfDirectoryExistsAsync ( pluginDirectoryPath )
39- log . info ( ' Copying template...' )
40- await copyTemplateAsync ( pluginDirectoryPath , settings . template )
37+ log . info ( ` Copying " ${ settings . template } " template ...` )
38+ await copyPluginTemplateAsync ( pluginDirectoryPath , settings . template )
4139 const versions = await resolveLatestStableVersions ( )
4240 await interpolateValuesIntoFilesAsync ( pluginDirectoryPath , {
4341 ...settings ,
0 commit comments