-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcli.js
153 lines (130 loc) Β· 4.31 KB
/
cli.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env node
/*
*
* Copyright 2022 flightpkg Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const args = process.argv.slice(2);
const logger = require('./src/shared/logger');
const checks = require('./src/shared/checks')
const { help_menu, version } = require('./src/constants');
const lib_js = require('./src/js/libv2')
const lib_rs = require('./src/rs/lib')
const lib_luau = require('./src/luau/lib')
const lib_py = require('./src/py/lib')
const cp = require("child_process");
const { getVer } = require('./src/cmds/version');
const Sentry = require("@sentry/node");
const Tracing = require("@sentry/tracing");
const frameworks = require('./src/cmds/create')
const frameworks_redwood = require('./src/packages/create-redwood-app/dist/collectInput')
Sentry.init({
dsn: "https://[email protected]/6423338",
tracesSampleRate: 1.0,
});
const update = Sentry.startTransaction({
op: "Update Error",
name: "An error occured during a flight update installation/check.",
});
const commandfail = Sentry.startTransaction({
op: "Command Error",
name: "An error occured while a user ran a flight command.",
});
const checkserror = Sentry.startTransaction({
op: "Checks Error",
name: "An error occured during the initialization checks.",
});
// Catch errors during update process
setTimeout(() => {
try {
checks.install_updates()
} catch (e) {
Sentry.captureException(e);
logger.error(e)
} finally {
update.finish();
}
}, 99);
setTimeout(() => {
try {
checks.init()
} catch (e) {
Sentry.captureException(e);
logger.error(e)
} finally {
checkserror.finish();
}
}, 99);
try {
if (args[0] == "-v" || args[0] == "--version") {
console.log(getVer())
}
if (args[0] == "-js" || args[0] == "--js") {
if (args[1] == "install" || args[1] == "i") {
lib_js.install()
} else if (args[1] == "uninstall") {
lib_js.uninstall(args[1])
} else if (args[1] == "publish") {
if (process.platform == 'linux') {
const child = cp.exec('./src/js/publisher/publish.sh', {stdio: "inherit"})
child.stdout.on('data', (data) => {
console.log(`${data}`);
});
}
if (process.platform == 'linux') {
const child = cp.exec('./src/js/publisher/publish.bat', {stdio: "inherit"})
child.stdout.on('data', (data) => {
console.log(`${data}`);
});
}
child.stderr.on('data', (data) => {
console.error(`ERROR:\n${data}`);
});
} else if (args[0] == undefined || args[0] == "--help" || args[0] == "-h") {
console.log(help_menu)
}
} else if (args[0] == "-rs" || args[0] == "--rs") {
if (args[1] == undefined) {
console.log(help_menu)
} else if (args[1] !== undefined) {
lib_rs.run(args[1])
}} else if (args[0] == "-lua" || args[0] == "--lua"|| args[0] == "--luau" || args[0] == "-luau") {
if (args[1] == undefined) {
console.log(help_menu)
} else if (args[1] !== undefined) {
lib_luau.run(args[1])
}} else if (args[0] == undefined || args[0] == "--help" || args[0] == "-h") {
console.log(help_menu)
}
if (args[0] == "-py" || args[0] == "--py") {
if (args[1] == "install" || args[1] == "i") {
lib_py.install()
}
}
if (args[0] == "create" || args[0] == "init") {
if (args[1] == "next.js" || args[1] == "nextjs") {
frameworks.create('nextjs')
} else if (args[1] == "redwood" || args[1] == "redwoodjs") {
frameworks_redwood.init() // Errors in compiled binary, works in testing.
} else {
logger.error('The requested framework is not supported by flight yet.')
}
}
} catch(e) {
logger.error('An error occurred when running the command requested.')
checks.init(e)
Sentry.captureException(e);
} finally {
commandfail.finish();
}