rewrite to es

This commit is contained in:
SrGooglo 2025-02-26 01:42:56 +00:00
parent 9e6f33fead
commit 1033b82d66
6 changed files with 137 additions and 182 deletions

View File

@ -1,19 +1,17 @@
require("dotenv").config() import dotenv from "dotenv"
dotenv.config()
// dependencies import packagejson from "../package.json" assert { type: "json" }
const packagejson = require("../package.json") import path from "path"
const path = require("path") import fs from "fs"
const fs = require("fs") import child_process from "child_process"
const child_process = require("child_process") import { Octokit } from "@octokit/rest"
const { Octokit } = require("@octokit/rest")
// utils import compressDistBundle from "./utils/compressDistBundle.js"
const compressDistBundle = require("./utils/compressDistBundle") import buildAppDist from "./utils/buildAppDist.js"
const buildAppDist = require("./utils/buildAppDist") import createGithubRelease from "./utils/createGithubRelease.js"
const createGithubRelease = require("./utils/createGithubRelease") import uploadAssets from "./utils/uploadAssets.js"
const uploadAssets = require("./utils/uploadAssets") import composeChangelog from "./utils/composeChangelog.js"
const composeChangelog = require("./utils/composeChangelog")
const bumpVersion = require("./utils/bumpVersion")
// constants & paths // constants & paths
const repo = "ragestudio/comty" const repo = "ragestudio/comty"
@ -64,7 +62,7 @@ async function main() {
steps.ignoreVersion = true steps.ignoreVersion = true
} }
// check if is any changes pending to commit // Verifica si hay cambios pendientes para hacer commit
if (!steps.ignoreCommits) { if (!steps.ignoreCommits) {
const gitStatus = child_process const gitStatus = child_process
.execSync("git status --porcelain", { .execSync("git status --porcelain", {
@ -83,7 +81,7 @@ async function main() {
let currentVersion = packagejson.version let currentVersion = packagejson.version
// check if currentVersion match with current latest release on github // Verifica si la versión actual coincide con el último release en GitHub
const latestRelease = await octokit.repos const latestRelease = await octokit.repos
.getLatestRelease({ .getLatestRelease({
owner: repo.split("/")[0], owner: repo.split("/")[0],
@ -101,47 +99,12 @@ async function main() {
if (!steps.ignoreVersion) { if (!steps.ignoreVersion) {
if (latestRelease && latestRelease.data.tag_name === currentVersion) { if (latestRelease && latestRelease.data.tag_name === currentVersion) {
if (process.argv.includes("--bump")) {
const bumpType =
process.argv[process.argv.indexOf("--bump") + 1]
const newVersion = await bumpVersion({
root: process.cwd(),
type: bumpType,
count: 1,
}).catch((error) => {
console.error(`🆘 Failed to bump version >`, error)
return false
})
if (!newVersion) {
throw new Error("Failed to bump version")
}
currentVersion = newVersion
// create new commit
await child_process.execSync(
`git add . && git commit -m "Bump version to ${currentVersion}"`,
{
cwd: process.cwd(),
stdio: "inherit",
},
)
// push to remote
await child_process.execSync(`git push`, {
cwd: process.cwd(),
stdio: "inherit",
})
} else {
console.log( console.log(
"🚫 Current version is already latest version, please bump version first. \n - use --bump <patch|minor|major> to automatically bump version. \n - use --ignore-version to force release.", "🚫 Current version is already latest version, please bump version first. \n - use --bump <patch|minor|major> to automatically bump version. \n - use --ignore-version to force release.",
) )
return true return true
} }
} }
}
if (steps.build) { if (steps.build) {
steps.build = await buildAppDist(appSrcPath) steps.build = await buildAppDist(appSrcPath)
@ -185,17 +148,15 @@ async function main() {
]) ])
console.log("🎉 Assets uploaded! >", assets) console.log("🎉 Assets uploaded! >", assets)
console.log(`🔗 ${release.html_url}`) console.log(`🔗 ${release.html_url}`)
fs.unlinkSync(packedDistPath) fs.unlinkSync(packedDistPath)
} }
console.log("All Done!") console.log("All Done!")
return true return true
} }
main().catch((err) => { main().catch((err) => {
console.error(`Fatal error: `, err) console.error("Fatal error: ", err)
}) })

View File

@ -1,15 +1,13 @@
const child_process = require("child_process") import child_process from "node:child_process"
async function buildAppDist(srcPath) { export default async function buildAppDist(srcPath) {
// build app for production // build app for production
console.log("⚒ Building app...") console.log("⚒ Building app...")
await child_process.execSync("yarn build", { await child_process.execSync("yarn build", {
cwd: srcPath, cwd: srcPath,
stdio: "inherit" stdio: "inherit",
}) })
console.log("⚒ Building app done!") console.log("⚒ Building app done!")
return srcPath return srcPath
} }
module.exports = buildAppDist

View File

@ -1,31 +1,29 @@
require("dotenv").config() import { Octokit } from "@octokit/rest"
const { Octokit } = require("@octokit/rest")
const repo = "ragestudio/comty" const repo = "ragestudio/comty"
const octokit = new Octokit({ const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN, auth: process.env.GITHUB_TOKEN,
}) })
async function getChangeLogString() { export default async function getChangeLogString() {
// get latest tag // get latest tag
const latestTag = await octokit.repos.getLatestRelease({ const latestTag = await octokit.repos.getLatestRelease({
owner: repo.split("/")[0], owner: repo.split("/")[0],
repo: repo.split("/")[1] repo: repo.split("/")[1],
}) })
// get commits since latest tag // get commits since latest tag
const commits = await octokit.repos.listCommits({ const commits = await octokit.repos.listCommits({
owner: repo.split("/")[0], owner: repo.split("/")[0],
repo: repo.split("/")[1], repo: repo.split("/")[1],
since: latestTag.data.published_at since: latestTag.data.published_at,
}) })
let changelog = commits.data.map(async (commit) => { let changelog = commits.data.map(async (commit) => {
const commitData = await octokit.repos.getCommit({ const commitData = await octokit.repos.getCommit({
owner: repo.split("/")[0], owner: repo.split("/")[0],
repo: repo.split("/")[1], repo: repo.split("/")[1],
ref: commit.sha ref: commit.sha,
}) })
const filenamesChanged = commitData.data.files.map((file) => { const filenamesChanged = commitData.data.files.map((file) => {
@ -70,21 +68,25 @@ async function getChangeLogString() {
changelog = await Promise.all(changelog) changelog = await Promise.all(changelog)
// make a string from the changes with Markdown syntax // make a string from the changes with Markdown syntax
let changelogString = changelog.map((commit) => { let changelogString = changelog
const additions = commit.files.map((file) => { .map((commit) => {
const additions = commit.files
.map((file) => {
return file.additions return file.additions
}).reduce((a, b) => a + b, 0) })
.reduce((a, b) => a + b, 0)
const deletions = commit.files.map((file) => { const deletions = commit.files
.map((file) => {
return file.deletions return file.deletions
}).reduce((a, b) => a + b, 0) })
.reduce((a, b) => a + b, 0)
return `* [+${additions}/-${deletions}][${commit.packages.join(" | ")}] [${commit.message}](${commit.url}) - by [@${commit.author}](${commit.authorUrl})` return `* [+${additions}/-${deletions}][${commit.packages.join(" | ")}] [${commit.message}](${commit.url}) - by [@${commit.author}](${commit.authorUrl})`
}).join("\n\n") })
.join("\n\n")
changelogString = changelogString.trim() changelogString = changelogString.trim()
return changelogString return changelogString
} }
module.exports = getChangeLogString

View File

@ -1,7 +1,7 @@
const fs = require("fs") import fs from "node:fs"
const sevenzip = require("7zip-min") import sevenzip from "7zip-min"
async function compressDistBundle(origin, output) { export default async function compressDistBundle(origin, output) {
// compress with 7zip // compress with 7zip
console.log("⚒ Compressing app...") console.log("⚒ Compressing app...")
@ -24,5 +24,3 @@ async function compressDistBundle(origin, output) {
return output return output
} }
module.exports = compressDistBundle

View File

@ -1,25 +1,23 @@
const axios = require("axios") import axios from "axios"
async function createGithubRelease(repo, payload, token) { export default async function createGithubRelease(repo, payload, token) {
const { version, changelog } = payload const { version, changelog } = payload
const response = await axios({ const response = await axios({
method: "post", method: "post",
url: `https://api.github.com/repos/${repo}/releases`, url: `https://api.github.com/repos/${repo}/releases`,
headers: { headers: {
"Authorization": `token ${token}`, Authorization: `token ${token}`,
"Content-Type": "application/json" "Content-Type": "application/json",
}, },
data: { data: {
tag_name: version, tag_name: version,
name: `v${version}`, name: `v${version}`,
body: changelog body: changelog,
} },
}) })
console.log("⚒ Creating release done!") console.log("⚒ Creating release done!")
return response.data return response.data
} }
module.exports = createGithubRelease

View File

@ -1,4 +1,4 @@
async function uploadAssets(octokit, repo, release, assets) { export default async function uploadAssets(octokit, repo, release, assets) {
console.log("⚒ Uploading assets...") console.log("⚒ Uploading assets...")
console.log(`ReleaseID: ${release.id}`) console.log(`ReleaseID: ${release.id}`)
@ -19,5 +19,3 @@ async function uploadAssets(octokit, repo, release, assets) {
return true return true
} }
module.exports = uploadAssets