Skip to content

Commit

Permalink
Updated app creator with support for Sublime Text
Browse files Browse the repository at this point in the history
- Allow user to enter app name. App name is used for setting standalone name and Sublime Text project name.
- Support for creating a Sublime Text project and uncommenting code that updates Levure app scripts when updating them in a Sublime Text project.
- Improved UI
- Progress is now logged to the message box.
- Clarified instructions.
  • Loading branch information
trevordevore committed Dec 10, 2018
1 parent 268bba6 commit 5f0eff7
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 62 deletions.
6 changes: 5 additions & 1 deletion utils/convert stacks to ui.md
@@ -1,6 +1,10 @@
# Converting stacks to UI components

If you are going to version control your stacks then you should have each stack in its own stack file and all scripts should be in script only stack files. Here are two scripts which can aid you in converting your stacks.
If you are going to version control your stacks then you should have each stack in its own stack file and all scripts should be in script only stack files.
There are several ways to do that:
- Geoff Canyon's Navigator has functionality built-in to break out your scripts. You can [download it on dropbox](https://www.dropbox.com/s/kz3zqi4botzglgq/navigator.zip?dl=1) or [clone or fork it on github](https://github.com/gcanyon/navigator)
- The [Levure videos on YouTube](https://www.youtube.com/watch?v=eyggLzIbeSU) demonstrate how to do it manually.
- This repo includes two scripts which can aid you in converting your stacks.

## Save a stack in memory to a stack file on disk

Expand Down
Binary file modified utils/create-levure-application.livecode
Binary file not shown.
2 changes: 2 additions & 0 deletions utils/create_levure_app_files/README.md
@@ -0,0 +1,2 @@
This folder contains the files that have the master/most-current versions of the various files that Levure creates when it creates an app.
The contents of these files are assigned to scripts and properties of the `create-levure-application.livecode` stack when it is saved. If you modify one of these files make sure you laod the `create-levure-application.livecode` stack in the LiveCode IDE and save it.
2 changes: 1 addition & 1 deletion utils/create_levure_app_files/app.yml
@@ -1,4 +1,4 @@
name:
name: <appname>
version: 0.0.1
build: 1
encrypt stacks: false
Expand Down
23 changes: 23 additions & 0 deletions utils/create_levure_app_files/appname.sublime-project
@@ -0,0 +1,23 @@
{
"folders":
[
{
"folder_exclude_patterns":
[
"builds"
],
"path": "app/",
"name": "<appname>",
}
],
"livecode":
{
"notify_on_save": true,
"notify_server":
{
"host": "localhost",
"port": 61373,
"debug": false
}
}
}
175 changes: 115 additions & 60 deletions utils/create_levure_app_files/stack.livecodescript
@@ -1,22 +1,34 @@
local sSettingsA
local sAppName
local sUseSublimeText
local sTargetFolder


command uiCreateLevureApp
local tOutputFolder

put field "appName" into sAppName
put the hilite of button "useSublimeText" into sUseSublimeText

if sAppName is empty then
beep
answer "Please specify a name for the app."
exit to top
end if

answer folder "Select your application folder"
put it into tOutputFolder
put it into sTargetFolder

if tOutputFolder is not empty then
show msg
put "Create Levure App" & cr
if sTargetFolder is not empty then
put empty
_log "Create Levure App"

CreateLevureApp tOutputFolder
CreateLevureApp
end if
end uiCreateLevureApp


command CreateLevureApp pFolder
command CreateLevureApp
local tError

put empty into sSettingsA
Expand All @@ -29,8 +41,6 @@ command CreateLevureApp pFolder
end if
end if

put pFolder into sSettingsA["target folder"]

if the hilite of button "UseGit" then
CreateApplicationFilesAndFolders
put the result into tError
Expand Down Expand Up @@ -69,7 +79,7 @@ command LevureZipDownloadComplete pUrl, pUrlStatus
if pUrlStatus is "cached" then
local tFilename

put sSettingsA["target folder"] & "/levure-master.zip" into tFilename
put sTargetFolder & "/levure-master.zip" into tFilename
put url pUrl into URL ("binfile:" & tFilename)
UnzipLevureFiles tFilename
put the result into tError
Expand All @@ -79,7 +89,7 @@ command LevureZipDownloadComplete pUrl, pUrlStatus

if tError is empty then
delete char -4 to -1 of tFilename
rename folder tFilename to sSettingsA["target folder"] & "/levure"
rename folder tFilename to sTargetFolder & "/levure"
put the result into tError
end if

Expand Down Expand Up @@ -114,14 +124,14 @@ command CreateApplicationFilesAndFolders
if tError is empty then
local tFolder

put sSettingsA["target folder"] & "/app" into tFolder
fileCreateAllFoldersInPath tFolder, sSettingsA["target folder"]
put sTargetFolder & "/app" into tFolder
fileCreateAllFoldersInPath tFolder, sTargetFolder
put the result into tError
end if

if tError is empty then
put "Create levure folders" & cr after msg
create folder sSettingsA["target folder"] & "/builds"
_log "Create levure folders"
create folder sTargetFolder & "/builds"
create folder tFolder & "/backscripts"
create folder tFolder & "/behaviors"
create folder tFolder & "/frontscripts"
Expand All @@ -133,15 +143,21 @@ command CreateApplicationFilesAndFolders
end if

if tError is empty then
put "Create app.yml and app.livecodescript" & cr after msg
_log "Create app.yml and app.livecodescript"
put DefaultAppYaml() into url("binfile:" & tFolder & "/app.yml")
put DefaultAppScript() into url("binfile:" & tFolder & "/app.livecodescript")
end if

if tError is empty and sUseSublimeText then
put DefaultSublimeProject() into url("binfile:" & sTargetFolder & slash & sAppname & ".sublime-project")
put the result into tError
end if


if tError is empty then
local tBehaviorFile

put "Create sample window files/folders" & cr after msg
_log "Create sample window files/folders"
create folder tFolder & "/ui/sample_window"
create folder tFolder & "/ui/sample_window/behaviors"

Expand All @@ -163,14 +179,24 @@ command CreateStandaloneStackfile
local tError

if tError is empty then
put "Create standalone.livecodescript" & cr after msg
clone stack "LevureStandaloneTemplate" as "LevureStandalone"
set the stackfiles of stack "LevureStandalone" to "levureFramework,../levure/framework/levure.livecodescript"
set the behavior of stack "LevureStandalone" to the long id of stack (sSettingsA["target folder"] & "/levure/framework/levure.livecodescript")
local tStackName

_log "Create standalone.livecodescript"

put sAppName into tStackName
if word 1 to -1 of tStackName is empty or there is a stack tStackName then put "LevureStandalone" into tStackName

clone stack "LevureStandaloneTemplate" as tStackName
set the stackfiles of stack tStackName to "levureFramework,../levure/framework/levure.livecodescript"
set the behavior of stack tStackName to the long id of stack (sTargetFolder & "/levure/framework/levure.livecodescript")
# levureFramework was loaded into memory when assigned as the behavior
delete stack "levureFramework"
save stack "LevureStandalone" as (sSettingsA["target folder"] & "/app/standalone.livecode")
delete stack "LevureStandalone"

set the title of stack tStackName to sAppName
set the cRevStandaloneSettings["name"] of stack tStackName to sAppName

save stack sAppName as (sTargetFolder & "/app/standalone.livecode")
delete stack sAppName
end if

return tError
Expand All @@ -181,26 +207,26 @@ command SetupGitInFolder
local tFolder, tResult, tError

put the defaultFolder into tFolder
set the defaultFolder to sSettingsA["target folder"]
set the defaultFolder to sTargetFolder

if tError is empty then
put "Setup git" & cr after msg
_log "Setup git"
put shell(sSettingsA["git folder"] & "git init") into tResult
if the result is not empty then
put tResult into tError
end if
end if

if tError is empty then
put "Setup Levure as submodule" & cr after msg
_log "Setup Levure as submodule"
put shell(sSettingsA["git folder"] & "git submodule add https://github.com/trevordevore/levure.git levure") into tResult
if the result is not empty then
put tResult into tError
end if
end if

if tError is empty then
put the uGitIgnoreFile of this stack into url("binfile:" & sSettingsA["target folder"] & "/.gitignore")
put the uGitIgnoreFile of this stack into url("binfile:" & sTargetFolder & "/.gitignore")
end if

set the defaultFolder to tFolder
Expand All @@ -213,10 +239,10 @@ command AddFilesToGit
local tFolder, tResult, tError

put the defaultFolder into tFolder
set the defaultFolder to sSettingsA["target folder"]
set the defaultFolder to sTargetFolder

if tError is empty then
put "Add files to git" & cr after msg
_log "Add files to git"
put shell(sSettingsA["git folder"] & "git add .") into tResult
if the result is not empty then
put tResult into tError
Expand All @@ -230,27 +256,53 @@ end AddfilesToGit


private function DefaultAppYaml
return the uAppYAML of this stack
local tYAML

put the uAppYAML of this stack into tYAML
replace "<appname>" with sAppname in tYAML
return tYAML for value
end DefaultAppYaml


private function DefaultAppScript
return the uAppStackScript of this stack
local tScript, tLineNo

put the uAppStackScript of this stack into tScript

if sUseSublimeText then
put lineoffset("levureLoadExternalEditorServer", tScript) into tLineNo
if tLineNo > 0 then
delete char 1 to 3 of word 1 of line tLineNo-1 of tScript
delete char 1 to 3 of word 1 of line tLineNo of tScript
delete char 1 to 3 of word 1 of line tLineNo+1 of tScript
end if
end if

return tScript
end DefaultAppScript


private function DefaultSublimeProject
local tSublimeProject

put the uSublimeProject of this stack into tSublimeProject
replace "<appname>" with sAppname in tSublimeProject
return tSublimeProject
end DefaultSublimeProject


command UnzipLevureFiles pFilename
local tError

if tError is empty then
put "Unzip Levure" & cr after msg
_log "Unzip Levure"
revZipOpenArchive pFilename, "read"
put the result into tError
end if

if tError is empty then
put "Reflate Levure" & cr after msg
zipDecompressArchiveToFolder pFilename, sSettingsA["target folder"], empty, "UnzipPackageCallback"
_log "Reflate Levure"
zipDecompressArchiveToFolder pFilename, sTargetFolder, empty, "UnzipPackageCallback"
put the result into tError
end if

Expand All @@ -266,7 +318,7 @@ end UnzipPackageCallback


command AppProjectCompleted
put "Done" after msg
_log "Done"
answer "Your Levure project has been created."
end AppProjectCompleted

Expand All @@ -278,6 +330,11 @@ command AnswerError pMsg, pError
end AnswerError


command _log pMsg
put pMsg & cr after msg
end _log


/**
* \brief Creates a zip file from a directory. The ZIP archive should already have been opened with revZipOpenArchive.
*
Expand Down Expand Up @@ -450,8 +507,6 @@ end CardOf
command fileCreateAllFoldersInPath pPath, pRootPath, pPerms
local theCheck,tError,thePathSegment

put "Create" && pPath & cr after msg

## Watch for double slashes /Folder/To//Something//
## You will not enter a never ending loop if you aren't careful.
_stripDoubleSlash pPath
Expand Down Expand Up @@ -571,18 +626,18 @@ on fileSetPermissions pFile, pOwner, pGroup, pAll
put _executableBitFromType(pAll) into pAll
put shell(format("chmod %u%u%u %s ", pOwner, pGroup, pAll, pFile)) into theResult
break
end SWITCH
end switch

if the result is not empty then
put line 1 of theResult into tError
end if
if the result is not empty then
put line 1 of theResult into tError
end if

return tError
end fileSetPermissions
return tError
end fileSetPermissions


private function _executableBitFromType pType
switch pType
private function _executableBitFromType pType
switch pType
case "execute"
put 7 into pType
break
Expand All @@ -594,26 +649,26 @@ private function _executableBitFromType pType
break
default
put 0 into pType
end switch
return pType
end _executableBitFromType
end switch
return pType
end _executableBitFromType


private function _escapeForShell pStr
local theChar,theSpecialChars
private function _escapeForShell pStr
local theChar,theSpecialChars

if the platform is "win32" then
replace "/" with "\" in pStr
put quote & pStr & quote into pStr
else
put "\" & space & quote & "'`<>!;()[]?#$^&*=|" into theSpecialChars
repeat for each char theChar in theSpecialChars
replace theChar with ("\" & theChar) in pStr
end REPEAT
end if
if the platform is "win32" then
replace "/" with "\" in pStr
put quote & pStr & quote into pStr
else
put "\" & space & quote & "'`<>!;()[]?#$^&*=|" into theSpecialChars
repeat for each char theChar in theSpecialChars
replace theChar with ("\" & theChar) in pStr
end REPEAT
end if

return pStr
end _escapeForShell
return pStr
end _escapeForShell


## Used for removing multiple slashes from folder paths
Expand Down

0 comments on commit 5f0eff7

Please sign in to comment.