Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { VERSION } from './version.ts'

import { buildgraph } from './commands/buildgraph/index.ts'
import { run } from './commands/run/index.ts'
import { plugin } from './commands/plugin/index.ts'
import { engine } from './commands/engine/index.ts'
import { info } from './commands/info/index.ts'
import { build } from './commands/build/index.ts'
Expand Down Expand Up @@ -57,6 +58,7 @@ export const cli = cmd
.command('buildgraph', buildgraph)
.command('run', run)
.command('engine', engine)
.command('plugin', plugin)
.command('build', build)
.command('cook', cook)
.command('pkg', pkg)
Expand Down
4 changes: 4 additions & 0 deletions src/commands/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { GlobalOptions } from '../../lib/types.ts'
import { buildId } from './buildId.ts'
import { config } from './config.ts'
import { listTargets } from './list-targets.ts'
import { project } from './project.ts'
import { plugin } from './plugin.ts'

export const info = new Command<GlobalOptions>()
.description('info')
Expand All @@ -13,3 +15,5 @@ export const info = new Command<GlobalOptions>()
.command('buildId', buildId)
.command('config', config)
.command('list-targets', listTargets)
.command('project', project)
.command('plugin', plugin)
28 changes: 28 additions & 0 deletions src/commands/info/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Command } from '@cliffy/command'
import * as path from '@std/path'

import type { GlobalOptions } from '../../lib/types.ts'
import { Config } from '../../lib/config.ts'
import { displayUPluginInfo, findPluginFile, readUPluginFile } from '../../lib/project-info.ts'

export const plugin = new Command<GlobalOptions>()
.description('Displays information about a plugin')
.arguments('<pluginName>')
.action(async (options, pluginName: string) => {
const config = Config.getInstance()
const { engine: { path: enginePath }, project: { path: projectPath } } = config.mergeConfigCLIConfig({
cliOptions: options,
})

const match = await findPluginFile(pluginName, projectPath, enginePath)
if (match) {
const pluginData = await readUPluginFile(match)
if (pluginData) {
displayUPluginInfo(pluginData)
} else {
console.log(`The plugin ${pluginName} could not be loaded`)
}
} else {
console.log(`Unable to find the plugin ${pluginName}`)
}
})
23 changes: 23 additions & 0 deletions src/commands/info/project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Command } from '@cliffy/command'

import { createProject } from '../../lib/project.ts'
import type { GlobalOptions } from '../../lib/types.ts'
import { Config } from '../../lib/config.ts'
import { displayUProjectInfo, readUProjectFile } from '../../lib/project-info.ts'

