Skip to content

Commit

Permalink
github action to build script
Browse files Browse the repository at this point in the history
  • Loading branch information
tejonaco committed Sep 3, 2024
1 parent 06e9c6c commit b1bee3c
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build, Release, and Update Tag
on:
push:
tags:
- "*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Build the project
run: npm run build
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: v${{ github.ref }}
draft: false
prerelease: false
- name: Upload Release Assets
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const fs = require('fs').promises;
const path = require('path');
const uploadAsset = async (file) => {
const fileName = path.basename(file);
const fileContent = await fs.readFile(file);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ steps.create_release.outputs.id }},
name: fileName,
data: fileContent
});
};
const uploadDir = async (dir) => {
const files = await fs.readdir(dir);
for (const file of files) {
const filePath = path.join(dir, file);
const stat = await fs.stat(filePath);
if (stat.isDirectory()) {
await uploadDir(filePath);
} else {
await uploadAsset(filePath);
}
}
};
await uploadDir('./dist');
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "fc-plus",
"version": "0.0.1",
"version": "1.0.0",
"type": "module",
"scripts": {
"build:watch": "vite build --watch",
"build:watch": "cross-env WATCH=true vite build --watch",
"build": "vite build",
"server": "http-server -c5 dist",
"dev": "npm-run-all --parallel build:watch server"
Expand All @@ -14,6 +14,7 @@
"@types/unidecode": "^0.1.3",
"@violentmonkey/types": "^0.1.9",
"autoprefixer": "^10.4.20",
"cross-env": "^7.0.3",
"http-server": "^14.1.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.41",
Expand Down
5 changes: 3 additions & 2 deletions src/userscript-header.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name FC Plus
// @namespce tejonaco
// @version 1.0.0
// @version {{version}}
// @description Extensión para forocoches.com
// @license MIT
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Roto2.svg/240px-Roto2.svg.png
Expand All @@ -12,5 +12,6 @@
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// @run-at document-idle
// @resource css style.css
// @resource css {{css}}
// @downloadURL https://github.com/tejonaco/fc-plus/releases/latest/download/index.user.js
// ==/UserScript==
14 changes: 12 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import preact from '@preact/preset-vite'
import { ConfigEnv, UserConfig, defineConfig } from "vite";
import fs from 'fs';
import {version} from "./package.json"

function prepareHeader() {
const fileContents = fs.readFileSync('src/userscript-header.js', 'utf-8')

const css = process.env.WATCH? 'style.css': `https://github.com/tejonaco/fc-plus/releases/download/${version}/style.css`

return fileContents.replace('{{version}}', version).replace('{{css}}', css)
}

export default defineConfig((mode: ConfigEnv): UserConfig => {
return {
Expand All @@ -10,7 +18,9 @@ export default defineConfig((mode: ConfigEnv): UserConfig => {
target: "esnext",
minify: false,
outDir: "dist",
watch: 'src',
watch: {
include: 'src'
},
lib: {
entry: 'src/index.tsx',
name: 'index',
Expand All @@ -19,7 +29,7 @@ export default defineConfig((mode: ConfigEnv): UserConfig => {
},
rollupOptions: {
output: {
banner: () => fs.readFileSync('src/userscript-header.js', 'utf-8')
banner: prepareHeader
},
}
},
Expand Down

0 comments on commit b1bee3c

Please sign in to comment.