Skip to content

Commit 11bc8e6

Browse files
committed
move to bun
1 parent 1fd1e65 commit 11bc8e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+799
-7029
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ npm node_modules
22
build
33
main.js
44
Publish.js
5+
*.svelte

.eslintrc

Lines changed: 0 additions & 22 deletions
This file was deleted.

.eslintrc.cjs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/** @type {import('eslint').Linter.Config} */
2+
const config = {
3+
root: true,
4+
parser: '@typescript-eslint/parser',
5+
env: {
6+
node: true,
7+
},
8+
plugins: ['isaacscript', 'import', 'only-warn'],
9+
extends: [
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/eslint-recommended',
12+
'plugin:@typescript-eslint/recommended',
13+
'plugin:@typescript-eslint/recommended-type-checked',
14+
'plugin:@typescript-eslint/stylistic-type-checked',
15+
],
16+
parserOptions: {
17+
sourceType: 'module',
18+
tsconfigRootDir: __dirname,
19+
ecmaVersion: 'latest',
20+
project: ['./tsconfig.json'],
21+
},
22+
rules: {
23+
'@typescript-eslint/no-explicit-any': ['warn'],
24+
25+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_' }],
26+
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports', fixStyle: 'inline-type-imports' }],
27+
28+
'@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: true }],
29+
'@typescript-eslint/restrict-template-expressions': 'off',
30+
31+
'@typescript-eslint/ban-ts-comment': 'off',
32+
'@typescript-eslint/no-empty-function': 'off',
33+
'@typescript-eslint/no-inferrable-types': 'off',
34+
'@typescript-eslint/explicit-function-return-type': ['warn'],
35+
'@typescript-eslint/require-await': 'off',
36+
},
37+
};
38+
39+
module.exports = config;

.prettierrc.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2-
"printWidth": 180,
2+
"plugins": ["prettier-plugin-svelte"],
3+
4+
"printWidth": 160,
35
"useTabs": true,
46
"semi": true,
57
"singleQuote": true,
6-
"arrowParens": "avoid"
8+
"arrowParens": "avoid",
9+
10+
"svelteAllowShorthand": false
711
}

automation/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"devBranch": "master",
3+
"releaseBranch": "release",
4+
"github": "https://github.com/mProjectsCode/obsidian-js-engine-plugin"
5+
}

automation/release.ts

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import { $seq, Verboseness, $input, $choise, $confirm, CMD_FMT } from './shellUtils';
2+
import config from './config.json';
3+
import { Version, getIncrementOptions, parseVersion, stringifyVersion } from 'versionUtils';
4+
import { UserError } from 'utils';
5+
6+
async function runPreconditions(): Promise<void> {
7+
// run preconditions
8+
await $seq(
9+
[`bun run format`, `bun run lint:fix`, `bun run test`],
10+
(cmd: string) => {
11+
throw new UserError(`precondition "${cmd}" failed`);
12+
},
13+
() => {},
14+
Verboseness.VERBOSE,
15+
);
16+
17+
// add changed files
18+
await $seq(
19+
[`git add .`],
20+
() => {
21+
throw new UserError('failed to add preconditions changes to git');
22+
},
23+
() => {},
24+
Verboseness.NORMAL,
25+
);
26+
27+
// check if there were any changes
28+
let changesToCommit = false;
29+
await $seq(
30+
[`git diff --quiet`, `git diff --cached --quiet`],
31+
() => {
32+
changesToCommit = true;
33+
},
34+
() => {},
35+
Verboseness.QUITET,
36+
);
37+
38+
// if there were any changes, commit them
39+
if (changesToCommit) {
40+
await $seq(
41+
[`git commit -m "[auto] run release preconditions"`],
42+
() => {
43+
throw new UserError('failed to add preconditions changes to git');
44+
},
45+
() => {},
46+
Verboseness.NORMAL,
47+
);
48+
}
49+
}
50+
51+
async function run() {
52+
console.log('looking for untracked changes ...');
53+
54+
// check for any uncommited files and exit if there are any
55+
await $seq(
56+
[`git add .`, `git diff --quiet`, `git diff --cached --quiet`, `git checkout ${config.devBranch}`],
57+
() => {
58+
throw new UserError('there are still untracked changes');
59+
},
60+
() => {},
61+
Verboseness.QUITET,
62+
);
63+
64+
console.log('\nrunning preconditions ...\n');
65+
66+
await runPreconditions();
67+
68+
console.log('\nbumping versions ...\n');
69+
70+
const manifestFile = Bun.file('./manifest.json');
71+
const manifest = await manifestFile.json();
72+
73+
const versionString: string = manifest.version;
74+
const currentVersion: Version = parseVersion(versionString);
75+
const currentVersionString = stringifyVersion(currentVersion);
76+
77+
const versionIncrementOptions = getIncrementOptions(currentVersion);
78+
79+
const selctedIndex = await $choise(
80+
`Current version "${currentVersionString}". Select new version`,
81+
versionIncrementOptions.map(x => stringifyVersion(x)),
82+
);
83+
const newVersion = versionIncrementOptions[selctedIndex];
84+
const newVersionString = stringifyVersion(newVersion);
85+
86+
console.log('');
87+
88+
await $confirm(`Version will be updated "${currentVersionString}" -> "${newVersionString}". Are you sure`, () => {
89+
throw new UserError('user canceled script');
90+
});
91+
92+
manifest.version = newVersionString;
93+
94+
await Bun.write(manifestFile, JSON.stringify(manifest, null, '\t'));
95+
96+
const versionsFile = Bun.file('./versions.json');
97+
const versionsJson = await versionsFile.json();
98+
99+
versionsJson[newVersionString] = manifest.minAppVersion;
100+
101+
await Bun.write(versionsFile, JSON.stringify(versionsJson, null, '\t'));
102+
103+
const packageFile = Bun.file('./package.json');
104+
const packageJson = await packageFile.json();
105+
106+
packageJson.version = newVersionString;
107+
108+
await Bun.write(packageFile, JSON.stringify(packageJson, null, '\t'));
109+
110+
await $seq(
111+
[`bun run format`, `git add .`, `git commit -m "[auto] bump version to \`${newVersionString}\`"`],
112+
() => {
113+
throw new UserError('failed to add preconditions changes to git');
114+
},
115+
() => {},
116+
Verboseness.NORMAL,
117+
);
118+
119+
console.log('\ncreating release tag ...\n');
120+
121+
await $seq(
122+
[
123+
`git checkout ${config.releaseBranch}`,
124+
`git merge ${config.devBranch} --commit -m "[auto] merge \`${newVersionString}\` release commit"`,
125+
`git push origin ${config.releaseBranch}`,
126+
`git tag -a ${newVersionString} -m "release version ${newVersionString}"`,
127+
`git push origin ${newVersionString}`,
128+
`git checkout ${config.devBranch}`,
129+
`git merge ${config.releaseBranch}`,
130+
`git push origin ${config.devBranch}`,
131+
],
132+
() => {
133+
throw new UserError('failed to merge or create tag');
134+
},
135+
() => {},
136+
Verboseness.NORMAL,
137+
);
138+
139+
console.log('');
140+
141+
console.log(`${CMD_FMT.BgGreen}done${CMD_FMT.Reset}`);
142+
console.log(`${config.github}`);
143+
console.log(`${config.github}/releases/tag/${newVersionString}`);
144+
}
145+
146+
try {
147+
await run();
148+
} catch (e) {
149+
if (e instanceof UserError) {
150+
console.error(e.message);
151+
} else {
152+
console.error(e);
153+
}
154+
}

0 commit comments

Comments
 (0)