mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
rewrite to es
This commit is contained in:
parent
9e6f33fead
commit
1033b82d66
@ -1,19 +1,17 @@
|
||||
require("dotenv").config()
|
||||
import dotenv from "dotenv"
|
||||
dotenv.config()
|
||||
|
||||
// dependencies
|
||||
const packagejson = require("../package.json")
|
||||
const path = require("path")
|
||||
const fs = require("fs")
|
||||
const child_process = require("child_process")
|
||||
const { Octokit } = require("@octokit/rest")
|
||||
import packagejson from "../package.json" assert { type: "json" }
|
||||
import path from "path"
|
||||
import fs from "fs"
|
||||
import child_process from "child_process"
|
||||
import { Octokit } from "@octokit/rest"
|
||||
|
||||
// utils
|
||||
const compressDistBundle = require("./utils/compressDistBundle")
|
||||
const buildAppDist = require("./utils/buildAppDist")
|
||||
const createGithubRelease = require("./utils/createGithubRelease")
|
||||
const uploadAssets = require("./utils/uploadAssets")
|
||||
const composeChangelog = require("./utils/composeChangelog")
|
||||
const bumpVersion = require("./utils/bumpVersion")
|
||||
import compressDistBundle from "./utils/compressDistBundle.js"
|
||||
import buildAppDist from "./utils/buildAppDist.js"
|
||||
import createGithubRelease from "./utils/createGithubRelease.js"
|
||||
import uploadAssets from "./utils/uploadAssets.js"
|
||||
import composeChangelog from "./utils/composeChangelog.js"
|
||||
|
||||
// constants & paths
|
||||
const repo = "ragestudio/comty"
|
||||
@ -64,7 +62,7 @@ async function main() {
|
||||
steps.ignoreVersion = true
|
||||
}
|
||||
|
||||
// check if is any changes pending to commit
|
||||
// Verifica si hay cambios pendientes para hacer commit
|
||||
if (!steps.ignoreCommits) {
|
||||
const gitStatus = child_process
|
||||
.execSync("git status --porcelain", {
|
||||
@ -83,7 +81,7 @@ async function main() {
|
||||
|
||||
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
|
||||
.getLatestRelease({
|
||||
owner: repo.split("/")[0],
|
||||
@ -101,45 +99,10 @@ async function main() {
|
||||
|
||||
if (!steps.ignoreVersion) {
|
||||
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(
|
||||
"🚫 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
|
||||
}
|
||||
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.",
|
||||
)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,17 +148,15 @@ async function main() {
|
||||
])
|
||||
|
||||
console.log("🎉 Assets uploaded! >", assets)
|
||||
|
||||
console.log(`🔗 ${release.html_url}`)
|
||||
|
||||
fs.unlinkSync(packedDistPath)
|
||||
}
|
||||
|
||||
console.log("All Done!")
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(`Fatal error: `, err)
|
||||
console.error("Fatal error: ", err)
|
||||
})
|
||||
|
@ -1,15 +1,13 @@
|
||||
const child_process = require("child_process")
|
||||
import child_process from "node:child_process"
|
||||
|
||||
async function buildAppDist(srcPath) {
|
||||
// build app for production
|
||||
console.log("⚒ Building app...")
|
||||
await child_process.execSync("yarn build", {
|
||||
cwd: srcPath,
|
||||
stdio: "inherit"
|
||||
})
|
||||
console.log("⚒ Building app done!")
|
||||
export default async function buildAppDist(srcPath) {
|
||||
// build app for production
|
||||
console.log("⚒ Building app...")
|
||||
await child_process.execSync("yarn build", {
|
||||
cwd: srcPath,
|
||||
stdio: "inherit",
|
||||
})
|
||||
console.log("⚒ Building app done!")
|
||||
|
||||
return srcPath
|
||||
return srcPath
|
||||
}
|
||||
|
||||
module.exports = buildAppDist
|
@ -1,90 +1,92 @@
|
||||
require("dotenv").config()
|
||||
|
||||
const { Octokit } = require("@octokit/rest")
|
||||
import { Octokit } from "@octokit/rest"
|
||||
const repo = "ragestudio/comty"
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: process.env.GITHUB_TOKEN,
|
||||
auth: process.env.GITHUB_TOKEN,
|
||||
})
|
||||
|
||||
async function getChangeLogString() {
|
||||
// get latest tag
|
||||
const latestTag = await octokit.repos.getLatestRelease({
|
||||
owner: repo.split("/")[0],
|
||||
repo: repo.split("/")[1]
|
||||
})
|
||||
export default async function getChangeLogString() {
|
||||
// get latest tag
|
||||
const latestTag = await octokit.repos.getLatestRelease({
|
||||
owner: repo.split("/")[0],
|
||||
repo: repo.split("/")[1],
|
||||
})
|
||||
|
||||
// get commits since latest tag
|
||||
const commits = await octokit.repos.listCommits({
|
||||
owner: repo.split("/")[0],
|
||||
repo: repo.split("/")[1],
|
||||
since: latestTag.data.published_at
|
||||
})
|
||||
// get commits since latest tag
|
||||
const commits = await octokit.repos.listCommits({
|
||||
owner: repo.split("/")[0],
|
||||
repo: repo.split("/")[1],
|
||||
since: latestTag.data.published_at,
|
||||
})
|
||||
|
||||
let changelog = commits.data.map(async (commit) => {
|
||||
const commitData = await octokit.repos.getCommit({
|
||||
owner: repo.split("/")[0],
|
||||
repo: repo.split("/")[1],
|
||||
ref: commit.sha
|
||||
})
|
||||
let changelog = commits.data.map(async (commit) => {
|
||||
const commitData = await octokit.repos.getCommit({
|
||||
owner: repo.split("/")[0],
|
||||
repo: repo.split("/")[1],
|
||||
ref: commit.sha,
|
||||
})
|
||||
|
||||
const filenamesChanged = commitData.data.files.map((file) => {
|
||||
return file.filename
|
||||
})
|
||||
const filenamesChanged = commitData.data.files.map((file) => {
|
||||
return file.filename
|
||||
})
|
||||
|
||||
// check packages involved in each commit
|
||||
let packagesChanged = filenamesChanged.map((file) => {
|
||||
// search for the pkg name in the path (eg packages/app/src/...)
|
||||
const pkg = file.split("/")[1]
|
||||
// check packages involved in each commit
|
||||
let packagesChanged = filenamesChanged.map((file) => {
|
||||
// search for the pkg name in the path (eg packages/app/src/...)
|
||||
const pkg = file.split("/")[1]
|
||||
|
||||
// if the pkg is not found, return null
|
||||
if (!pkg) return null
|
||||
// if the pkg is not found, return null
|
||||
if (!pkg) return null
|
||||
|
||||
return pkg
|
||||
})
|
||||
return pkg
|
||||
})
|
||||
|
||||
// filter out null values
|
||||
packagesChanged = packagesChanged.filter((pkg) => {
|
||||
return pkg !== null
|
||||
})
|
||||
// filter out null values
|
||||
packagesChanged = packagesChanged.filter((pkg) => {
|
||||
return pkg !== null
|
||||
})
|
||||
|
||||
// remove duplicates
|
||||
packagesChanged = [...new Set(packagesChanged)]
|
||||
// remove duplicates
|
||||
packagesChanged = [...new Set(packagesChanged)]
|
||||
|
||||
// if no packages changed, return "internal"
|
||||
if (packagesChanged.length === 0) {
|
||||
packagesChanged = ["internal"]
|
||||
}
|
||||
// if no packages changed, return "internal"
|
||||
if (packagesChanged.length === 0) {
|
||||
packagesChanged = ["internal"]
|
||||
}
|
||||
|
||||
return {
|
||||
message: commitData.data.commit.message,
|
||||
author: commitData.data.commit.author.name,
|
||||
authorUrl: commitData.data.author.html_url,
|
||||
url: commit.html_url,
|
||||
filenamesChanged: filenamesChanged,
|
||||
files: commitData.data.files,
|
||||
packages: packagesChanged,
|
||||
}
|
||||
})
|
||||
return {
|
||||
message: commitData.data.commit.message,
|
||||
author: commitData.data.commit.author.name,
|
||||
authorUrl: commitData.data.author.html_url,
|
||||
url: commit.html_url,
|
||||
filenamesChanged: filenamesChanged,
|
||||
files: commitData.data.files,
|
||||
packages: packagesChanged,
|
||||
}
|
||||
})
|
||||
|
||||
changelog = await Promise.all(changelog)
|
||||
changelog = await Promise.all(changelog)
|
||||
|
||||
// make a string from the changes with Markdown syntax
|
||||
let changelogString = changelog.map((commit) => {
|
||||
const additions = commit.files.map((file) => {
|
||||
return file.additions
|
||||
}).reduce((a, b) => a + b, 0)
|
||||
// make a string from the changes with Markdown syntax
|
||||
let changelogString = changelog
|
||||
.map((commit) => {
|
||||
const additions = commit.files
|
||||
.map((file) => {
|
||||
return file.additions
|
||||
})
|
||||
.reduce((a, b) => a + b, 0)
|
||||
|
||||
const deletions = commit.files.map((file) => {
|
||||
return file.deletions
|
||||
}).reduce((a, b) => a + b, 0)
|
||||
const deletions = commit.files
|
||||
.map((file) => {
|
||||
return file.deletions
|
||||
})
|
||||
.reduce((a, b) => a + b, 0)
|
||||
|
||||
return `* [+${additions}/-${deletions}][${commit.packages.join(" | ")}] [${commit.message}](${commit.url}) - by [@${commit.author}](${commit.authorUrl})`
|
||||
}).join("\n\n")
|
||||
return `* [+${additions}/-${deletions}][${commit.packages.join(" | ")}] [${commit.message}](${commit.url}) - by [@${commit.author}](${commit.authorUrl})`
|
||||
})
|
||||
.join("\n\n")
|
||||
|
||||
changelogString = changelogString.trim()
|
||||
changelogString = changelogString.trim()
|
||||
|
||||
return changelogString
|
||||
return changelogString
|
||||
}
|
||||
|
||||
module.exports = getChangeLogString
|
@ -1,28 +1,26 @@
|
||||
const fs = require("fs")
|
||||
const sevenzip = require("7zip-min")
|
||||
import fs from "node:fs"
|
||||
import sevenzip from "7zip-min"
|
||||
|
||||
async function compressDistBundle(origin, output) {
|
||||
// compress with 7zip
|
||||
console.log("⚒ Compressing app...")
|
||||
export default async function compressDistBundle(origin, output) {
|
||||
// compress with 7zip
|
||||
console.log("⚒ Compressing app...")
|
||||
|
||||
// check if out file exists
|
||||
if (fs.existsSync(output)) {
|
||||
fs.unlinkSync(output)
|
||||
}
|
||||
// check if out file exists
|
||||
if (fs.existsSync(output)) {
|
||||
fs.unlinkSync(output)
|
||||
}
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
sevenzip.pack(origin, output, (err) => {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
await new Promise((resolve, reject) => {
|
||||
sevenzip.pack(origin, output, (err) => {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
|
||||
return resolve(output)
|
||||
})
|
||||
})
|
||||
return resolve(output)
|
||||
})
|
||||
})
|
||||
|
||||
console.log("⚒ Compressing app done! > " + output)
|
||||
console.log("⚒ Compressing app done! > " + output)
|
||||
|
||||
return output
|
||||
return output
|
||||
}
|
||||
|
||||
module.exports = compressDistBundle
|
@ -1,25 +1,23 @@
|
||||
const axios = require("axios")
|
||||
import axios from "axios"
|
||||
|
||||
async function createGithubRelease(repo, payload, token) {
|
||||
const { version, changelog } = payload
|
||||
export default async function createGithubRelease(repo, payload, token) {
|
||||
const { version, changelog } = payload
|
||||
|
||||
const response = await axios({
|
||||
method: "post",
|
||||
url: `https://api.github.com/repos/${repo}/releases`,
|
||||
headers: {
|
||||
"Authorization": `token ${token}`,
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
data: {
|
||||
tag_name: version,
|
||||
name: `v${version}`,
|
||||
body: changelog
|
||||
}
|
||||
})
|
||||
const response = await axios({
|
||||
method: "post",
|
||||
url: `https://api.github.com/repos/${repo}/releases`,
|
||||
headers: {
|
||||
Authorization: `token ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
data: {
|
||||
tag_name: version,
|
||||
name: `v${version}`,
|
||||
body: changelog,
|
||||
},
|
||||
})
|
||||
|
||||
console.log("⚒ Creating release done!")
|
||||
console.log("⚒ Creating release done!")
|
||||
|
||||
return response.data
|
||||
return response.data
|
||||
}
|
||||
|
||||
module.exports = createGithubRelease
|
@ -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(`ReleaseID: ${release.id}`)
|
||||
@ -19,5 +19,3 @@ async function uploadAssets(octokit, repo, release, assets) {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
module.exports = uploadAssets
|
||||
|
Loading…
x
Reference in New Issue
Block a user