Last active
May 3, 2022 04:29
-
-
Save BertiKarsunke/2f158be41f960f446f1a11d870a89770 to your computer and use it in GitHub Desktop.
refresh Apple authentication For Fastlane with google zx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zx | |
console.warn("restore apple credential : start") | |
//need env files | |
const content = await fs.readFile('.env', 'utf8') | |
const env_array = content.split("\n") | |
let email; | |
for (const iterator of env_array) { | |
if(iterator.indexOf("USERNAME") != -1){ | |
let elarry = iterator.split("="); | |
elarry[1] = elarry[1].replaceAll('"',""); | |
email = elarry[1].trim(); | |
} | |
} | |
const mailRegexp =/\S+@\S+\.\S+/; | |
if(mailRegexp.test(email)){ | |
console.log(chalk.blue('restore apple credential : ') + chalk.red(email)) | |
}else{ | |
console.log(chalk.red('cant read enviroment email address') + chalk.green(email)) | |
await $`exit 1` | |
} | |
// console.log(chalk.red('restore apple credential')) | |
// await $`fastlane fastlane-credentials add --username ${email}` | |
await $`rm -rf ~/.fastlane/spaceship/${email}` | |
let result = await $`fastlane spaceauth -u ${email}` | |
// console.log(result.stdout); | |
let resultStout = result.stdout; | |
// let resultText = await fs.readFile('./result.txt', "utf8") | |
let splitresult = resultStout.split("\n"); | |
let command = "" | |
for (const el of splitresult) { | |
if(el.indexOf("export FASTLANE_SESSION=") != -1){ | |
// console.log(el) | |
command = el; | |
} | |
} | |
if(command.length > 0){ | |
await $`echo ${command}` | |
}else{ | |
console.log(chalk.red('failed : ') + chalk.blue("restore apple credential")) | |
await $`exit 1` | |
} | |
console.log(chalk.blue('finish : ') + chalk.white("restore apple credential")) | |
await $`exit 1` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment