2020-04-26 22:05:19 +00:00
|
|
|
import {promises as fsp} from 'fs';
|
|
|
|
import {join} from 'path';
|
|
|
|
import prompts from 'prompts';
|
|
|
|
import semver from 'semver';
|
|
|
|
|
|
|
|
export interface Versions {
|
|
|
|
[index: string]: string;
|
|
|
|
firefox: string;
|
|
|
|
kitty: string;
|
|
|
|
'sublime-text': string;
|
|
|
|
tauon: string;
|
|
|
|
vscode: string;
|
|
|
|
}
|
|
|
|
|
2020-08-06 12:47:06 +00:00
|
|
|
export async function main(): Promise<void> {
|
2020-04-26 22:05:19 +00:00
|
|
|
const versions: Versions = await getVersions();
|
|
|
|
|
|
|
|
const command = await prompts({
|
|
|
|
message: 'What do you want to do?',
|
|
|
|
name: 'command',
|
|
|
|
type: 'select',
|
|
|
|
choices: [
|
|
|
|
{
|
|
|
|
title: 'Show',
|
|
|
|
value: 'show'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Update',
|
|
|
|
value: 'update'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
initial: 0
|
|
|
|
});
|
|
|
|
if (command.command === 'show') {
|
|
|
|
console.log(versions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command.command === 'update') {
|
|
|
|
const whichTheme = await prompts({
|
|
|
|
message: 'Which theme do you want to update?',
|
|
|
|
name: 'theme',
|
|
|
|
type: 'select',
|
2020-08-06 12:47:06 +00:00
|
|
|
choices: Object.keys(versions).map((value) => ({
|
2020-04-26 22:05:19 +00:00
|
|
|
title: `${value} (${String(versions[value])})`,
|
|
|
|
value
|
|
|
|
})),
|
|
|
|
initial: 0
|
|
|
|
});
|
|
|
|
|
|
|
|
const currentVersion: string = versions[whichTheme.theme];
|
|
|
|
const whichVersion = await prompts({
|
|
|
|
message: 'To what version do you want to update?',
|
|
|
|
name: 'version',
|
|
|
|
type: 'select',
|
|
|
|
choices: [
|
|
|
|
{
|
|
|
|
title: `Major (${currentVersion} -> ${semver.inc(
|
|
|
|
currentVersion,
|
|
|
|
'major'
|
|
|
|
)!})`,
|
|
|
|
value: 'major'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: `Minor (${currentVersion} -> ${semver.inc(
|
|
|
|
currentVersion,
|
|
|
|
'minor'
|
|
|
|
)!})`,
|
|
|
|
value: 'minor'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: `Patch (${currentVersion} -> ${semver.inc(
|
|
|
|
currentVersion,
|
|
|
|
'patch'
|
|
|
|
)!})`,
|
|
|
|
value: 'patch'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
initial: 0
|
|
|
|
});
|
|
|
|
|
|
|
|
const selectedTheme: string = whichTheme.theme;
|
|
|
|
const newVersion: string = semver.inc(
|
|
|
|
currentVersion,
|
|
|
|
whichVersion.version
|
|
|
|
)!;
|
|
|
|
versions[selectedTheme] = newVersion;
|
|
|
|
await fsp.writeFile(
|
|
|
|
join(__dirname, '../../love-versions.json'),
|
|
|
|
JSON.stringify(versions, null, 2) + '\n'
|
|
|
|
);
|
|
|
|
|
2020-08-06 13:05:50 +00:00
|
|
|
if (['vscode'].includes(selectedTheme)) {
|
2020-04-26 22:05:19 +00:00
|
|
|
const packageLocation: string = join(
|
|
|
|
__dirname,
|
|
|
|
`../${selectedTheme}/package.json`
|
|
|
|
);
|
|
|
|
const themePackage: any = JSON.parse(
|
|
|
|
await fsp.readFile(packageLocation, 'utf8')
|
|
|
|
);
|
|
|
|
themePackage.version = newVersion;
|
|
|
|
await fsp.writeFile(
|
|
|
|
packageLocation,
|
|
|
|
JSON.stringify(themePackage, null, 2) + '\n'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getVersions(): Promise<Versions> {
|
|
|
|
return JSON.parse(
|
|
|
|
await fsp.readFile(join(__dirname, '../../love-versions.json'), 'utf8')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (require.main === module) {
|
2020-08-06 12:47:06 +00:00
|
|
|
void main();
|
2020-04-26 22:05:19 +00:00
|
|
|
}
|