-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.js
More file actions
executable file
·79 lines (62 loc) · 2.09 KB
/
Copy pathrun.js
File metadata and controls
executable file
·79 lines (62 loc) · 2.09 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
import { load } from "https://deno.land/std@0.177.0/dotenv/mod.ts";
import { exists, getJson } from "./helpers.js";
import { Select } from "https://deno.land/x/cliffy@v0.25.7/prompt/select.ts";
import { colors } from "https://deno.land/x/cliffy@v0.25.7/ansi/mod.ts";
export default async function _run(args) {
let functionName = args._.shift()
let funPath = `./functions/${functionName}`
if (!functionName) {
funPath = Deno.cwd()
functionName = funPath.split("/").pop()
Deno.chdir('../../')
if (await exists('./tictapp.json')) {
const { project } = await getJson(`./tictapp.json`)
if (project) {
Deno.env.set('PROJECT_REF', project.ref)
}
}
console.log(colors.red(`Function Auto`), { funPath, functionName, cwd: Deno.cwd() })
//Deno.exit()
}
const envVars = await load({
envPath: `functions/${functionName}/.env`,
defaultsPath: `.env.defaults`,
export: false
});
if ((await exists(`./functions/${functionName}/deno.json`))) {
const p = Deno.run({
cmd: [
Deno.execPath(),
"task",
"--config",
`./functions/${functionName}/deno.json`,
"--cwd",
`./functions/${functionName}`,
"start"
],
env: envVars,
});
await p.status()
} else {
let entrypoint = `./functions/${functionName}/index.js`
if (!(await exists(entrypoint)))
entrypoint = `./functions/${functionName}/index.ts`
if (!(await exists(entrypoint))) {
console.error(`Entrypoint failed: ${entrypoint}`)
Deno.exit()
}
const p = Deno.run({
cmd: [
Deno.execPath(),
"run",
"--allow-all",
"--watch",
"--import-map",
`./functions/import_map.json`,
entrypoint
],
env: envVars,
});
await p.status()
}
}