Skip to content

Commit eea02b7

Browse files
committed
canary releases
1 parent 80f8129 commit eea02b7

File tree

4 files changed

+106
-46
lines changed

4 files changed

+106
-46
lines changed

automation/release.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { $seq, Verboseness, $input, $choise, $confirm, CMD_FMT } from './shellUtils';
1+
import { $seq, Verboseness, $input, $choise as $choice, $confirm, CMD_FMT } from './shellUtils';
22
import config from './config.json';
3-
import { Version, getIncrementOptions, parseVersion, stringifyVersion } from 'versionUtils';
3+
import { CanaryVersion, Version, getIncrementOptions, parseVersion, stringifyVersion } from 'versionUtils';
44
import { UserError } from 'utils';
55

66
async function runPreconditions(): Promise<void> {
@@ -70,17 +70,20 @@ async function run() {
7070
const manifestFile = Bun.file('./manifest.json');
7171
const manifest = await manifestFile.json();
7272

73+
const betaManifestFile = Bun.file('./manifest-beta.json');
74+
const betaManifest = await betaManifestFile.json();
75+
7376
const versionString: string = manifest.version;
7477
const currentVersion: Version = parseVersion(versionString);
7578
const currentVersionString = stringifyVersion(currentVersion);
7679

7780
const versionIncrementOptions = getIncrementOptions(currentVersion);
7881

79-
const selctedIndex = await $choise(
82+
const selectedIndex = await $choice(
8083
`Current version "${currentVersionString}". Select new version`,
8184
versionIncrementOptions.map(x => stringifyVersion(x)),
8285
);
83-
const newVersion = versionIncrementOptions[selctedIndex];
86+
const newVersion = versionIncrementOptions[selectedIndex];
8487
const newVersionString = stringifyVersion(newVersion);
8588

8689
console.log('');
@@ -89,23 +92,30 @@ async function run() {
8992
throw new UserError('user canceled script');
9093
});
9194

92-
manifest.version = newVersionString;
95+
if (!(newVersion instanceof CanaryVersion)) {
96+
manifest.version = newVersionString;
97+
}
98+
99+
betaManifest.version = newVersionString;
93100

94101
await Bun.write(manifestFile, JSON.stringify(manifest, null, '\t'));
102+
await Bun.write(betaManifestFile, JSON.stringify(betaManifest, null, '\t'));
95103

96-
const versionsFile = Bun.file('./versions.json');
97-
const versionsJson = await versionsFile.json();
104+
if (!(newVersion instanceof CanaryVersion)) {
105+
const versionsFile = Bun.file('./versions.json');
106+
const versionsJson = await versionsFile.json();
98107

99-
versionsJson[newVersionString] = manifest.minAppVersion;
108+
versionsJson[newVersionString] = manifest.minAppVersion;
100109

101-
await Bun.write(versionsFile, JSON.stringify(versionsJson, null, '\t'));
110+
await Bun.write(versionsFile, JSON.stringify(versionsJson, null, '\t'));
102111

103-
const packageFile = Bun.file('./package.json');
104-
const packageJson = await packageFile.json();
112+
const packageFile = Bun.file('./package.json');
113+
const packageJson = await packageFile.json();
105114

106-
packageJson.version = newVersionString;
115+
packageJson.version = newVersionString;
107116

108-
await Bun.write(packageFile, JSON.stringify(packageJson, null, '\t'));
117+
await Bun.write(packageFile, JSON.stringify(packageJson, null, '\t'));
118+
}
109119

110120
await $seq(
111121
[`bun run format`, `git add .`, `git commit -m "[auto] bump version to \`${newVersionString}\`"`],

automation/shellUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function $(cmd: string, verboseness: Verboseness = Verboseness.NORM
4444

4545
if (verboseness === Verboseness.NORMAL || verboseness === Verboseness.VERBOSE) {
4646
if (exit === 0) {
47-
console.log(`${CMD_FMT.FgGreen}sucess${CMD_FMT.Reset} - ${cmd}\n`);
47+
console.log(`${CMD_FMT.FgGreen}success${CMD_FMT.Reset} - ${cmd}\n`);
4848
} else {
4949
console.log(`${CMD_FMT.FgRed}fail${CMD_FMT.Reset} - ${cmd} - code ${exit}\n`);
5050
}
@@ -107,7 +107,7 @@ export async function $choise(message: string, options: string[]): Promise<numbe
107107
ret = optionNumbers.get(selectedStr);
108108

109109
if (ret === undefined) {
110-
console.log(`${CMD_FMT.FgRed}invalid slection, please select a valid option${CMD_FMT.Reset}`);
110+
console.log(`${CMD_FMT.FgRed}invalid selection, please select a valid option${CMD_FMT.Reset}`);
111111
}
112112
}
113113

@@ -127,7 +127,7 @@ export async function $confirm(message: string, onReject: () => void): Promise<v
127127
return;
128128
}
129129

130-
console.log(`${CMD_FMT.FgRed}invalid slection, please select a valid option${CMD_FMT.Reset}`);
130+
console.log(`${CMD_FMT.FgRed}invalid selection, please select a valid option${CMD_FMT.Reset}`);
131131
}
132132
}
133133

automation/versionUtils.ts

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,35 @@ import { P } from '@lemons_dev/parsinom/lib/ParsiNOM';
22
import { P_UTILS } from '@lemons_dev/parsinom/lib/ParserUtils';
33
import { Parser } from '@lemons_dev/parsinom/lib/Parser';
44
import { UserError } from 'utils';
5+
import Moment from 'moment';
56

6-
export interface Version {
7+
export class Version {
78
major: number;
89
minor: number;
910
patch: number;
11+
12+
constructor(major: number, minor: number, patch: number) {
13+
this.major = major;
14+
this.minor = minor;
15+
this.patch = patch;
16+
}
17+
18+
toString(): string {
19+
return `${this.major}.${this.minor}.${this.patch}`;
20+
}
21+
}
22+
23+
export class CanaryVersion extends Version {
24+
canary: string;
25+
26+
constructor(major: number, minor: number, patch: number, canary: string) {
27+
super(major, minor, patch);
28+
this.canary = canary;
29+
}
30+
31+
toString(): string {
32+
return `${super.toString()}-canary.${this.canary}`;
33+
}
1034
}
1135

1236
const numberParser: Parser<number> = P_UTILS.digits()
@@ -19,19 +43,44 @@ const numberParser: Parser<number> = P_UTILS.digits()
1943
}
2044
});
2145

