-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
306 lines (263 loc) · 11.5 KB
/
index.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import figlet from 'figlet'
import ora from 'ora'
import { execa, execaCommand } from 'execa'
import chalk from 'chalk'
import inquirer from 'inquirer'
import gradient from 'gradient-string'
import { existsSync, mkdirSync } from 'fs'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
const { textSync } = figlet
const __dirname = dirname(fileURLToPath(import.meta.url))
const filesDir = join(__dirname, `rvs-files`)
let ytName;
let rvName;
let patchArr = new Array();
await console.clear()
const rvGradient = gradient(['#bb2ea1', '#ebf92b'])
console.log(rvGradient(textSync(`ReVanced-Script`)))
async function main() {
console.log(chalk.bold.green(`Checks`))
async function mkdir() {
const spinner = ora(`Create a directory for our files to sit in...`).start()
if (!existsSync(filesDir)) {
mkdirSync(filesDir);
spinner.succeed(chalk.greenBright(`Created files directory.`))
} else {
spinner.warn(chalk.yellowBright(`Files directory already exists, ${chalk.italic(`skipping...`)}`))
}
} await mkdir()
async function checkJava() {
const spinner = ora(`Checking if Zulu JDK 17 is installed...`).start()
const { stdout } = await execa('java', ['--version']).catch(() => {
const errTxt = `Java is not installed.`
spinner.fail(chalk.bold.red(errTxt))
throw new Error(errTxt)
})
if (!stdout.includes(`Zulu`)) {
const errTxt = `Zulu is not installed.`
spinner.fail(chalk.bold.red(errTxt))
throw new Error(errTxt)
}
if (!stdout.includes(`Zulu17`)) {
const errTxt = `Zulu is installed but with a incorrect version.`
spinner.fail(chalk.bold.red(errTxt))
throw new Error(errTxt)
}
spinner.succeed(chalk.greenBright(`Zulu JDK is installed...`))
} await checkJava()
async function checkCurl() {
const spinner = ora(`Checking if curl is installed...`).start()
await execa('curl', [`--version`]).catch(() => {
const errTxt = `Curl is not installed.`
spinner.fail(chalk.bold.red(errTxt))
throw new Error(errTxt)
})
spinner.succeed(chalk.greenBright(`curl is installed...`))
} await checkCurl()
console.log(chalk.bold.green(`Downloads`))
async function dlPkg() {
await cli()
async function cli() {
const spinner = ora(`Downloading CLI...`).start()
if (existsSync(join(filesDir, `cli.jar`))) {
spinner.warn(chalk.yellowBright(`CLI already exists, ${chalk.italic(`skipping...`)}`))
return
}
const { stdout } = await execa('curl', ['-s', 'https://api.github.com/repos/revanced/revanced-cli/releases/latest']).catch(err =>
{
console.log(chalk.bold.red(`Error occured while executing command`))
throw new Error(err)
}
)
const json = JSON.parse(stdout)
const version = json[`tag_name`].substring(1)
await execa('curl',
[
'-Locli.jar',
`https://github.com/revanced/revanced-cli/releases/download/v${version}/revanced-cli-${version}-all.jar`
],
{
cwd: filesDir
}
).catch(err =>
{
console.log(chalk.bold.red(`Error occured while executing command`))
throw new Error(err)
}
)
spinner.succeed(chalk.greenBright(`CLI successfully downloaded...`))
}
await patches()
async function patches() {
const spinner = ora(`Downloading Patches...`).start()
if (existsSync(join(filesDir, `patches.jar`))) {
spinner.warn(chalk.yellowBright(`Patches already exists, ${chalk.italic(`skipping...`)}`))
return
}
const { stdout } = await execa('curl', ['-s', 'https://api.github.com/repos/revanced/revanced-patches/releases/latest']).catch(err =>
{
console.log(chalk.bold.red(`Error occured while executing command`))
throw new Error(err)
}
)
const json = JSON.parse(stdout)
const version = json[`tag_name`].substring(1)
await execa('curl',
[
'-Lopatches.jar',
`https://github.com/revanced/revanced-patches/releases/download/v${version}/revanced-patches-${version}.jar`
],
{
cwd: filesDir
}
).catch(err =>
{
console.log(chalk.bold.red(`Error occured while executing command`))
throw new Error(err)
}
)
spinner.succeed(chalk.greenBright(`Patches successfully downloaded...`))
}
await integ()
async function integ() {
const spinner = ora(`Downloading Integrations...`).start()
if (existsSync(join(filesDir, `integ.apk`))) {
spinner.warn(chalk.yellowBright(`Integrations already exists, ${chalk.italic(`skipping...`)}`))
return
}
await execa('curl',
[
'-Lointeg.apk',
`https://github.com/revanced/revanced-integrations/releases/download/v0.27.0/app-release-unsigned.apk`
],
{
cwd: filesDir
}
).catch(err =>
{
console.log(chalk.bold.red(`Error occured while executing command`))
throw new Error(err)
}
)
spinner.succeed(chalk.greenBright(`Integrations successfully downloaded...`))
}
} await dlPkg()
console.log(chalk.bold.green(`Configuration`))
async function configure() {
async function ytApk() {
await inquirer.prompt(
{
type: `input`,
name: `ytApk`,
message: `What is your YouTube apk filename?\n rvs-files: ${filesDir}\n ${chalk.italic(`(file must be in the 'rvs-files' directory and must have no spaces in its name)`)}`,
default: `yt.apk`,
validate: function (input) {
const done = this.async();
async function checkFile() {
if(/\s/g.test(input)){
done(chalk.yellowBright(`⚠ File must have no spaces in its name, please rename your apk file.`))
return
}
if (!existsSync(join(filesDir, input))) {
done(chalk.yellowBright(`⚠ File does not exist, please double check your spelling.`))
return
}
ytName = input
done(null, true)
} checkFile();
}
}
)
} await ytApk()
async function slctPatches() {
const { stdout } = await execaCommand(`java -jar cli.jar -a ${ytName} -c -l -o revanced.apk -b patches.jar -m integ.apk`,
{
cwd: filesDir
}
).catch(err =>
{
console.log(chalk.bold.red(`Error occured while executing command`))
throw new Error(err)
}
)
let outputArr = stdout.toString().replace(/\r\n/g, '\n').split('\n')
let nameArr = outputArr.map(line => {
let cleaned = line.replaceAll('INFO:', '')
cleaned = cleaned.replaceAll('"', "'")
cleaned = cleaned.replaceAll(/\t/g, ' ')
return cleaned
})
let choicesArr = []
for (let name of nameArr) {
const value = name.trim().split(' ')[0]
await choicesArr.push(JSON.parse(`{"name": "${name}", "value": "${value}", "short": "${value}"}`))
}
await inquirer.prompt(
{
type: `checkbox`,
name: `patchArr`,
message: `Select your preferred patches.`,
pageSize: 15,
choices: choicesArr,
validate: function (input) {
const done = this.async();
async function check() {
if (!input.length > 0) {
done(chalk.yellowBright(`⚠ You must pick atleast one of the patches.`))
return
}
patchArr = input
done(null, true)
} check();
}
}
)
} await slctPatches()
async function apkName() {
await inquirer.prompt(
{
type: `input`,
name: `apkName`,
message: `What would you like your ReVanced apk be named?\n (spaces and '.apk' will be removed.)`,
default: `revanced`,
validate: function (input) {
const done = this.async();
async function check() {
let name = input.replaceAll(` `, '')
if (!name) {
done(chalk.yellowBright(`⚠ Name cannot be empty`))
return
}
if (name.endsWith(`.apk`)) {
name.replace(`.apk`, ``)
}
rvName = name
done(null, true)
} check();
}
}
)
} await apkName()
} await configure()
async function build() {
console.log(chalk.yellowBright(`⚠ Starting build with ${patchArr.length} patches...`))
let patchString = ``
for(let patch in patchArr){
patchString = patchString += `-i ${patchArr[patch]} `
}
const command = execaCommand(`java -jar cli.jar -a ${ytName} -c -o ${rvName}.apk -b patches.jar -m integ.apk --exclusive ${patchString}`,
{
cwd: filesDir
}
)
command.stdout.pipe(process.stdout)
const {stdout} = await command
console.log(stdout)
console.log(chalk.bold.greenBright(`✔ Successfully built ReVanced apk.`))
console.log(chalk.greenBright(`You should be able to see your APK inside of the 'rvs-files' directory with the name you have given it.`))
console.log(chalk.greenBright(`Either you can install it through adb or pass the apk file onto your phone and install it directly.`))
console.log(`Support the development of this script by giving the repository a star: https://github.com/Norikiru/ReVanced-Script`)
console.log(`Script made by Norikiru, based on CnC-Robert's bash script: https://github.com/CnC-Robert/revanced-cli-script`)
} await build()
} main();