@@ -5,93 +5,224 @@ send "doPackage" to me
55on doPackage
66 local tArgs
77 put the commandArguments into tArgs
8-
8+
99 if tArgs [10 ] is true and not (tArgs [8 ] ends with ".lcb" ) then
10- protectStack the commandName, tArgs [2 ], tArgs [7 ], tArgs [8 ], tArgs [3 ], tArgs [4 ]
10+ protectStack the commandName, tArgs [2 ], tArgs [7 ], tArgs [8 ], tArgs [3 ], tArgs [4 ]
1111 end if
1212
1313 extractDocs the commandName, tArgs [5 ], tArgs [6 ], tArgs [7 ], tArgs [8 ]
14-
14+
15+ local tPackage
1516 if not (tArgs [8 ] ends with ".lcb" ) then
16- packageScriptExtension tArgs [7 ], tArgs [8 ], tArgs [9 ], tArgs [10 ]
17+ packageScriptExtension tArgs [7 ], tArgs [8 ], tArgs [9 ], tArgs [10 ]
1718 else
18- packageBuilderExtension tArgs [7 ], tArgs [8 ], tArgs [9 ], tArgs [10 ], tArgs [11 ], tArgs [12 ]
19+ packageBuilderExtension tArgs [7 ], tArgs [8 ], tArgs [9 ], tArgs [10 ], tArgs [11 ], tArgs [12 ]
1920 end if
21+ put the result into tPackage
22+
23+ extractExtension tPackage , tArgs [7 ], tArgs [9 ], tArgs [10 ]
2024 quit 0
2125end doPackage
2226
2327function q pParam
24- return quote & pParam & quote
28+ return quote & pParam & quote
2529end q
2630
2731command protectStack pEnginePath, pProtectifyScript, pSourceFolder, pSourceFileName, pOutput, pGitHash
28- local tShell
29- put merge (q("[[pEnginePath]]" ) && q("[[pProtectifyScript]]" ) && \
30- q("[[pSourceFolder]]" & slash & "[[pSourceFileName]]" ) && \
31- q("[[pOutput]]" ) && q("[[pGitHash]]" )) into tShell
32-
33- get shell (tShell )
32+ local tShell
33+ put merge (q("[[pEnginePath]]" ) && q("[[pProtectifyScript]]" ) && \
34+ q("[[pSourceFolder]]" & slash & "[[pSourceFileName]]" ) && \
35+ q("[[pOutput]]" ) && q("[[pGitHash]]" )) into tShell
36+
37+ get shell (tShell )
3438 if the result is not 0 then
35- write "subprocess error when protecting stack" && pSourceFileName & ":" && it to stderr
36- quit 1
39+ write "subprocess error when protecting stack" && pSourceFileName & ":" && it to stderr
40+ quit 1
3741 end if
3842end protectStack
3943
4044command extractDocs pEnginePath, pExtractScript, pDocsParser, pSourceFolder, pSourceFileName
41- write the params to stdout
42- local tShell , tSource
43- put pSourceFolder & slash & pSourceFileName into tSource
44- put merge (q("[[pEnginePath]]" ) && q("[[pExtractScript]]" ) && \
45- q("[[pDocsParser]]" ) && q("[[pSourceFolder]]" ) && q("[[tSource]]" )) \
46- into tShell
47-
45+ write the params to stdout
46+ local tShell , tSource
47+ put pSourceFolder & slash & pSourceFileName into tSource
48+ put merge (q("[[pEnginePath]]" ) && q("[[pExtractScript]]" ) && \
49+ q("[[pDocsParser]]" ) && q("[[pSourceFolder]]" ) && q("[[tSource]]" )) \
50+ into tShell
51+
4852 get shell (tShell )
4953 if the result is not 0 then
50- write "subprocess error when extracting docs from" && pSourceFileName & ":" && it to stderr
51- quit 2
54+ write "subprocess error when extracting docs from" && pSourceFileName & ":" && it to stderr
55+ quit 2
5256 end if
5357end extractDocs
5458
59+ private command addFolderToArchive pBaseFolder, pArchive, pRemoveSource, pSourceFileName, pSupportFiles
60+ # First add the files, then recusively add any sub folders
61+ local tFiles
62+ put files (pBaseFolder ) into tFiles
63+ filter tFiles without "."
64+ filter tFiles without ".."
65+
66+ repeat for each line tFile in tFiles
67+ # This must be tweaked if the files to remove are ever not
68+ # top-level source files
69+ if pRemoveSource is "true" then
70+ if tFile is pSourceFileName then
71+ next repeat
72+ end if
73+ if tFile is among the lines of pSupportFiles then
74+ next repeat
75+ end if
76+ end if
77+ revZipAddItemWithFile pArchive , tFile , pBaseFolder & slash & tFile
78+ if the result begins with "ziperr" then
79+ return the result
80+ end if
81+ end repeat
82+
83+ local tFolders
84+ put folders (pBaseFolder ) into tFolders
85+ filter tFolders without "."
86+ filter tFolders without ".."
87+
88+ repeat for each line tFolder in tFolders
89+ addFolderToArchiveRecursive pBaseFolder , tFolder , pArchive
90+ if the result begins with "ziperr" then
91+ return the result
92+ end if
93+ end repeat
94+ return empty
95+ end addFolderToArchive
96+
97+ private command addFolderToArchiveRecursive pBaseFolder, pFolder, pArchive
98+ # First add the files, then recusively add any sub folders
99+ local tFiles
100+ put files (pBaseFolder & slash & pFolder ) into tFiles
101+ filter tFiles without "."
102+ filter tFiles without ".."
103+
104+ repeat for each line tFile in tFiles
105+ revZipAddItemWithFile pArchive , pFolder & slash & tFile , (pBaseFolder & slash & pFolder & slash & tFile )
106+ if the result begins with "ziperr" then
107+ return the result
108+ end if
109+ end repeat
110+
111+ local tFolders
112+ put folders (pBaseFolder & slash & pFolder ) into tFolders
113+ filter tFolders without "."
114+ filter tFolders without ".."
115+
116+ repeat for each line tFolder in tFolders
117+ addFolderToArchiveRecursive pBaseFolder , pFolder & slash & tFolder , pArchive
118+ if the result begins with "ziperr" then
119+ return the result
120+ end if
121+ end repeat
122+ return empty
123+ end addFolderToArchiveRecursive
124+
55125private command packageExtension pExtensionName, pSourceFolder, pSourceFileName, pTargetFolder, pRemoveSource, pSupportFiles
126+ write "packaging extension" && pSourceFileName & return to stdout
56127 local tTargetDir , tBuildTarget , tZip
57128 put pExtensionName into tTargetDir
58129 put pTargetFolder & slash & tTargetDir into tBuildTarget
59130 put pSourceFolder & slash & tTargetDir & ".lce" into tZip
60131
61- local tShell , tCurFolder
62- put the folder into tCurFolder
63- put "cd" && q(pSourceFolder ) into tShell
64- put return & "zip -q -r" && tTargetDir & ".lce *" after tShell
65- put return & "cd" && q(tCurFolder ) after tShell
66- put return & "mkdir -p" && q(tBuildTarget ) after tShell
67- put return & "unzip -q -o " & q(tZip ) && "-d " & q(tBuildTarget ) \
68- after tShell
69- put return & "rm" && q(tZip ) after tShell
70-
71- if pRemoveSource is "true" then
72- put return & "rm" && q(tBuildTarget & slash & pSourceFileName ) \
73- after tShell
74- repeat for each line tSupport in pSupportFiles
75- put return & "rm" && q(tBuildTarget & slash & tSupport ) \
76- after tShell
77- end repeat
132+ local tArchive , tError
133+ revZipOpenArchive tZip , "write"
134+ if the result begins with "ziperr" then
135+ put the result into tError
78136 end if
79-
80- write "packaging extension" && pSourceFileName & return to stdout
81- get shell (tShell )
82- if the result is not 0 then
83- write "subprocess error when packaging extension" && pSourceFileName & ":" && it to stderr
84- quit 3
137+ addFolderToArchive pSourceFolder , tZip , pRemoveSource , pSourceFileName , pSupportFiles
138+ if the result begins with "ziperr" then
139+ put the result into tError
140+ end if
141+ revZipCloseArchive tZip
142+ if the result begins with "ziperr" then
143+ put the result into tError
144+ end if
145+ if tError is not empty then
146+ write "zip error when packaging extension" && pSourceFileName & ":" && tError to stderr
147+ quit 3
85148 end if
149+ return tZip
86150end packageExtension
87151
152+ private command __EnsurePath pPath
153+ if there is a folder pPath then exit __EnsurePath
154+
155+ local tPath
156+ set the itemdel to "/"
157+ repeat for each item tFolder in pPath
158+
159+ if tFolder contains ":" then
160+ put tFolder after tPath
161+ else
162+ put slash & tFolder after tPath
163+ end if
164+
165+ if tPath is empty then next repeat
166+ if there is a folder (quote & tPath & quote ) then next repeat
167+
168+ create folder tPath
169+ end repeat
170+ end __EnsurePath
171+
172+ private command extractExtension pZip, pExtensionName, pSourceFolder, pTargetFolder
173+ local tTargetDir , tBuildTarget , tError
174+ put pExtensionName into tTargetDir
175+ put pTargetFolder & slash & tTargetDir into tBuildTarget
176+
177+ create folder tBuildTarget
178+ # Extract the icon,docs and executable module into the folder
179+ revZipOpenArchive pZip , "read"
180+ if the result begins with "ziperr" then
181+ put the result into tError
182+ end if
183+
184+ # Work out the root of the zip
185+ local tZipItems , tZipRoot
186+ put revZipEnumerateItems (pZip ) into tZipItems
187+ if the result begins with "ziperr" then
188+ put the result into tError
189+ end if
190+ if the last char of line 1 of tZipItems is "/" then
191+ put line 1 of tZipItems into tZipRoot
192+ else
193+ put empty into tZipRoot
194+ end if
195+
196+ # Extract all the files
197+ local tDirectory
198+ set the itemdel to slash
199+ repeat for each line tFile in tZipItems
200+ put tBuildTarget & slash & item 1 to - 2 of tFile into tDirectory
201+ __EnsurePath tDirectory
202+ revZipExtractItemToFile pZip , tFile , tBuildTarget & slash & tFile
203+ if the result begins with "ziperr" then
204+ put the result into tError
205+ end if
206+ end repeat
207+
208+ revZipCloseArchive pZip
209+ if the result begins with "ziperr" then
210+ put the result into tError
211+ end if
212+ if tError is not empty then
213+ write "zip error when extracting extension" && pExtensionName & ":" && tError to stderr
214+ quit 3
215+ end if
216+ end extractExtension
217+
88218command packageScriptExtension pSourceFolder, pSourceFileName, pTargetFolder, pRemoveSource
89219 local tExtShortName
90220 set the itemdelimiter to "."
91221 put item - 2 of pSourceFileName into tExtShortName
92222
93223 packageExtension "com.livecode.library." & tExtShortName , \
94- pSourceFolder , pSourceFileName , pTargetFolder , pRemoveSource
224+ pSourceFolder , pSourceFileName , pTargetFolder , pRemoveSource
225+ return the result
95226end packageScriptExtension
96227
97228private function getSupportFiles pSourceFolder, pSourceFileName, pExtension
@@ -152,7 +283,8 @@ command packageBuilderExtension pSourceFolder, pSourceFileName, pTargetFolder, p
152283 end if
153284
154285 packageExtension tExtensionName , pSourceFolder , pSourceFileName , \
155- pTargetFolder , pRemoveSource , tSupportFiles
286+ pTargetFolder , pRemoveSource , tSupportFiles
287+ return the result
156288end packageBuilderExtension
157289
158290on errorDialog tError
0 commit comments