diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..e2a2497 --- /dev/null +++ b/.github/workflows/tag.yml @@ -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'); \ No newline at end of file diff --git a/package.json b/package.json index f9432e9..0bd5cab 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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", diff --git a/src/userscript-header.js b/src/userscript-header.js index f635104..a716082 100644 --- a/src/userscript-header.js +++ b/src/userscript-header.js @@ -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 @@ -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== \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index eb746e4..4cd4c39 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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 { @@ -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', @@ -19,7 +29,7 @@ export default defineConfig((mode: ConfigEnv): UserConfig => { }, rollupOptions: { output: { - banner: () => fs.readFileSync('src/userscript-header.js', 'utf-8') + banner: prepareHeader }, } },