-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoonProject.lua
More file actions
244 lines (230 loc) · 8.47 KB
/
Copy pathMoonProject.lua
File metadata and controls
244 lines (230 loc) · 8.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
--- Module for creating Coding projects
-- @script MoonProject
-- @author letiulthecode
-- @license MIT
-- @release 01/01/2021
local MoonProject = {}
MoonProject._VERSION = '0.4'
MoonProject._CHANGELOG = 'Tutorial updated, Made SetEnv and SetDynamicEnv, we preparing to remove BuildRun.'
MoonProject._LAST_UPDATE = '01/04/2021'
local exe = os.execute
local close = os.exit
local write = io.write
local remove = os.remove
---The data table contains data for a basic enviorment
--@table data
local data = {}
---The Dynamic Data table contains data for a dynamic enviorment
--@table dynamicdata
local dynamicdata = {}
---Insert a custom value in data table.
--@see data
function MoonProject.IncludeData(index, include)
MoonProject.checknil(index, include)
table.insert(data, index, include)
end
---Insert a custom value in dynamicdata table.
--@see dynamicdata
function MoonProject.IncludeDyData(index, include)
MoonProject.checknil(index, include)
table.insert(data, index, include)
end
--- Show information of Current version, changelog, etc
function MoonProject.Info()
write('MoonProject Info\nVersion: '..MoonProject._VERSION..'\nLast Updated: '..MoonProject._LAST_UPDATE..'\nChangelog: '..MoonProject._CHANGELOG..'\n')
end
--- Basic Enviorment
--@section Enviorment
--@param Compiler
--@param SourceFile
--@param Flags
--@param OutputFile
function MoonProject.SetEnv(c, t, f, o)
MoonProject.checknil(c, t, f, o)
data[1] = c
data[2] = t
data[3] = f
data[4] = o
--- Just Build up the program,
--@return Compiled File
function MoonProject.Build()
if not exe(data[1].." "..data[2].." "..data[3].." "..data[4]) then
assert(false, "Project: Probably Compilation error, Check the error above\n")
end
end
--- Run compiled file
--@return Compiled File Result
function MoonProject.Run()
if not exe('\n./'..data[4]) then
assert(false, '\nProject: Probably runtime error (or exit code of your code).\n')
end
end
---Update an output file
--@return Updated file
function MoonProject.Update()
MoonProject.Clean(data[4])
MoonProject.Build()
write('File '..data[4]..' is now updated\n')
end
--- Build the source program and run.
--- This is used for debugging
--@return Compiled Code Result
function MoonProject.BuildRun()
write("MoonProject by Lethel(c) Version "..MoonProject._VERSION.."\n")
write("\n\n1-Compiling...\n")
if not exe("\n"..data[1].." "..data[2].." "..data[3].." "..data[4]) then
assert(false, "Project: Probably Compilation error, Check the error above\n")
else
write("\nCompilaton success.")
end
write("\n\n2-Running...\n")
write("Results:\n\n")
if not exe("\n./"..data[4]) then
assert(false, "Project: Unable to run file (or exit code of your code), Check First and/or Second Step.\n") end
write("\n\n_____________\n")
write("\n\n3-Cleaning...\n")
if not exe('rm '..data[4]) then
write("Project WARN: The file already was deleted or name is incorrect.\n")
else
write("\nClear success.")
end
write("\n\nBuild & Run process completed without any error.\n")
end
end
--- Dynamic Enviorments
--@section DynamicEnviorment
--@param Compiler
--@param SourceFile
function MoonProject.SetDynamicEnv(c, t)
MoonProject.checknil(c, t)
dynamicdata[1] = c
dynamicdata[2] = t
--- Build the program without flags and output files
--@return Compiled File
function MoonProject.BuildDynamic()
write("MoonProject by Lethel(c) Version "..MoonProject._VERSION.."\n")
write('\nBuilding...\n\n')
if not exe(dynamicdata[1].." "..dynamicdata[2]) then
assert(false, 'ERROR: Probably compilation error, check the error above.\n')
else
write('Building (dynamic mode) success\n')
end
end
--- Build and run without flags and giving output filename
--- This is used for debug like BuildRun
--@return Compiled Code Result
function MoonProject.BuildRunDynamic()
write("MoonProject by Lethel(c) Version "..MoonProject._VERSION.."\n")
write('\nBuilding...\n\n')
if not exe(dynamicdata[1].." "..dynamicdata[2]) then
assert(false, 'ERROR: Probably compilation error, check the error above.\n')
end
write('\nRunning...\n\n')
write('Results:\n\n')
if not exe('./'..dynamicdata[2]) then
assert(false, 'Project: Unable to run file, Check First and/or Second Step.\n')
end
write('\nCleaning...\n\n')
if not remove(dynamicdata[2]) then
write("Project WARN: The file already was deleted or name is incorrect.\n")
end
write("\n\nBuild & Run (Dynamic mode) process completed without any error.\n")
end
---Update an output file
--@return Updated file
function MoonProject.Update()
MoonProject.Clean(dynamicdata[2])
MoonProject.Build()
write('File '..data[2]..' is now updated\n')
end
--- Run compiled file
--@return Compiled File Result
function MoonProject.Run()
if not exe('\n./'..dynamicdata[2]) then
assert(false, '\nProject: Probably runtime error (or exit code of your code).\n')
end
end
end
--- Check if an value is null or is a empty string
--- For advoid the permission is denied to open the output
--- file
-- @param Value
function MoonProject.checknil(...)
if ... == nil then
assert(false, "Project: Fields cannot be empty")
elseif ... == "" then
assert(false, "Project: Fields cannot be empty")
elseif ... == ' ' then
assert(false, "Project: Fields cannot be a space")
end
end
--- remove/Delete the file on param 'file'
--@param File
--@return FIle Deleted
function MoonProject.Clean(f)
MoonProject.checknil(f)
if not exe('rm -r '..f) or remove(f) then
write('Project WARN: File has already been deleted or dosent exist\n')
close(2)
end
end
--- Make an C file and test its out,
--- After running it will clean;
--@return "Hello World!"
function MoonProject.Test()
write("Testing with test.c file...\n\n")
local fi = io.open('./test.c', 'w')
local env = os.getenv("PATH")
fi:write('#include <stdio.h>\n\nint main() {\n printf("Hello World!");\n return 0;\n}')
fi:close()
write('Testing if gcc is installed...\n')
if not env:gmatch('/usr/bin/gcc') then
remove('test.c')
assert(false, 'Project: gcc not installed, install it with "sudo apt install gcc"\n')
else
write('GCC installed and ready to test\n\n')
end
MoonProject.BuildRun()
remove('test.c')
write('Tested!\n')
end
--- MoonProject.new will create a new project
--- Returns nil if he dont reconigze the language.
--@param name of the project
--@param name of the language
--@return Project
function MoonProject.new(name, language)
MoonProject.checknil(name, language)
local function NewProject(command, moduleext)
if language == command then
write("Wait till project "..name.." be created... (It will be created in the current folder)\n")
if not exe('mkdir ./'..name.." && cd "..name.." && mkdir src && cd src && touch main."..command.." && mkdir include && cd include && touch module."..moduleext.." && cd ../../..") then
write("Project WARN: Folder "..name.." has already been created.\n")
close(1)
end
write("Project "..name.." has been created\nHint: src folder is for your source code, and include folder are for modules for you use.\n")
close(0)
end
end
local function CustomNProject(nm, command, command2, mde, mde2)
if language == nm then
write("Wait till project "..name.." be created... (It will be created in the current folder)\n")
if not exe('mkdir ./'..name.." && cd "..name.." && mkdir src && cd src && touch main."..command.."&& touch main."..command2.." && mkdir include && cd include && touch module."..mde.."&& touch module."..mde2.." && cd ../../..") then
write("Project WARN: Folder "..name.." has already been created.\n")
close(1)
end
write("Project "..name.." has been created\nHint: src folder is for your source code, and include folder are for modules for you use.\n")
close(0)
end
end
NewProject('lua', 'lua')
NewProject('py', 'py')
NewProject('go', 'go')
NewProject('c', 'h')
NewProject('cpp', 'hh')
NewProject('java', 'java')
NewProject('js', 'js')
NewProject('ts', 'ts')
CustomNProject('c/cpp', 'c', 'cpp', 'h', 'hh')
end
return MoonProject