export const project = new Command<GlobalOptions>()
.description('Displays information about the project')
.action(async (options) => {
const config = Config.getInstance()
const { engine: { path: enginePath }, project: { path: projectPath } } = config.mergeConfigCLIConfig({
cliOptions: options,
})
const project = await createProject(enginePath, projectPath)

const projectData = await readUProjectFile(project.projectFileVars.projectFullPath)
if (projectData) {
displayUProjectInfo(projectData)
} else {
console.log('The project file could not be loaded')
}
})
44 changes: 44 additions & 0 deletions src/commands/plugin/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Command } from '@cliffy/command'
import { Config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'
import { createProject } from '../../lib/project.ts'
import { readUProjectFile, UnrealEnginePluginReference, UProject, writeUProjectFile } from '../../lib/project-info.ts'
import { exec } from '../../lib/utils.ts'
import * as path from '@std/path'

export type AddOptions = typeof add extends Command<void, void, infer Options, infer Argument, GlobalOptions> ? Options
: never

export const add = new Command<GlobalOptions>()
.description('Adds an external plugin to the project')
.arguments('<url:string> <pluginName:string>')
.option(
'-f, --folder <folder:string>',
"Plugin subfolder to install to, leaving default will install directly into the project's Plugin folder",
{ default: '' },
)
.option('-e, --enable', 'Enable this plugin in the project, defaults to true', { default: true })
.action(async (options, url, pluginName) => {
const { folder, enable } = options as AddOptions
const config = Config.getInstance()
const { engine: { path: enginePath }, project: { path: projectPath } } = config.mergeConfigCLIConfig({
cliOptions: options,
})
const project = await createProject(enginePath, projectPath)

const target_loc = path.relative(
Deno.cwd(),
path.join(project.projectFileVars.projectDir, 'Plugins', folder, pluginName),
)

console.log(`installing ${pluginName} to ${target_loc}`)

await exec('git', ['clone', '--depth', '1', url, target_loc])

if (enable) {
project.enablePlugin({
pluginName: pluginName,
shouldEnable: true,
})
}
})
24 changes: 24 additions & 0 deletions src/commands/plugin/disable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Command } from '@cliffy/command'
import { Config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'
import { createProject } from '../../lib/project.ts'
import { readUProjectFile, UnrealEnginePluginReference, UProject, writeUProjectFile } from '../../lib/project-info.ts'

export type DisableOptions = typeof disable extends Command<void, void, infer Options, infer Argument, GlobalOptions>
? Options
: never

export const disable = new Command<GlobalOptions>()
.description('Disables a plugin for the project')
.arguments('<target:string>')
.action(async (options, target) => {
const config = Config.getInstance()
const { engine: { path: enginePath }, project: { path: projectPath } } = config.mergeConfigCLIConfig({
cliOptions: options,
})
const project = await createProject(enginePath, projectPath)
project.enablePlugin({
pluginName: target,
shouldEnable: false,
})
})
24 changes: 24 additions & 0 deletions src/commands/plugin/enable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Command } from '@cliffy/command'
import { Config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'
import { createProject } from '../../lib/project.ts'
import { readUProjectFile, UnrealEnginePluginReference, UProject, writeUProjectFile } from '../../lib/project-info.ts'

export type EnableOptions = typeof enable extends Command<void, void, infer Options, infer Argument, GlobalOptions>
? Options
: never

export const enable = new Command<GlobalOptions>()
.description('Disables a plugin for the project')
.arguments('<target:string>')
.action(async (options, target) => {
const config = Config.getInstance()
const { engine: { path: enginePath }, project: { path: projectPath } } = config.mergeConfigCLIConfig({
cliOptions: options,
})
const project = await createProject(enginePath, projectPath)
project.enablePlugin({
pluginName: target,
shouldEnable: true,
})
})
19 changes: 19 additions & 0 deletions src/commands/plugin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Command } from '@cliffy/command'
import type { GlobalOptions } from '../../lib/types.ts'

import { info } from './info.ts'
import { add } from './add.ts'
import { list } from './list.ts'
import { enable } from './enable.ts'
import { disable } from './disable.ts'

