-
Notifications
You must be signed in to change notification settings - Fork 0
/
tt.js
121 lines (97 loc) · 3.45 KB
/
tt.js
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
import { Command, ValidationError, CompletionsCommand, UpgradeCommand, DenoLandProvider, GithubProvider, colors } from "./deps.js";
import { VERSION } from './version.js'
import { getLogin, getJson, exists } from "./helpers.js";
// account
import loginCommand from './loginCommand/index.js'
import whoamiCommand from './whoamiCommand/index.js'
// supabase projects
import projectsCommand from './projectsCommand/index.js'
// deno projects
import functionsCommand from "./functionsCommand/index.js";
// vercel projects
import vercelCommand from './vercelCommand/index.js'
// tools
import linkCommand from './linkCommand/index.js'
import genCommand from './genCommand/index.js'
const login = await getLogin()
if (login) {
Deno.env.set('TOKEN', login.token)
if (login.deno_deploy_token)
Deno.env.set('DENO_DEPLOY_TOKEN', login.deno_deploy_token)
if (login.vercel_token)
Deno.env.set('VERCEL_ACCESS_TOKEN', login.vercel_token)
}
let project
if (await exists('./tictapp.json')) {
const cfg = await getJson(`./tictapp.json`)
if (cfg && cfg.project) {
project = cfg.project
Deno.env.set('PROJECT_REF', project.ref)
}
}
const tt = new Command()
// Main command.
.name("tt")
.version(VERSION)
if (login) {
tt.meta('Profile', login && colors.cyan(login.profile.primary_email))
}
if (project) {
tt.meta('Project', project && `${colors.bold(project.name || '*')} ${colors.dim(project.ref)} ${colors.green(project.endpoint)}`)
}
tt.meta('Workdir', colors.dim(Deno.cwd()))
tt.description(`The tictapp command line interface
https://github.com/tictapp/cli`)
//.meta('Account', login ? login.profile.primary_email : 'Unauthorized')
.globalOption("-d, --debug", "Enable debug output.")
.globalOption("-w, --workdir [path:file]", "Specify project working directory", {
//default: './',
async action(options) {
try {
Deno.chdir(options.workdir)
} catch (e) {
throw new ValidationError(e)
}
project = null
Deno.env.delete('PROJECT_REF')
if (await exists('./tictapp.json')) {
const cfg = await getJson(`./tictapp.json`)
if (cfg && cfg.project) {
project = cfg.project
Deno.env.set('PROJECT_REF', project.ref)
}
}
// console.log(this)
this.meta('Workdir', colors.dim(Deno.cwd()))
this.meta('Project', project
? `${colors.bold(project.name || '*')} ${colors.dim(project.ref)} ${colors.green(project.endpoint)}`
: colors.dim(`Not linked`))
}
})
.arguments("[command]")
.action(function () {
//console.log('MAIN action', a)
this.showHelp();
return;
})
// account
.command('login', loginCommand)
.command('whoami', whoamiCommand)
// projects
.command('projects', projectsCommand)
.command('functions', functionsCommand)
.command('vercel', vercelCommand)
// tools
.command('link', linkCommand)
.command('gen', genCommand)
.command("completions", new CompletionsCommand())
.command("upgrade", new UpgradeCommand({
main: "tt.js",
args: ["--allow-all"],
provider: [
new DenoLandProvider({ name: 'tictapp' }),
new GithubProvider({ repository: "serebano/tictapp-cli" })
],
}))
.parse(Deno.args);
await tt