2021-04-19 19:54:29 +00:00
|
|
|
import { createInterface } from 'readline';
|
|
|
|
import { readFileSync, writeFileSync } from 'fs';
|
|
|
|
|
2021-05-05 17:18:07 +00:00
|
|
|
import { exec as _exec } from 'child_process';
|
|
|
|
import { promisify } from 'util';
|
|
|
|
|
|
|
|
const exec = promisify(_exec);
|
|
|
|
|
2021-04-19 19:54:29 +00:00
|
|
|
const rl = createInterface({
|
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2021-05-05 17:18:07 +00:00
|
|
|
const [ type1, type2, repo, subpath ] = process.argv.slice(2);
|
2021-04-19 19:54:29 +00:00
|
|
|
|
2021-05-05 17:18:07 +00:00
|
|
|
console.log(type1, type2, repo, subpath);
|
2021-04-19 19:54:29 +00:00
|
|
|
|
2021-05-05 17:18:07 +00:00
|
|
|
const ask = async (prompt) => {
|
|
|
|
return await new Promise((resp) => {
|
|
|
|
rl.question(prompt, (ans) => {
|
|
|
|
resp(ans);
|
2021-04-19 19:54:29 +00:00
|
|
|
});
|
2021-05-05 17:18:07 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const repeatAsk = async (prompt) => {
|
|
|
|
const answers = [];
|
2021-04-19 19:54:29 +00:00
|
|
|
|
|
|
|
let ans;
|
|
|
|
|
|
|
|
while (ans !== '') {
|
2021-05-05 17:18:07 +00:00
|
|
|
ans = await ask(prompt);
|
2021-04-19 19:54:29 +00:00
|
|
|
if (ans === '') break;
|
|
|
|
|
|
|
|
answers.push(ans);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log();
|
|
|
|
|
|
|
|
return answers;
|
|
|
|
};
|
|
|
|
|
|
|
|
const authors = await repeatAsk(`Add Author (leave blank if no more) > `);
|
|
|
|
|
|
|
|
console.log(authors);
|
|
|
|
|
|
|
|
const images = await repeatAsk(`Add Image (leave blank if no more) > `);
|
|
|
|
|
|
|
|
console.log(images);
|
|
|
|
|
|
|
|
let js, file;
|
|
|
|
|
|
|
|
switch (type1) {
|
|
|
|
case 'theme': {
|
|
|
|
switch (type2) {
|
|
|
|
case 'pc': {
|
|
|
|
file = `src/modules/ports/themes/pcThemes.js`;
|
|
|
|
js = ` ['${repo}', '', '/powercord_manifest.json', 'pcTheme', {
|
|
|
|
authors: ${JSON.stringify(authors)},
|
|
|
|
images: ${JSON.stringify(images)}
|
|
|
|
}],`;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2021-05-05 17:18:07 +00:00
|
|
|
|
|
|
|
case 'bd': {
|
|
|
|
file = `src/modules/ports/themes/bdThemes.js`;
|
|
|
|
js = ` ['${repo}', '', '${subpath}', 'bdTheme', {
|
|
|
|
authors: ${JSON.stringify(authors)},
|
|
|
|
images: ${JSON.stringify(images)}
|
|
|
|
}],`;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2021-04-19 19:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(js, file);
|
|
|
|
|
|
|
|
let contents = readFileSync(file, 'utf8').split('\n');
|
|
|
|
|
|
|
|
contents.splice(-1, 0, '', ...js.split('\n'));
|
|
|
|
|
|
|
|
contents = contents.join('\n');
|
|
|
|
|
|
|
|
writeFileSync(file, contents);
|
|
|
|
|
2021-05-05 17:18:07 +00:00
|
|
|
const shouldCommit = await new Promise((resp) => {
|
|
|
|
rl.question(`Continue with automated Git (Y/N) > `, (ans) => {
|
|
|
|
resp(ans);
|
|
|
|
});
|
|
|
|
}) === 'Y';
|
|
|
|
|
|
|
|
if (shouldCommit) {
|
|
|
|
console.log('Building...');
|
|
|
|
|
|
|
|
await exec(`node src/index.js`);
|
|
|
|
|
|
|
|
console.log('Committing...');
|
|
|
|
|
|
|
|
await exec(`git add dist ${file}`);
|
|
|
|
|
|
|
|
await exec(`git commit -m "[(Auto) Add Theme (${type2.toUpperCase()}Theme)] ${repo}"`);
|
|
|
|
|
|
|
|
console.log('Pushing...');
|
|
|
|
|
|
|
|
await exec(`git push`);
|
|
|
|
}
|
|
|
|
|
2021-04-19 19:54:29 +00:00
|
|
|
rl.close();
|