-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
4 changed files
with
52 additions
and
4 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
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,44 @@ | ||
import { applyEdits, modify, parse } from 'jsonc-parser' | ||
import { promises as fs } from 'node:fs' | ||
import { resolve } from 'node:path' | ||
import semver from 'semver' | ||
import { readPackageJSON } from 'pkg-types' | ||
|
||
import type { ParseError } from 'jsonc-parser' | ||
|
||
async function main() { | ||
const npmPath = resolve(process.cwd(), 'package.json') | ||
const npm = await readPackageJSON(npmPath) | ||
if (npm.version == null) { | ||
throw new Error('Failed to read package.json: version is not found') | ||
} | ||
|
||
const denoPath = resolve(process.cwd(), 'deno.jsonc') | ||
const denoConfig = await fs.readFile(denoPath, 'utf-8').catch(() => '{}') | ||
const errors: ParseError[] = [] | ||
const deno = parse(denoConfig, errors, { allowTrailingComma: true }) | ||
if (errors.length > 0) { | ||
throw new Error(`Failed to parse deno.jsonc: ${errors.map((e) => e.error).join(', ')}`) | ||
} | ||
if (deno.version == null) { | ||
throw new Error('Failed to read deno.jsonc: version is not found') | ||
} | ||
|
||
if (!semver.gt(npm.version, deno.version)) { | ||
throw new Error( | ||
`Failed to bump: npm version (${npm.version}) is not greater than deno version (${deno.version})`, | ||
) | ||
} | ||
|
||
console.log(`Bump deno version to ${npm.version}`) | ||
const denoConfigEdit = modify(denoConfig, ['version'], npm.version, { | ||
formattingOptions: { tabSize: 2, insertSpaces: true }, | ||
}) | ||
const denoConfigModified = applyEdits(denoConfig, denoConfigEdit) | ||
await fs.writeFile(denoPath, denoConfigModified) | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |