-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
75 lines (66 loc) · 2.15 KB
/
cli.ts
File metadata and controls
75 lines (66 loc) · 2.15 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
import { parseArgs } from "https://deno.land/std@0.210.0/cli/parse_args.ts";
import { ensureDirSync } from "https://deno.land/std@0.210.0/fs/ensure_dir.ts";
import { existsSync } from "https://deno.land/std@0.210.0/fs/exists.ts";
const parsedArgs = parseArgs(Deno.args);
if (!parsedArgs["_"][0]) {
console.error(
"\u001b[31m[ERROR]:Please input resource name. ex cli.ts user\u001b[0m",
);
Deno.exit(1);
}
ensureDirSync(`./garden`);
ensureDirSync(`./garden/${parsedArgs["_"][0]}`);
// ./garden/extra_load.tsx が存在しなければ作成する
if (!existsSync(`./garden/extra_load.tsx`)) {
const souceText = "console.log('Load ./garden!');\n";
Deno.writeTextFileSync(
`./garden/extra_load.ts`,
souceText,
);
console.info(`✅ Create File: ./garden/extra_load.ts`);
}
const create = await fetch(
"https://deno.land/x/garden@0.0.1/routesTemplate/create.tsx?source=",
);
const createFilePath = `./garden/${parsedArgs["_"][0]}/create.tsx`;
Deno.writeTextFileSync(
createFilePath,
await create.text(),
);
console.info(`✅ Create File: ${createFilePath}`);
Deno.writeTextFileSync(
`./garden/extra_load.ts`,
`(async () => await import('.${createFilePath}'));\n`,
{ append: true },
);
const login = await fetch(
"https://raw.githubusercontent.com/Octo8080X/garden/main/routesTemplate/create.tsx",
);
const loginFilePath = `./garden/${parsedArgs["_"][0]}/login.tsx`;
Deno.writeTextFileSync(
loginFilePath,
await login.text(),
);
console.info(`✅ Create File: ${loginFilePath}`);
Deno.writeTextFileSync(
`./garden/extra_load.ts`,
`(async () => await import('.${loginFilePath}'));\n`,
{ append: true },
);
const logout = await fetch(
"https://raw.githubusercontent.com/Octo8080X/garden/main/routesTemplate/logout.tsx",
);
const logoutFilePath = `./garden/${parsedArgs["_"][0]}/logout.tsx`;
Deno.writeTextFileSync(
logoutFilePath,
await logout.text(),
);
console.info(`✅ Create File: ${logoutFilePath}`);
Deno.writeTextFileSync(
`./garden/extra_load.ts`,
`(async () => await import('.${logoutFilePath}'));\n`,
{ append: true },
);
console.info(
`Please add \`(async () => await import('./garden/extra_loader.ts'));\` to your main.ts.`,
);