1
1
#!/usr/bin/env python3
2
2
import os
3
3
import sys
4
- from typing import Union , Optional , Callable
5
4
import yaml
6
5
import threading
7
6
import time
@@ -25,7 +24,101 @@ def alooHelp() -> None:
25
24
26
25
27
26
def createApp (projectOption : str ) -> None :
28
- pass
27
+ projectName = ""
28
+ projectPath = ""
29
+ if projectOption == "--path" :
30
+ projectName = os .getcwd ()
31
+ else :
32
+ projectName = input ("Project Name \x1b [90m[aloo-project]: " ) or "aloo-project"
33
+ os .system (f"mkdir { projectName } " )
34
+ projectPath = projectName + "/"
35
+ appName = input ("App Description \x1b [90m[Example App]: " ) or "Example App"
36
+ appDesc = (
37
+ input ("App Description \x1b [90m[An default template app for aloo project]: " )
38
+ or "An default template app for aloo project"
39
+ )
40
+
41
+ currFilePath = "/" .join (__file__ .split ("/" )[:- 1 ])
42
+ if currFilePath .endswith ("bin" ):
43
+ currFilePath = "/" .join (__file__ .split ("/" )[:- 2 ]) + "/etc/aloo/"
44
+
45
+ if "aloo.config.yaml" in os .listdir (os .getcwd ()):
46
+ os .system ("clear" )
47
+ raise FileExistsError ("'aloo.config.yaml' already exist" )
48
+ appInfo = yaml .dump (
49
+ {"app-name" : appName , "description" : appDesc , "project-name" : projectName },
50
+ open (projectPath + "aloo.config.yaml" , "w" ),
51
+ )
52
+
53
+ os .mkdir (projectPath + "src" )
54
+ os .mkdir (projectPath + "test" )
55
+ os .system ("clear" )
56
+
57
+ mainC = open (projectPath + "src/main.c" , "w+" )
58
+ testC = open (projectPath + "test/main.c" , "w+" )
59
+ CMakeFile = open (projectPath + "CMakeLists.txt" , "w+" )
60
+
61
+ mainCSample = open (
62
+ currFilePath + "main.c" ,
63
+ "r" ,
64
+ ).read ()
65
+
66
+ testCSample = open (
67
+ currFilePath + "test.c" ,
68
+ "r" ,
69
+ ).read ()
70
+
71
+ CMakeSample = open (
72
+ currFilePath + "CMakeLists.txt" ,
73
+ "r" ,
74
+ ).read ()
75
+ alooDir = currFilePath .removesuffix ("scripts/src/" )
76
+
77
+ mainCSample = mainCSample .replace ("$projectName" , projectName ).replace (
78
+ "$appName" , appName
79
+ )
80
+ mainC .write (mainCSample )
81
+
82
+ testCSample = testCSample .replace ("$projectName" , projectName ).replace (
83
+ "$appName" , appName
84
+ )
85
+ testC .write (testCSample )
86
+
87
+ CMakeSample = CMakeSample .replace ("$appName" , appName ).replace (
88
+ "$include_dir" , alooDir + "include"
89
+ )
90
+ CMakeSample = CMakeSample .replace ("$libaloo" , alooDir + "lib" ).replace (
91
+ "$libaloo" , alooDir + "lib"
92
+ )
93
+ CMakeFile .write (CMakeSample )
94
+
95
+ colorsCSS = open (
96
+ currFilePath + "styles/colors.css" ,
97
+ "r" ,
98
+ ).read ()
99
+ materialCSS = open (
100
+ currFilePath + "styles/material.css" ,
101
+ "r" ,
102
+ ).read ()
103
+
104
+ while colorsCSS .index ("\t " ) != - 1 :
105
+ colorsCSS = colorsCSS .replace ("\t " , "" )
106
+ while colorsCSS .index ("\n " ) != - 1 :
107
+ colorsCSS = colorsCSS .replace ("\n " , "" )
108
+
109
+ while materialCSS .index ("\t " ) != - 1 :
110
+ materialCSS = materialCSS .replace ("\t " , "" )
111
+ while materialCSS .index ("\n " ) != - 1 :
112
+ materialCSS = materialCSS .replace ("\n " , "" )
113
+
114
+ os .mkdir (projectPath + "styles" )
115
+ cssBundle = open (
116
+ projectPath + "styles/material.bundle.min.css" ,
117
+ "w+" ,
118
+ )
119
+ cssBundle .write (materialCSS + colorsCSS )
120
+
121
+ print ("\t \033 [1;32m Aloo project created successfully\033 [0m" )
29
122
30
123
31
124
def loader (i : int ):
@@ -102,9 +195,9 @@ def run(runWhat_App_Test: str) -> None:
102
195
alooHelp ()
103
196
case "create-app" :
104
197
if sys .argv .__len__ () == 2 :
105
- print ("Please give with one of the options: [app | test ]" )
198
+ print ("Please give with one of the options: [--name | --path ]" )
106
199
exit (1 )
107
- elif sys .argv [2 ] != "app " and sys .argv [2 ] != "test " :
200
+ elif sys .argv [2 ] != "--name " and sys .argv [2 ] != "--path " :
108
201
print ("Option must be either --name or --path" )
109
202
exit (1 )
110
203
else :
0 commit comments