export const plugin = new Command<GlobalOptions>()
.description('Prints information about a plugin')
.action(function () {
this.showHelp()
})
.command('info', info)
.command('list', list)
.command('enable', enable)
.command('disable', disable)
.command('add', add)
10 changes: 10 additions & 0 deletions src/commands/plugin/info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Command } from '@cliffy/command'
import { Config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'

export const info = new Command<GlobalOptions>()
.description('Prints information about a plugin')
.action((options) => {
const config = Config.getInstance()
const cfg = config.mergeConfigCLIConfig({ cliOptions: options })
})
148 changes: 148 additions & 0 deletions src/commands/plugin/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { Command, EnumType } from '@cliffy/command'
import { Config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'
import { createProject } from '../../lib/project.ts'
import { findFilesByExtension } from '../../lib/utils.ts'
import * as path from '@std/path'
import { findPluginFile, readUPluginFile, readUProjectFile } from '../../lib/project-info.ts'

async function getEnabledPlugins(pluginName: string, projectPath: string, enginePath: string, refArray: Array<string>) {
const pluginArray: Array<string> = []
const match = await findPluginFile(pluginName, projectPath, enginePath)
if (match && match != '') {
const pluginData = await readUPluginFile(match)

if (pluginData && pluginData.Plugins) {
for (const plugin of pluginData.Plugins) {
if (plugin.Enabled) {
if (![...refArray, ...pluginArray].includes(plugin.Name)) {
pluginArray.push(plugin.Name)
}
}
}

const subPlugins: Array<string> = []
for (const pluginName of pluginArray) {
if (![...refArray, ...subPlugins].includes(pluginName)) {
const subPluginArray = await getEnabledPlugins(pluginName, projectPath, enginePath, [
...pluginArray,
...refArray,
...subPlugins,
])
subPlugins.push(...subPluginArray)
}
}
pluginArray.push(...subPlugins)
}
} else {
console.log(`Unable to find the plugin ${pluginName}`)
}
return pluginArray
}

enum ListTarget {
All = 'all',
Referenced = 'referenced',
Project = 'project',
Engine = 'engine',
Default = 'default',
}

export type ListOptions = typeof list extends Command<void, void, infer Options, infer Argument, GlobalOptions>
? Options
: never

export const list = new Command<GlobalOptions>()
.description(`
Lists plugins
target - defaults to referenced:
* all - Lists all plugins from the engine and project
* referenced - Lists all plugins referenced by the project
* engine - Lists all engine plugins
* project - Lists only plugins in the project plugins
* default - Lists all plugins that are enabled by default
`)
.type('ListTarget', new EnumType(ListTarget))
.arguments('<target:ListTarget>')
.option('-r, --recursive', 'List all nested plugins that are enabled when used with "referenced" or "default"', {
default: false,
})
.action(async (options, target = ListTarget.Project) => {
const { recursive } = options as ListOptions
const config = Config.getInstance()
const { engine: { path: enginePath }, project: { path: projectPath } } = config.mergeConfigCLIConfig({
cliOptions: options,
})
const project = await createProject(enginePath, projectPath)
const projectData = await readUProjectFile(project.projectFileVars.projectFullPath)

switch (target) {
case ListTarget.All: {
const projectPlugins = await findFilesByExtension(path.join(projectPath, 'Plugins'), 'uplugin', true)
const enginePlugins = await findFilesByExtension(path.join(enginePath, 'Engine', 'Plugins'), 'uplugin', true)
console.log('Project Plugins:\n')
projectPlugins.forEach((plugin) => {
console.log(path.basename(plugin, '.uplugin'))
})
console.log('Engine Plugins:\n')
enginePlugins.forEach((plugin) => {
console.log(path.basename(plugin, '.uplugin'))
})
break
}
case ListTarget.Referenced: {
const allEnabledPlugins: Array<string> = []

if (projectData && projectData.Plugins) {
for (const plugin of projectData.Plugins) {
if (plugin.Enabled) {
allEnabledPlugins.push(plugin.Name)
}
if (recursive) {
const enabledPlugins = await getEnabledPlugins(plugin.Name, projectPath, enginePath, allEnabledPlugins)
allEnabledPlugins.push(...enabledPlugins)
}
}
}
const uniquePlugins = [...new Set(allEnabledPlugins)]
console.log('All Referenced Plugins:')
console.log(uniquePlugins)
break
}
case ListTarget.Project: {
const projectPlugins = await findFilesByExtension(path.join(projectPath, 'Plugins'), 'uplugin', true)
console.log('Project Plugins:\n')
projectPlugins.forEach((plugin) => {
console.log(path.basename(plugin, '.uplugin'))
})
break
}
case ListTarget.Engine: {
const enginePlugins = await findFilesByExtension(path.join(enginePath, 'Engine', 'Plugins'), 'uplugin', true)
console.log('Engine Plugins:\n')
enginePlugins.forEach((plugin) => {
console.log(path.basename(plugin, '.uplugin'))
})
break
}
case ListTarget.Default: {
const projectPlugins = await findFilesByExtension(path.join(projectPath, 'Plugins'), 'uplugin', true)
console.log('Project Plugins enabled by default:\n')
for (const plugin of projectPlugins) {
const uplugin = await readUPluginFile(plugin)
if (uplugin && uplugin.EnabledByDefault) {
console.log(path.basename(plugin, '.uplugin'))
}
}
console.log('Engine Plugins enabled by default:\n')
const enginePlugins = await findFilesByExtension(path.join(enginePath, 'Engine', 'Plugins'), 'uplugin', true)
for (const plugin of enginePlugins) {
const uplugin = await readUPluginFile(plugin)
if (uplugin && uplugin.EnabledByDefault) {
console.log(path.basename(plugin, '.uplugin'))
}
}
break
}
}
})
2 changes: 1 addition & 1 deletion src/commands/run/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const client = new Command<GlobalOptions>()
await project.compile({
target: EngineTarget.Client,
configuration: configuration as EngineConfiguration,
dryRun: options.dryRun,
dryRun: dryRun,
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/run/commandlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const commandlet = new Command<GlobalOptions>()
await project.compile({
target: EngineTarget.Editor,
configuration: configuration as EngineConfiguration,
dryRun: options.dryRun,
dryRun: dryRun,
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/run/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const editor = new Command<GlobalOptions>()
await project.compile({
target: EngineTarget.Editor,
configuration: configuration as EngineConfiguration,
dryRun: options.dryRun,
dryRun: dryRun,
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/run/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const game = new Command<GlobalOptions>()
await project.compile({
target: EngineTarget.Game,
configuration: configuration as EngineConfiguration,
dryRun: options.dryRun,
dryRun: dryRun,
})
}

Expand Down
Loading