22-
export const versionParser: Parser<Version> = P.sequenceMap(
23-
(major, _1, minor, _2, patch) => {
24-
return {
25-
major,
26-
minor,
27-
patch,
28-
};
46+
const canaryParser: Parser<string> = P.sequenceMap(
47+
(_, c1, c2, c3) => {
48+
return c1 + c2 + c3;
2949
},
30-
numberParser,
31-
P.string('.'),
32-
numberParser,
33-
P.string('.'),
34-
numberParser,
50+
P.string('-canary.'),
51+
P_UTILS.digit()
52+
.repeat(8, 8)
53+
.map(x => x.join('')),
54+
P.string('T'),
55+
P_UTILS.digit()
56+
.repeat(6, 6)
57+
.map(x => x.join('')),
58+
);
59+
60+
export const versionParser: Parser<Version> = P.or(
61+
P.sequenceMap(
62+
(major, _1, minor, _2, patch) => {
63+
return new Version(major, minor, patch);
64+
},
65+
numberParser,
66+
P.string('.'),
67+
numberParser,
68+
P.string('.'),
69+
numberParser,
70+
P_UTILS.eof(),
71+
),
72+
P.sequenceMap(
73+
(major, _1, minor, _2, patch, canary) => {
74+
return new CanaryVersion(major, minor, patch, canary);
75+
},
76+
numberParser,
77+
P.string('.'),
78+
numberParser,
79+
P.string('.'),
80+
numberParser,
81+
canaryParser,
82+
P_UTILS.eof(),
83+
),
3584
);
3685

3786
export function parseVersion(str: string): Version {
@@ -44,25 +93,16 @@ export function parseVersion(str: string): Version {
4493
}
4594

4695
export function stringifyVersion(version: Version): string {
47-
return `${version.major}.${version.minor}.${version.patch}`;
96+
return version.toString();
4897
}
4998

50-
export function getIncrementOptions(version: Version): [Version, Version, Version] {
99+
export function getIncrementOptions(version: Version): [Version, Version, Version, CanaryVersion] {
100+
const moment = Moment();
101+
const canary = moment.format('YYYYMMDDTHHmmss');
51102
return [
52-
{
53-
major: version.major + 1,
54-
minor: 0,
55-
patch: 0,
56-
},
57-
{
58-
major: version.major,
59-
minor: version.minor + 1,
60-
patch: 0,
61-
},
62-
{
63-
major: version.major,
64-
minor: version.minor,
65-
patch: version.patch + 1,
66-
},
103+
new Version(version.major + 1, 0, 0),
104+
new Version(version.major, version.minor + 1, 0),
105+
new Version(version.major, version.minor, version.patch + 1),
106+
new CanaryVersion(version.major, version.minor, version.patch, canary),
67107
];
68108
}

manifest-beta.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": "lemons-plugin-template",
3+
"name": "Lemons Plugin Template",
4+
"version": "0.0.4",
5+
"minAppVersion": "1.4.0",
6+
"description": "This is a sample plugin for Obsidian. This plugin demonstrates some of the capabilities of the Obsidian API.",
7+
"author": "Moritz Jung",
8+
"authorUrl": "https://mprojectscode.github.io/",
9+
"isDesktopOnly": false
10+
}

0 commit comments

Comments
 (0)