mirror of
https://github.com/JosunLP/UserScriptProjectTemplate.git
synced 2025-06-21 10:11:07 +00:00
⬆️ Upgrading Project
Switching from Webpack to vite, upgrading the version of the logo file and updating dependencies
This commit is contained in:
parent
d63a0cf44b
commit
8089771d41
10 changed files with 1189 additions and 312 deletions
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2022 Jonas Pfalzgraf
|
||||
Copyright (c) 2024 Jonas Pfalzgraf
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
Binary file not shown.
BIN
assets/icon.png
BIN
assets/icon.png
Binary file not shown.
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 4.7 KiB |
|
@ -4,17 +4,18 @@
|
|||
"supportUrl": "",
|
||||
"iconUrl": "./assets/icon.png",
|
||||
"includes": [
|
||||
"https://*.ingress.com/intel*"
|
||||
],
|
||||
"excludes": [
|
||||
"https://*.ingress.com/mission/*"
|
||||
"https://*.josunlp.de/*",
|
||||
"https://josunlp.de/*"
|
||||
],
|
||||
"excludes": [],
|
||||
"requires": [],
|
||||
"recources": [],
|
||||
"resources": [],
|
||||
"connecters": [],
|
||||
"matches": [
|
||||
"https://*.ingress.com/intel*"
|
||||
"https://*.josunlp.de/*",
|
||||
"https://josunlp.de/*"
|
||||
],
|
||||
"matchAllFrames": false,
|
||||
"runAt": "document-start",
|
||||
"grants": [
|
||||
"GM_setValue",
|
||||
|
|
1363
package-lock.json
generated
1363
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -3,9 +3,10 @@
|
|||
"version": "0.0.1",
|
||||
"description": "A user script project template to create large and structured TypeScript projects for Tampermonkey or Greasemonkey. It is intended to form a scalable base and is primarily aimed at the Ingress community.",
|
||||
"main": "index.ts",
|
||||
"module": "node",
|
||||
"scripts": {
|
||||
"build": "webpack && npm run build-userScriptHeader",
|
||||
"build-tooling": "tsc ./tools/userScriptHeader.ts --target esnext --module esnext --lib ESNext",
|
||||
"build": "vite build && npm run build-userScriptHeader",
|
||||
"build-tooling": "tsc ./tools/userScriptHeader.ts --resolveJsonModule --esModuleInterop",
|
||||
"build-userScriptHeader": "npm run build-tooling && node ./tools/userScriptHeader.js"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -29,6 +30,9 @@
|
|||
"ts-loader": "^9.3.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.7.4",
|
||||
"undici-types": "^6.18.2",
|
||||
"vite": "^5.2.12",
|
||||
"vite-tsconfig-paths": "^4.3.2",
|
||||
"webpack": "^5.74.0",
|
||||
"webpack-cli": "^4.10.0"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const fs = require("fs");
|
||||
const pkg = require("../package.json");
|
||||
const config = require("../header.config.json");
|
||||
import * as fs from "fs";
|
||||
import pkg from "../package.json";
|
||||
import config from "../header.config.json";
|
||||
|
||||
const targetFile = "./dist/" + pkg.name + ".user.js";
|
||||
|
||||
/**
|
||||
|
@ -8,11 +9,11 @@ const targetFile = "./dist/" + pkg.name + ".user.js";
|
|||
* @param header
|
||||
*/
|
||||
function appendHeader(header: string) {
|
||||
fs.readFile(targetFile, "utf8", (err: any, data: string) => {
|
||||
fs.readFile(targetFile, "utf8", (err: NodeJS.ErrnoException | null, data: string) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
fs.writeFile(targetFile, header + data, (err: any) => {
|
||||
fs.writeFile(targetFile, header + data, (err: NodeJS.ErrnoException | null) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
@ -23,7 +24,7 @@ function appendHeader(header: string) {
|
|||
/**
|
||||
* Builds base64 url from file
|
||||
* @param filePath
|
||||
* @returns
|
||||
* @returns base64 url
|
||||
*/
|
||||
async function buildBase64UrlFromFile(filePath: string): Promise<string> {
|
||||
const file = await fs.promises.readFile(filePath);
|
||||
|
@ -31,20 +32,16 @@ async function buildBase64UrlFromFile(filePath: string): Promise<string> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Generates multible entrys
|
||||
* Generates multiple entries
|
||||
* @param type
|
||||
* @param array
|
||||
* @returns multible entrys
|
||||
* @returns multiple entries
|
||||
*/
|
||||
function generateMultibleEntrys(type: string, array: string[]): string {
|
||||
function generateMultipleEntries(type: string, array: string[]): string {
|
||||
let result: string = "";
|
||||
debugger;
|
||||
if (array) {
|
||||
array.forEach((item: string) => {
|
||||
result += `// ${type} ${item}`;
|
||||
if (array.length > 1) {
|
||||
result += "\n";
|
||||
}
|
||||
result += `// ${type} ${item}\n`;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
|
@ -53,7 +50,7 @@ function generateMultibleEntrys(type: string, array: string[]): string {
|
|||
/**
|
||||
* Removes empty lines from string
|
||||
* @param string
|
||||
* @returns empty lines from string
|
||||
* @returns string without empty lines
|
||||
*/
|
||||
function removeEmptyLinesFromString(string: string): string {
|
||||
return string.replace(/\n\s*\n/g, "\n");
|
||||
|
@ -63,18 +60,16 @@ function removeEmptyLinesFromString(string: string): string {
|
|||
* Generates user script header
|
||||
*/
|
||||
async function generateUserScriptHeader() {
|
||||
const excludes = generateMultibleEntrys("@exclude", config.excludes);
|
||||
const requires = generateMultibleEntrys("@require", config.requires);
|
||||
const resources = generateMultibleEntrys("@resource", config.resources);
|
||||
const connecters = generateMultibleEntrys("@connect", config.connecters);
|
||||
const grants = generateMultibleEntrys("@grant", config.grants);
|
||||
const matches = generateMultibleEntrys("@match", config.matches);
|
||||
const includes = generateMultibleEntrys("@match", config.includes);
|
||||
const antifeatures = generateMultibleEntrys(
|
||||
"@antifeature",
|
||||
config.antifeatures
|
||||
);
|
||||
const excludes = generateMultipleEntries("@exclude", config.excludes);
|
||||
const requires = generateMultipleEntries("@require", config.requires);
|
||||
const resources = generateMultipleEntries("@resource", config.resources);
|
||||
const connecters = generateMultipleEntries("@connect", config.connecters);
|
||||
const grants = generateMultipleEntries("@grant", config.grants);
|
||||
const matches = generateMultipleEntries("@match", config.matches);
|
||||
const includes = generateMultipleEntries("@match", config.includes);
|
||||
const antifeatures = generateMultipleEntries("@antifeature", config.antifeatures);
|
||||
const base64url = await buildBase64UrlFromFile(config.iconUrl);
|
||||
|
||||
let noframes = "";
|
||||
let matchAllFrames = "";
|
||||
let updateUrl = "";
|
||||
|
@ -82,24 +77,19 @@ async function generateUserScriptHeader() {
|
|||
let supportUrl = "";
|
||||
|
||||
if (config.noframes) {
|
||||
noframes = `// @noframes
|
||||
`;
|
||||
noframes = `// @noframes\n`;
|
||||
}
|
||||
if (config.matchAllFrames) {
|
||||
matchAllFrames = `// @matchAllFrames
|
||||
`;
|
||||
matchAllFrames = `// @matchAllFrames\n`;
|
||||
}
|
||||
if (config.updateUrl !== "") {
|
||||
updateUrl = `// @updateURL ${config.updateUrl}
|
||||
`;
|
||||
updateUrl = `// @updateURL ${config.updateUrl}\n`;
|
||||
}
|
||||
if (config.downloadUrl !== "") {
|
||||
downloadUrl = `// @downloadURL ${config.downloadUrl}
|
||||
`;
|
||||
downloadUrl = `// @downloadURL ${config.downloadUrl}\n`;
|
||||
}
|
||||
if (config.supportUrl !== "") {
|
||||
supportUrl = `// @supportURL ${config.supportUrl}
|
||||
`;
|
||||
supportUrl = `// @supportURL ${config.supportUrl}\n`;
|
||||
}
|
||||
|
||||
let header = `// ==UserScript==
|
||||
|
@ -125,6 +115,7 @@ ${noframes}
|
|||
${matchAllFrames}
|
||||
// ==/UserScript==
|
||||
`;
|
||||
|
||||
header = removeEmptyLinesFromString(header);
|
||||
header += "\n";
|
||||
appendHeader(header);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist/",
|
||||
"noImplicitAny": true,
|
||||
"module": "ESNext",
|
||||
"target": "ES6",
|
||||
|
@ -9,5 +8,9 @@
|
|||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"paths": {
|
||||
"undici-types": ["./node_modules/undici/types/index.d.ts"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
21
vite.config.ts
Normal file
21
vite.config.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { defineConfig } from "vite";
|
||||
import { resolve } from "path";
|
||||
import tsconfigPaths from "vite-tsconfig-paths";
|
||||
import pkgjsn from "./package.json";
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: resolve(__dirname, "src/index.ts"),
|
||||
output: {
|
||||
entryFileNames: `${pkgjsn.name}.user.js`,
|
||||
dir: resolve(__dirname, "dist"),
|
||||
},
|
||||
},
|
||||
sourcemap: "inline", // Equivalent to 'inline-source-map'
|
||||
},
|
||||
plugins: [tsconfigPaths()],
|
||||
resolve: {
|
||||
extensions: [".tsx", ".ts", ".js"],
|
||||
},
|
||||
});
|
|
@ -1,24 +0,0 @@
|
|||
const path = require('path');
|
||||
const pkgjsn = require('./package.json');
|
||||
|
||||
module.exports = {
|
||||
entry: './src/index.ts',
|
||||
devtool: 'inline-source-map',
|
||||
mode: 'production',
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
use: 'ts-loader',
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
],
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.tsx', '.ts', '.js'],
|
||||
},
|
||||
output: {
|
||||
filename: pkgjsn.name + '.user.js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
},
|
||||
};
|
Loading…
Add table
Reference in a new issue