Skip to content

Commit 2632721

Browse files
committed
hello world
1 parent 515cdf5 commit 2632721

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1578
-0
lines changed

LICENSE

+373
Large diffs are not rendered by default.

TheOldGuard.jpg

125 KB
Loading

banner.png

28.4 KB
Loading

core/cli.ts

+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
import Template from '../io/temp/temp.ts'
2+
import App from '../io/app/index.ts'
3+
4+
let isAppCreated : Boolean | undefined;
5+
6+
//#region update to new file
7+
async function createApp(){
8+
9+
try{
10+
11+
for await (const dirEntry of Deno.readDir("client")) {
12+
if(dirEntry.name.toString() == "china"){
13+
isAppCreated = true;
14+
}
15+
16+
}
17+
18+
if(!isAppCreated){
19+
20+
getApp();
21+
}
22+
23+
console.log("happy coding...🦖");
24+
25+
26+
}catch(e){
27+
28+
if(Deno.errors.NotFound.name == e.name){
29+
console.log("File Does not Exist")
30+
createFolder();
31+
}
32+
}
33+
}
34+
35+
36+
async function createFolder(){
37+
38+
console.log("Creating Client Folder")
39+
try{
40+
41+
let folder = await Deno.mkdir("client");
42+
console.log("Folder Created");
43+
console.log("Creating the app");
44+
await getApp();
45+
46+
47+
}catch(e){
48+
49+
if(Deno.errors.AlreadyExists.name == e.name){
50+
console.log("Folder Already Exists")
51+
}
52+
53+
}
54+
55+
}
56+
57+
58+
async function getApp(){
59+
60+
const gitProcess = Deno.run({
61+
cmd: ["git","clone","https://github.com/devUniversity/project-china.git","client/china"],
62+
stdout: "piped",
63+
stderr: "piped",
64+
});
65+
66+
const { code } = await gitProcess.status();
67+
68+
if (code === 0) {
69+
const rawOutput = await gitProcess.output();
70+
await Deno.stdout.write(rawOutput);
71+
72+
const status = await commandGit("rm",["-rf","--cached"," ."]);
73+
74+
75+
if(status === true ){
76+
Deno.chdir("client/china");
77+
78+
const result = await commandGit("remote",["rename","origin","china"]);
79+
80+
if(result == true){
81+
82+
console.log("happy coding...🦖 you can contribute with the china remote");
83+
}
84+
85+
}else{
86+
87+
console.log("China Directory does not exist");
88+
}
89+
90+
91+
92+
} else {
93+
const rawError = await gitProcess.stderrOutput();
94+
const errorString = new TextDecoder().decode(rawError);
95+
console.log("project already exsists you may begin coding");
96+
}
97+
98+
Deno.exit(code);
99+
}
100+
101+
102+
103+
async function commandGit(command: string, flags: string[]){
104+
// TODO make this more modular
105+
106+
console.log(flags);
107+
const gitProcess = Deno.run({
108+
cmd: ["git",command,flags[0],flags[1],flags[2]],
109+
stdout: "piped",
110+
stderr: "piped",
111+
});
112+
113+
114+
const { code } = await gitProcess.status();
115+
116+
if (code === 0) {
117+
const rawOutput = await gitProcess.output();
118+
await Deno.stdout.write(rawOutput);
119+
120+
return true
121+
}
122+
else{
123+
const rawError = await gitProcess.stderrOutput();
124+
const errorString = new TextDecoder().decode(rawError);
125+
126+
if(errorString.includes("pathspec")){
127+
console.log(errorString,"cache has already been cleared");
128+
return true;
129+
}else{
130+
console.log(errorString,"failed to clear cache");
131+
return false;
132+
}
133+
134+
135+
}
136+
}
137+
138+
139+
//#endregion
140+
141+
142+
143+
if (import.meta.main) {
144+
145+
const expr = Deno.args[1];
146+
switch (expr) {
147+
case 'spa':
148+
console.log("starting to create app...");
149+
createApp();
150+
break;
151+
case 'Server':
152+
console.log('Creating Server');
153+
// expected output: "Mangoes and papayas are $2.79 a pound."
154+
break;
155+
case 'template':
156+
Template()
157+
// expected output: "Mangoes and papayas are $2.79 a pound."
158+
break;
159+
case 'app':
160+
console.log("init app");
161+
App();
162+
// expected output: "Mangoes and papayas are $2.79 a pound."
163+
break;
164+
default:
165+
console.log(`Sorry, you need to select and option checkout --help to find out what is availbile`);
166+
}
167+
168+
169+
}

