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
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
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": "",
|
"supportUrl": "",
|
||||||
"iconUrl": "./assets/icon.png",
|
"iconUrl": "./assets/icon.png",
|
||||||
"includes": [
|
"includes": [
|
||||||
"https://*.ingress.com/intel*"
|
"https://*.josunlp.de/*",
|
||||||
],
|
"https://josunlp.de/*"
|
||||||
"excludes": [
|
|
||||||
"https://*.ingress.com/mission/*"
|
|
||||||
],
|
],
|
||||||
|
"excludes": [],
|
||||||
"requires": [],
|
"requires": [],
|
||||||
"recources": [],
|
"resources": [],
|
||||||
"connecters": [],
|
"connecters": [],
|
||||||
"matches": [
|
"matches": [
|
||||||
"https://*.ingress.com/intel*"
|
"https://*.josunlp.de/*",
|
||||||
|
"https://josunlp.de/*"
|
||||||
],
|
],
|
||||||
|
"matchAllFrames": false,
|
||||||
"runAt": "document-start",
|
"runAt": "document-start",
|
||||||
"grants": [
|
"grants": [
|
||||||
"GM_setValue",
|
"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",
|
"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.",
|
"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",
|
"main": "index.ts",
|
||||||
|
"module": "node",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack && npm run build-userScriptHeader",
|
"build": "vite build && npm run build-userScriptHeader",
|
||||||
"build-tooling": "tsc ./tools/userScriptHeader.ts --target esnext --module esnext --lib ESNext",
|
"build-tooling": "tsc ./tools/userScriptHeader.ts --resolveJsonModule --esModuleInterop",
|
||||||
"build-userScriptHeader": "npm run build-tooling && node ./tools/userScriptHeader.js"
|
"build-userScriptHeader": "npm run build-tooling && node ./tools/userScriptHeader.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -29,6 +30,9 @@
|
||||||
"ts-loader": "^9.3.1",
|
"ts-loader": "^9.3.1",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
|
"undici-types": "^6.18.2",
|
||||||
|
"vite": "^5.2.12",
|
||||||
|
"vite-tsconfig-paths": "^4.3.2",
|
||||||
"webpack": "^5.74.0",
|
"webpack": "^5.74.0",
|
||||||
"webpack-cli": "^4.10.0"
|
"webpack-cli": "^4.10.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const fs = require("fs");
|
import * as fs from "fs";
|
||||||
const pkg = require("../package.json");
|
import pkg from "../package.json";
|
||||||
const config = require("../header.config.json");
|
import config from "../header.config.json";
|
||||||
|
|
||||||
const targetFile = "./dist/" + pkg.name + ".user.js";
|
const targetFile = "./dist/" + pkg.name + ".user.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,11 +9,11 @@ const targetFile = "./dist/" + pkg.name + ".user.js";
|
||||||
* @param header
|
* @param header
|
||||||
*/
|
*/
|
||||||
function appendHeader(header: string) {
|
function appendHeader(header: string) {
|
||||||
fs.readFile(targetFile, "utf8", (err: any, data: string) => {
|
fs.readFile(targetFile, "utf8", (err: NodeJS.ErrnoException | null, data: string) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
fs.writeFile(targetFile, header + data, (err: any) => {
|
fs.writeFile(targetFile, header + data, (err: NodeJS.ErrnoException | null) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +24,7 @@ function appendHeader(header: string) {
|
||||||
/**
|
/**
|
||||||
* Builds base64 url from file
|
* Builds base64 url from file
|
||||||
* @param filePath
|
* @param filePath
|
||||||
* @returns
|
* @returns base64 url
|
||||||
*/
|
*/
|
||||||
async function buildBase64UrlFromFile(filePath: string): Promise<string> {
|
async function buildBase64UrlFromFile(filePath: string): Promise<string> {
|
||||||
const file = await fs.promises.readFile(filePath);
|
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 type
|
||||||
* @param array
|
* @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 = "";
|
let result: string = "";
|
||||||
debugger;
|
|
||||||
if (array) {
|
if (array) {
|
||||||
array.forEach((item: string) => {
|
array.forEach((item: string) => {
|
||||||
result += `// ${type} ${item}`;
|
result += `// ${type} ${item}\n`;
|
||||||
if (array.length > 1) {
|
|
||||||
result += "\n";
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -53,7 +50,7 @@ function generateMultibleEntrys(type: string, array: string[]): string {
|
||||||
/**
|
/**
|
||||||
* Removes empty lines from string
|
* Removes empty lines from string
|
||||||
* @param string
|
* @param string
|
||||||
* @returns empty lines from string
|
* @returns string without empty lines
|
||||||
*/
|
*/
|
||||||
function removeEmptyLinesFromString(string: string): string {
|
function removeEmptyLinesFromString(string: string): string {
|
||||||
return string.replace(/\n\s*\n/g, "\n");
|
return string.replace(/\n\s*\n/g, "\n");
|
||||||
|
@ -63,18 +60,16 @@ function removeEmptyLinesFromString(string: string): string {
|
||||||
* Generates user script header
|
* Generates user script header
|
||||||
*/
|
*/
|
||||||
async function generateUserScriptHeader() {
|
async function generateUserScriptHeader() {
|
||||||
const excludes = generateMultibleEntrys("@exclude", config.excludes);
|
const excludes = generateMultipleEntries("@exclude", config.excludes);
|
||||||
const requires = generateMultibleEntrys("@require", config.requires);
|
const requires = generateMultipleEntries("@require", config.requires);
|
||||||
const resources = generateMultibleEntrys("@resource", config.resources);
|
const resources = generateMultipleEntries("@resource", config.resources);
|
||||||
const connecters = generateMultibleEntrys("@connect", config.connecters);
|
const connecters = generateMultipleEntries("@connect", config.connecters);
|
||||||
const grants = generateMultibleEntrys("@grant", config.grants);
|
const grants = generateMultipleEntries("@grant", config.grants);
|
||||||
const matches = generateMultibleEntrys("@match", config.matches);
|
const matches = generateMultipleEntries("@match", config.matches);
|
||||||
const includes = generateMultibleEntrys("@match", config.includes);
|
const includes = generateMultipleEntries("@match", config.includes);
|
||||||
const antifeatures = generateMultibleEntrys(
|
const antifeatures = generateMultipleEntries("@antifeature", config.antifeatures);
|
||||||
"@antifeature",
|
|
||||||
config.antifeatures
|
|
||||||
);
|
|
||||||
const base64url = await buildBase64UrlFromFile(config.iconUrl);
|
const base64url = await buildBase64UrlFromFile(config.iconUrl);
|
||||||
|
|
||||||
let noframes = "";
|
let noframes = "";
|
||||||
let matchAllFrames = "";
|
let matchAllFrames = "";
|
||||||
let updateUrl = "";
|
let updateUrl = "";
|
||||||
|
@ -82,24 +77,19 @@ async function generateUserScriptHeader() {
|
||||||
let supportUrl = "";
|
let supportUrl = "";
|
||||||
|
|
||||||
if (config.noframes) {
|
if (config.noframes) {
|
||||||
noframes = `// @noframes
|
noframes = `// @noframes\n`;
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
if (config.matchAllFrames) {
|
if (config.matchAllFrames) {
|
||||||
matchAllFrames = `// @matchAllFrames
|
matchAllFrames = `// @matchAllFrames\n`;
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
if (config.updateUrl !== "") {
|
if (config.updateUrl !== "") {
|
||||||
updateUrl = `// @updateURL ${config.updateUrl}
|
updateUrl = `// @updateURL ${config.updateUrl}\n`;
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
if (config.downloadUrl !== "") {
|
if (config.downloadUrl !== "") {
|
||||||
downloadUrl = `// @downloadURL ${config.downloadUrl}
|
downloadUrl = `// @downloadURL ${config.downloadUrl}\n`;
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
if (config.supportUrl !== "") {
|
if (config.supportUrl !== "") {
|
||||||
supportUrl = `// @supportURL ${config.supportUrl}
|
supportUrl = `// @supportURL ${config.supportUrl}\n`;
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let header = `// ==UserScript==
|
let header = `// ==UserScript==
|
||||||
|
@ -125,6 +115,7 @@ ${noframes}
|
||||||
${matchAllFrames}
|
${matchAllFrames}
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
`;
|
`;
|
||||||
|
|
||||||
header = removeEmptyLinesFromString(header);
|
header = removeEmptyLinesFromString(header);
|
||||||
header += "\n";
|
header += "\n";
|
||||||
appendHeader(header);
|
appendHeader(header);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "./dist/",
|
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"target": "ES6",
|
"target": "ES6",
|
||||||
|
@ -9,5 +8,9 @@
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"allowSyntheticDefaultImports": 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