Vemto

Vemto

This class represents the Vemto API and is automatically injected inside plugin's code (vemto on main.js and window.vemtoApi inside Vue components)

Constructor

new Vemto()

Properties:
Name Type Description
log LogBase Class for log from plugins
generator object An object that allows to control the code generation process
Properties
Name Type Description
abort function Allows you to abort the code generation process

Methods

addBlockReason(reason)

You can use this method to explain why a plugin installation was blocked inside the canInstall Hook
Parameters:
Name Type Description
reason string The message you want to show when the installation is blocked

addEntityMarker(entity, text, coloropt, textColor=opt)

Method responsible for creating an entity marker within Vemto Schema
Parameters:
Name Type Attributes Default Description
entity Entity The entity you want to add the marker
text string The text you want to show in the marker
color string <optional>
#14B8A6 The background color
textColor= string <optional>
Optional, leave it empty and it will choose a color by the background contrast

debounce(callback, time) → {string}

You can use this method to debounce operations on the plugin Vue component without the need of installing a debounce library.
Parameters:
Name Type Description
callback function
time number
Returns:
Type
string

disableDefaultRunnerMigrations()

You can use this method to disable the default "php artisan migrate" command on the beforeRunnerStart hook

disableDefaultRunnerServer()

You can use this method to disable the default "php artisan serve" command on the beforeRunnerStart hook

disableDefaultRunnerWebPageTrigger()

You can use this method to disable opening the project URL on the beforeRunnerStart hook

executeArtisan(command) → {string}

You can use this method to execute a "php artisan" command. This method will prepend the command with the correct php binary in the start. For example, if you call executeArtisan('serve'), it may execute "C:\bin\php artisan serve", depending on Vemto configuration
Parameters:
Name Type Description
command string The command you want to run
Returns:
- The command output
Type
string

executeCommand(command)

You can use this method to run a command inside the project folder
Parameters:
Name Type Description
command string The command you want to run

executeComposer(command) → {string}

You can use this method to execute a "composer" command. This method will prepend the command with the correct composer executable in the start. For example, if you call executeComposer('install'), it may execute "C:\bin\composer install", depending on Vemto configuration
Parameters:
Name Type Description
command string The command you want to run
Returns:
- The command output
Type
string

executeNpm(command) → {string}

You can use this method to execute a "npm" command. This method will prepend the command with the correct npm executable in the start. For example, if you call executeNpm('install'), it may execute "C:\bin\npm install", depending on Vemto configuration
Parameters:
Name Type Description
command string The command you want to run
Returns:
- The command output
Type
string

executePhp(command) → {string}

You can use this method to execute a "php" command. This method will prepend the command with the correct php binary in the start. For example, if you call executePhp('artisan serve'), it may execute "C:\bin\php artisan serve", depending on Vemto configuration
Parameters:
Name Type Description
command string The command you want to run
Returns:
- The command output
Type
string

executePostComposer(command) → {string}

This works exactly like executeComposer, but will fail with a message in the console if the project packages are not installed
Parameters:
Name Type Description
command string The command you want to run
Returns:
- The command output
Type
string

formatByLanguage(content, languageopt) → {string}

Format the content as an specific programming language
Parameters:
Name Type Attributes Default Description
content string the text/code contet
language string <optional>
php the language you want to format. Accepts: php, js, html and blade
Returns:
- The formatted content
Type
string

getMultiTenancyStrategy() → {string}

Returns the multitenancy strategy (login, single-database, multi-database)
Returns:
Type
string

getPluginData() → {object}

Returns the current plugin data
Returns:
Type
object

getProject() → {Project}

Returns the project
Returns:
Type
Project

getProjectEntities() → {Array.<Entity>}

Returns the project entities (models and tables)
Returns:
Type
Array.<Entity>

getProjectModels() → {Array.<Entity>}

Returns the project models
Returns:
Type
Array.<Entity>

getProjectSettings() → {object}

Returns the project settings
Returns:
Type
object
You can use this method to open a link in the browser
Parameters:
Name Type Description
link string The link

parsePhp(content) → {PhpParser}

You can use this method to parse a php file
Parameters:
Name Type Description
content string The content you want to parse
Returns:
Type
PhpParser

pluginFileExists(filePath) → {boolean}

Determines if a file relative to the plugin path exists
Parameters:
Name Type Description
filePath string the file relative path
Returns:
Type
boolean

pluginFolderExists(folderPath) → {boolean}

Determines if a file relative to the project path exists
Parameters:
Name Type Description
folderPath string the folder relative path
Returns:
Type
boolean

projectFileExists(filePath) → {boolean}

Determines if a file relative to the project path exists
Parameters:
Name Type Description
filePath string the file relative path
Returns:
Type
boolean

projectFolderExists(folderPath) → {boolean}

Determines if a folder relative to the project path exists
Parameters:
Name Type Description
folderPath string the folder relative path
Returns:
Type
boolean

projectHasMultiTenancy() → {boolean}

Check if this project has already an installed multiTenancy plugin
Returns:
Type
boolean

readPluginFile(filePath) → {string|Buffer}

Read a file relative to the plugin path
Parameters:
Name Type Description
filePath string the file relative path to the plugin
Returns:
- the file content
Type
string | Buffer

readProjectFile(filePath) → {string|Buffer}

Read a file relative to the project path
Parameters:
Name Type Description
filePath string the file relative path to the project
Returns:
- the file content
Type
string | Buffer

registerProjectFile(filePath) → {boolean}

Registers a file in a project. When a file is registered, Vemto will check if it had manual changes before trying to rewrite it. If the file was changed, Vemto will skip and show the file difference for manual review
Parameters:
Name Type Description
filePath string the file relative path to the project
Returns:
Type
boolean

renderTemplate(from, to, optionsopt) → {string}

You can use this method to render a custom template from a Vemto plugin
Parameters:
Name Type Attributes Default Description
from string The template path relative to your plugin folder
to string The generated file path, relative to the project folder
options object <optional>
{}
Properties
Name Type Attributes Default Description
formatAs= object <optional>
The formatter you want to use (php, html, blade) - Not obligatory
data object <optional>
{} The data you are passing to the template - Not obligatory
Returns:
Type
string

replaceTemplate(template, replacementPath)

You can use this method to replace a default Vemto template (it will work similarly to change) the template content in the Template Editor
Parameters:
Name Type Description
template string The template path (exactly how you see in the Template Editor) you want to replace
replacementPath string Path to the file, inside the plugin folder, you want to use as a replacement

savePluginData(data) → {string}

Returns the multitenancy strategy (login, single-database, multi-database)
Parameters:
Name Type Description
data object The data you want to save for your plugin (the data is saved in the project, and not globally)
Returns:
Type
string

writePluginFile(filePath, content) → {boolean}

Write a file relative to the plugin path
Parameters:
Name Type Description
filePath string the file relative path to the plugin
content string the file content
Returns:
Type
boolean

writeProjectFile(filePath, content) → {boolean}

Write a file relative to the project path
Parameters:
Name Type Description
filePath string the file relative path to the project
content string the file content
Returns:
Type
boolean