Skip to content

Commit

Permalink
feat: Update File Patterns & Extensions (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cahllagerfeld authored Aug 10, 2023
1 parent 5bacbe6 commit 28fd610
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webstone/gluegun",
"version": "0.0.4",
"version": "0.0.5",
"description": "A delightful toolkit for building Node-powered CLIs.",
"repository": "webstoneHQ/gluegun",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/command-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function loadCommandFromFile(file: string, options: Options = {}): Comman

// strip the extension from the end of the commandPath
command.commandPath = (options.commandPath || last(file.split('commands' + path.sep)).split(path.sep)).map((f) =>
[`${command.name}.js`, `${command.name}.ts`].includes(f) ? command.name : f,
[`${command.name}.js`, `${command.name}.ts`, `${command.name}.cjs`].includes(f) ? command.name : f,
)

// if the last two elements of the commandPath are the same, remove the last one
Expand Down
20 changes: 16 additions & 4 deletions src/loaders/plugin-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export function loadPluginFromDirectory(directory: string, options: Options = {}

const {
brand = 'gluegun',
commandFilePattern = [`*.{js,ts}`, `!*.test.{js,ts}`],
extensionFilePattern = [`*.{js,ts}`, `!*.test.{js,ts}`],
commandFilePattern = [`*.{js,ts,cjs}`, `!*.test.{js,ts,cjs}`],
extensionFilePattern = [`*.{js,ts,cjs}`, `!*.test.{js,ts,cjs}`],
hidden = false,
name,
} = options
Expand Down Expand Up @@ -49,7 +49,13 @@ export function loadPluginFromDirectory(directory: string, options: Options = {}
plugin.commands = (options.preloadedCommands || []).map(loadCommandFromPreload)

// load the commands found in the commands sub-directory
const commandSearchDirectories = ['commands', 'build/commands', 'cli/commands', 'build/cli/commands']
const commandSearchDirectories = [
'commands',
'build/commands',
'cli/commands',
'build/cli/commands',
'dist/cli/commands',
]
commandSearchDirectories.forEach((dir) => {
if (jetpackPlugin.exists(dir) === 'dir') {
const commands = jetpackPlugin.cwd(dir).find({ matching: commandFilePattern, recursive: true })
Expand All @@ -61,7 +67,13 @@ export function loadPluginFromDirectory(directory: string, options: Options = {}
})

// load the extensions found in the extensions sub-directory
const extensionSearchDirectories = ['extensions', 'build/extensions', 'cli/extensions', 'build/cli/extensions']
const extensionSearchDirectories = [
'extensions',
'build/extensions',
'cli/extensions',
'build/cli/extensions',
'dist/cli/extensions',
]
extensionSearchDirectories.forEach((dir) => {
if (jetpackPlugin.exists(dir) === 'dir') {
const extensions = jetpackPlugin.cwd(dir).find({ matching: extensionFilePattern, recursive: false })
Expand Down
6 changes: 6 additions & 0 deletions src/toolbox/template-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ function buildGenerate(toolbox: GluegunToolbox): (opts: Options) => Promise<stri
pathToTemplate = `${templateDirectory}/${template}`
}

// check ./dist/cli/templates too, if that doesn't exist
if (!filesystem.isFile(pathToTemplate)) {
templateDirectory = opts.directory || `${baseDirectory}/dist/cli/templates`
pathToTemplate = `${templateDirectory}/${template}`
}

// bomb if the template doesn't exist
if (!filesystem.isFile(pathToTemplate)) {
throw new Error(`template not found ${pathToTemplate}`)
Expand Down

0 comments on commit 28fd610

Please sign in to comment.