Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Adding a 'Build' button #40

Closed
wants to merge 4 commits into from
Closed
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This package auto-installs several utilities for writing Love2D games in Atom. The individual packages can also be installed separately.

- [Features](#features)
- [Run Icon in Toolbar](#run-icon-in-toolbar)
- [Run and Build Icon in Toolbar](#run-and-build-icon-in-toolbar)
- [Love API Autocomplete](#love-api-autocomplete-via-autocomplete-lovehttpsatomiopackagesautocomplete-love)
- [Love API Click to Definition](#love-api-click-to-definition-via-hyperclick-lovehttpsatomiopackageshyperclick-love)
- [Lua Syntax Checking](#lua-syntax-checking-via-linter-luaparsehttpsatomiopackageslinter-luaparse)
Expand All @@ -13,10 +13,11 @@ This package auto-installs several utilities for writing Love2D games in Atom. T
## Features
`love-ide` auto-installs packages that provide the following features.

### Run Icon in Toolbar
### Run and Build Icon in Toolbar
![](https://raw.githubusercontent.com/rameshvarun/love-ide/master/demo/run.png)

Runs `love .` in the project directory. As of now, this can't be installed separately.
The first runs `love .` in the project directory, the other one makes an .exe file (or a .love file if you're not using Windows).
As of now, this can't be installed separately.

### Love API Autocomplete (via [autocomplete-love](https://atom.io/packages/autocomplete-love))
![](https://raw.githubusercontent.com/rameshvarun/love-ide/master/demo/autocomplete.png)
Expand Down
49 changes: 49 additions & 0 deletions lib/build-love.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
@echo off
if [%1]==[] goto usage
cd %1
powershell Compress-Archive * compressed.zip
set lovepath=%2
IF [%lovepath%]==[] ( goto :searchInEnVar )
IF ["%lovepath%"]==["love"] ( goto :searchInEnVar )
IF ["%lovepath%"]==["love.exe"] ( goto :searchInEnVar )
IF NOT EXIST "%2" ( goto :searchInEnVar )

:build
copy %lovepath% .
for %%I in (.) do set CurrDirName=%%~nxI
echo Building...
copy /by love.exe+compressed.zip "%CurrDirName%.exe"
del /f compressed.zip
del /f love.exe
goto :end

:searchInEnVar
echo Searching for love.exe in the environment variables...
for %%a in ("%PATH:;=" "%") do (
Echo.%%a | findstr /C:"LOVE">nul && (
pushd %%a
IF EXIST "love.exe" (
Echo.Found on %%a
set lovepath=%%a\love.exe
popd
goto :build
)
popd
Echo.Still searching...
) || (
Echo.Still searching...
)
)
Echo.Cannot find love.exe
pause
goto :end

:usage
echo Error: missing argument.
echo USAGE: %~nx0 ProjectDirectory [love.exe]
echo.
echo If the love.exe path is missing from the arguments it will be searched in the PATH environment variable.
pause

:end
exit
64 changes: 62 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ directory as the current working directory.`,
order: 3,
},
disableToolbarButton: {
title: 'Disable Toolbar Button',
description: `Don't show a run icon in the toolbar.`,
title: 'Disable Toolbar Buttons',
description: `Don't show a run and a build icon in the toolbar.`,
type: 'boolean',
default: false,
order: 4,
Expand All @@ -47,6 +47,55 @@ export function activate () {
require('atom-package-deps').install('love-ide');
}

function buildapp() {
// Find all the directories that have a main.lua in them.
var dirs = atom.project.getDirectories().filter(dir =>
dir.getFile('main.lua').existsSync());

// No directories were found.
if(dirs.length == 0) {
atom.notifications.addError("None of the project directories have a main.lua");
return;
}

// Prioritize the directory of the currently active editor.
const activeEditor = atom.workspace.getActiveTextEditor();
dirs.sort((a, b) => {
if (a.contains(activeEditor.getPath())) return -1;
if (b.contains(activeEditor.getPath())) return 1;
else return 0;
});

var lovePath = atom.config.get('love-ide.lovePath') || 'love';

var startpath = dirs[0].getPath();
var command = "zip -9 -r compressed.love .";

// Check OS
if (process.platform == "win32") {
// Get package directory
for (var lipath of atom.packages.getPackageDirPaths()) {
if (fs.existsSync(lipath + "\\love-ide\\lib")) {
startpath = lipath + "\\love-ide\\lib";
}
}

// Start CMD and run build-love.bat
command = `start cmd.exe @cmd /c "start build-love.bat ${dirs[0].getPath()} ${lovePath} && exit"`;
}

// Run commands
child_process.exec(command, {cwd: startpath}, (err, stdout, stderr) => {
if(err) {
var message = stderr.toString();
if (err.code == 127) message = "LOVE executable not found. Try setting the PATH in the love-ide settings menu.";
atom.notifications.addError('Error running LOVE.', {
detail: message
});
}
});
}

function run() {
// Find all the directories that have a main.lua in them.
var dirs = atom.project.getDirectories().filter(dir =>
Expand Down Expand Up @@ -140,6 +189,7 @@ function run() {
}

atom.commands.add('atom-text-editor', 'love-ide:run-love', run);
atom.commands.add('atom-text-editor', 'love-ide:build-love', buildapp);

var toolBarSection = null;
export function consumeToolBar(toolBar: ToolBar) {
Expand All @@ -152,6 +202,16 @@ export function consumeToolBar(toolBar: ToolBar) {
iconset: 'ion',
callback: run,
});

var buildTooltip = 'Create a .love-file';
if (process.platform == "win32") { buildTooltip = 'Build Love Windows Executable'; }

var buildButton = toolBarSection.addButton({
icon: 'ios-hammer',
tooltip: buildTooltip,
iconset: 'ion',
callback: buildapp,
});
}

export function deactivate() {
Expand Down