core/echo.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const watcher = Deno.watchFs('./');
2+
let filename: string | undefined;
3+
4+
5+
async function fileWatcher(){
6+
try{
7+
for await (const event of watcher){
8+
console.log(">>>> event", event.kind)
9+
if(event.kind.toString() == "modify" ){
10+
console.log("updating server");
11+
runDeno();
12+
}
13+
}
14+
}
15+
16+
catch(e){
17+
console.log(e)
18+
}
19+
20+
21+
}
22+
23+
24+
async function runDeno(){
25+
26+
try {
27+
const gitProcess = Deno.run({
28+
cmd: ["deno","run","--allow-read","--allow-write","--allow-run", filename!],
29+
});
30+
31+
await gitProcess.status
32+
}
33+
catch(e){
34+
console.log(e)
35+
}
36+
37+
}
38+
39+
40+
41+
if (import.meta.main) {
42+
43+
filename = Deno.args[0];
44+
fileWatcher();
45+
console.log("Watching the file", filename);
46+
47+
}
48+

core/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>Hello Worlds</p>

core/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Serve
2+
` deno run --allow-run --allow-read --allow-net ./oldguard/core/server.ts`

core/server.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { serve, ServerRequest, Response } from "https://deno.land/std/http/server.ts";
2+
import { Status } from "https://deno.land/std/http/http_status.ts";
3+
import { serveFile } from "https://deno.land/std/http/file_server.ts";
4+
5+
6+
const server = serve({ port: 8000 });
7+
console.log("http://localhost:8000/");
8+
for await (const req of server) {
9+
10+
let params = req.url.split("?")[1]
11+
console.log(params)
12+
let searchParams = new URLSearchParams(params);
13+
const decoder = new TextDecoder();
14+
const buf: Uint8Array = await Deno.readAll(req.body);
15+
console.log(decoder.decode(buf))
16+
console.log(req.url)
17+
console.log(searchParams.get("type"))
18+
19+
20+
let response: Response = {};
21+
try {
22+
if (req.url == "/") {
23+
24+
response = await serveFile(req, './oldguard/core/index.html');
25+
}else{
26+
response.body = JSON.stringify({ name: "Hello World" })
27+
}
28+
} catch {
29+
response.body = JSON.stringify({ name: "Error" })
30+
}
31+
32+
req.headers.set("Content-Type", "application/json");
33+
34+
response.status = Status.OK
35+
req.respond(response);
36+
serverLog(req, response!);
37+
38+
}
39+
40+
41+
42+
43+
44+
function serverLog(req: ServerRequest, res: Response): void {
45+
const d = new Date().toISOString();
46+
const dateFmt = `[${d.slice(0, 10)} ${d.slice(11, 19)}]`;
47+
const s = `${dateFmt} "${req.method} ${req.url} ${req.proto}" ${res.status}`;
48+
console.log(s);
49+
}

imports/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import "https://deno.land/x/dotenv/load.ts";
2+
import cmdState from '../utils/cmd.ts'
3+
import prompt from '../utils/cmd.ts'
4+
import CraeteFolder from '../utils/folder.ts'
5+
import commandGit from '../utils/cmdGit.ts'
6+
7+
const env = Deno.env;
8+
9+
export {cmdState, prompt,env,CraeteFolder,commandGit}

index.ts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import "./imports/index.ts";
2+
const env = Deno.env;
3+
let url = Deno.cwd() + "/" + env.get('tool');
4+
5+
async function runCli() {
6+
7+
try {
8+
9+
let cloudUrl = env.get('toolCloud')
10+
// console.log(Deno.env.toObject());
11+
console.log("Hello",env.get('USERNAME'))
12+
13+
if (Deno.args[0] == "cloud" && cloudUrl) {
14+
console.log('getting cloud version')
15+
url= cloudUrl.toString()
16+
} else {
17+
console.log('init local version')
18+
}
19+
20+
const gitProcess = Deno.run({
21+
cmd: ["deno", "run", "--allow-read", "--allow-write", "--allow-run","--allow-env", `${url}/core/cli.ts`, ...Deno.args],
22+
stderr: "piped",
23+
});
24+
25+
26+
27+
const { code } = await gitProcess.status();
28+
29+
if (code === 0) {
30+
//const rawOutput = await gitProcess.output();
31+
// await Deno.stdout.write(rawOutput);
32+
33+
// const rawInput = await gitProcess.stdin.write();
34+
//await Deno.stdout.write(rawOutput);
35+
} else {
36+
const rawError = await gitProcess.stderrOutput();
37+
const errorString = new TextDecoder().decode(rawError);
38+
console.log(errorString, "please indicate the project you would like to create");
39+
}
40+
41+
Deno.exit(code);
42+
}
43+
catch (e) {
44+
console.log("failing to do something", e)
45+
}
46+
47+
}
48+
49+
50+
if (import.meta.main) {
51+
52+
runCli();
53+
54+
}

0 commit comments

Comments
 (0)