generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf3d5c6
commit 54293ac
Showing
56 changed files
with
1,356 additions
and
760 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import manifest from '../../manifest.json' assert { type: 'json' }; | ||
|
||
export function getBuildBanner(buildType: string, getVersion: (version: string) => string) { | ||
return `/* | ||
------------------------------------------- | ||
${manifest.name} - ${buildType} | ||
------------------------------------------- | ||
By: ${manifest.author} (${manifest.authorUrl}) | ||
Time: ${new Date().toUTCString()} | ||
Version: ${getVersion(manifest.version)} | ||
------------------------------------------- | ||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD | ||
if you want to view the source, please visit the github repository of this plugin | ||
------------------------------------------- | ||
MIT License | ||
Copyright (c) ${new Date().getFullYear()} ${manifest.author} | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
`; | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import esbuild from 'esbuild'; | ||
import copy from 'esbuild-plugin-copy-watch'; | ||
import esbuildSvelte from 'esbuild-svelte'; | ||
import sveltePreprocess from 'svelte-preprocess'; | ||
import manifest from '../../manifest.json' assert { type: 'json' }; | ||
import { getBuildBanner } from 'build/buildBanner'; | ||
|
||
const banner = getBuildBanner('Dev Build', _ => 'Dev Build'); | ||
|
||
const context = await esbuild.context({ | ||
banner: { | ||
js: banner, | ||
}, | ||
entryPoints: ['src/main.ts'], | ||
bundle: true, | ||
external: [ | ||
'obsidian', | ||
'electron', | ||
'@codemirror/autocomplete', | ||
'@codemirror/collab', | ||
'@codemirror/commands', | ||
'@codemirror/language', | ||
'@codemirror/lint', | ||
'@codemirror/search', | ||
'@codemirror/state', | ||
'@codemirror/view', | ||
'@lezer/common', | ||
'@lezer/highlight', | ||
'@lezer/lr', | ||
], | ||
format: 'cjs', | ||
target: 'es2018', | ||
logLevel: 'info', | ||
sourcemap: 'inline', | ||
treeShaking: true, | ||
outdir: `exampleVault/.obsidian/plugins/${manifest.id}/`, | ||
outbase: 'src', | ||
define: { | ||
MB_GLOBAL_CONFIG_DEV_BUILD: 'true', | ||
}, | ||
plugins: [ | ||
copy({ | ||
paths: [ | ||
{ | ||
from: './styles.css', | ||
to: '', | ||
}, | ||
{ | ||
from: './manifest.json', | ||
to: '', | ||
}, | ||
], | ||
}), | ||
esbuildSvelte({ | ||
compilerOptions: { css: 'injected', dev: true, sveltePath: 'svelte' }, | ||
preprocess: sveltePreprocess(), | ||
filterWarnings: warning => { | ||
// we don't want warnings from node modules that we can do nothing about | ||
return !warning.filename?.includes('node_modules'); | ||
}, | ||
}), | ||
], | ||
}); | ||
|
||
await context.watch(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"devBranch": "master", | ||
"releaseBranch": "release", | ||
"github": "https://github.com/mProjectsCode/obsidian-media-db-plugin" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import { UserError } from 'utils/utils'; | ||
import { CanaryVersion, Version, getIncrementOptions, parseVersion, stringifyVersion } from 'utils/versionUtils'; | ||
import config from './config.json'; | ||
import { $choice as $choice, $confirm, $seq, CMD_FMT, Verboseness } from 'utils/shellUtils'; | ||
|
||
async function runPreconditions(): Promise<void> { | ||
// run preconditions | ||
await $seq( | ||
[`bun run format`, `bun run lint:fix`, `bun run test`], | ||
(cmd: string) => { | ||
throw new UserError(`precondition "${cmd}" failed`); | ||
}, | ||
() => {}, | ||
undefined, | ||
Verboseness.VERBOSE, | ||
); | ||
|
||
// add changed files | ||
await $seq( | ||
[`git add .`], | ||
() => { | ||
throw new UserError('failed to add preconditions changes to git'); | ||
}, | ||
() => {}, | ||
undefined, | ||
Verboseness.NORMAL, | ||
); | ||
|
||
// check if there were any changes | ||
let changesToCommit = false; | ||
await $seq( | ||
[`git diff --quiet`, `git diff --cached --quiet`], | ||
() => { | ||
changesToCommit = true; | ||
}, | ||
() => {}, | ||
undefined, | ||
Verboseness.QUITET, | ||
); | ||
|
||
// if there were any changes, commit them | ||
if (changesToCommit) { | ||
await $seq( | ||
[`git commit -m "[auto] run release preconditions"`], | ||
() => { | ||
throw new UserError('failed to add preconditions changes to git'); | ||
}, | ||
() => {}, | ||
undefined, | ||
Verboseness.NORMAL, | ||
); | ||
} | ||
} | ||
|
||
async function run() { | ||
console.log('looking for untracked changes ...'); | ||
|
||
// check for any uncommited files and exit if there are any | ||
await $seq( | ||
[`git add .`, `git diff --quiet`, `git diff --cached --quiet`, `git checkout ${config.devBranch}`], | ||
() => { | ||
throw new UserError('there are still untracked changes'); | ||
}, | ||
() => {}, | ||
undefined, | ||
Verboseness.QUITET, | ||
); | ||
|
||
console.log('\nrunning preconditions ...\n'); | ||
|
||
await runPreconditions(); | ||
|
||
console.log('\nbumping versions ...\n'); | ||
|
||
const manifestFile = Bun.file('./manifest.json'); | ||
const manifest = await manifestFile.json(); | ||
|
||
const versionString: string = manifest.version; | ||
const currentVersion: Version = parseVersion(versionString); | ||
const currentVersionString = stringifyVersion(currentVersion); | ||
|
||
const versionIncrementOptions = getIncrementOptions(currentVersion); | ||
|
||
const selectedIndex = await $choice( | ||
`Current version "${currentVersionString}". Select new version`, | ||
versionIncrementOptions.map(x => stringifyVersion(x)), | ||
); | ||
const newVersion = versionIncrementOptions[selectedIndex]; | ||
const newVersionString = stringifyVersion(newVersion); | ||
|
||
console.log(''); | ||
|
||
await $confirm(`Version will be updated "${currentVersionString}" -> "${newVersionString}". Are you sure`, () => { | ||
throw new UserError('user canceled script'); | ||
}); | ||
|
||
if (!(newVersion instanceof CanaryVersion)) { | ||
manifest.version = newVersionString; | ||
} | ||
|
||
await Bun.write(manifestFile, JSON.stringify(manifest, null, '\t')); | ||
|
||
const betaManifest = structuredClone(manifest); | ||
betaManifest.version = newVersionString; | ||
|
||
const betaManifestFile = Bun.file('./manifest-beta.json'); | ||
await Bun.write(betaManifestFile, JSON.stringify(betaManifest, null, '\t')); | ||
|
||
if (!(newVersion instanceof CanaryVersion)) { | ||
const versionsFile = Bun.file('./versions.json'); | ||
const versionsJson = await versionsFile.json(); | ||
|
||
versionsJson[newVersionString] = manifest.minAppVersion; | ||
|
||
await Bun.write(versionsFile, JSON.stringify(versionsJson, null, '\t')); | ||
|
||
const packageFile = Bun.file('./package.json'); | ||
const packageJson = await packageFile.json(); | ||
|
||
packageJson.version = newVersionString; | ||
|
||
await Bun.write(packageFile, JSON.stringify(packageJson, null, '\t')); | ||
} | ||
|
||
await $seq( | ||
[`bun run format`, `git add .`, `git commit -m "[auto] bump version to \`${newVersionString}\`"`], | ||
() => { | ||
throw new UserError('failed to add preconditions changes to git'); | ||
}, | ||
() => {}, | ||
undefined, | ||
Verboseness.NORMAL, | ||
); | ||
|
||
console.log('\ncreating release tag ...\n'); | ||
|
||
await $seq( | ||
[ | ||
`git checkout ${config.releaseBranch}`, | ||
`git merge ${config.devBranch} --commit -m "[auto] merge \`${newVersionString}\` release commit"`, | ||
`git push origin ${config.releaseBranch}`, | ||
`git tag -a ${newVersionString} -m "release version ${newVersionString}"`, | ||
`git push origin ${newVersionString}`, | ||
`git checkout ${config.devBranch}`, | ||
`git merge ${config.releaseBranch}`, | ||
`git push origin ${config.devBranch}`, | ||
], | ||
() => { | ||
throw new UserError('failed to merge or create tag'); | ||
}, | ||
() => {}, | ||
undefined, | ||
Verboseness.NORMAL, | ||
); | ||
|
||
console.log(''); | ||
|
||
console.log(`${CMD_FMT.BgGreen}done${CMD_FMT.Reset}`); | ||
console.log(`${config.github}`); | ||
console.log(`${config.github}/releases/tag/${newVersionString}`); | ||
} | ||
|
||
try { | ||
await run(); | ||
} catch (e) { | ||
if (e instanceof UserError) { | ||
console.error(e.message); | ||
} else { | ||
console.error(e); | ||
} | ||
} |
Oops, something went wrong.