mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-05 19:24:39 +00:00
format: run prettify
This commit is contained in:
+2
-2
@@ -7,10 +7,10 @@ export const base64Loader = {
|
||||
const [filePath, query] = id.split("?");
|
||||
if (query !== "base64") return null;
|
||||
|
||||
const data = fs.readFileSync(filePath, { encoding: 'base64' });
|
||||
const data = fs.readFileSync(filePath, { encoding: "base64" });
|
||||
const mimeType = mime.lookup(filePath);
|
||||
const dataURL = `data:${mimeType};base64,${data}`;
|
||||
|
||||
return `export default '${dataURL}';`;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
+10
-10
@@ -1,25 +1,25 @@
|
||||
// ref: https://stackoverflow.com/a/76920975
|
||||
import type { Plugin } from 'vite';
|
||||
import type { Plugin } from "vite";
|
||||
|
||||
export default function ClosePlugin(): Plugin {
|
||||
return {
|
||||
name: 'ClosePlugin', // required, will show up in warnings and errors
|
||||
name: "ClosePlugin", // required, will show up in warnings and errors
|
||||
|
||||
// use this to catch errors when building
|
||||
buildEnd(error) {
|
||||
if(error) {
|
||||
console.error('Error bundling')
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
if (error) {
|
||||
console.error("Error bundling");
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Build ended')
|
||||
console.log("Build ended");
|
||||
}
|
||||
},
|
||||
|
||||
// use this to catch the end of a build without errors
|
||||
closeBundle() {
|
||||
console.log('Bundle closed')
|
||||
process.exit(0)
|
||||
console.log("Bundle closed");
|
||||
process.exit(0);
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Browser, BuildTarget, Manifest } from './types'
|
||||
import type { AnyCase } from './utils'
|
||||
import type { Browser, BuildTarget, Manifest } from "./types";
|
||||
import type { AnyCase } from "./utils";
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -15,7 +15,7 @@ export function createManifest(
|
||||
return {
|
||||
manifest,
|
||||
browser,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,5 +29,5 @@ export function createManifest(
|
||||
* @return {*} {@link Manifest}
|
||||
*/
|
||||
export function createManifestBase(manifest: Manifest): Manifest {
|
||||
return manifest
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
+19
-19
@@ -1,26 +1,26 @@
|
||||
// vite-plugin-inline-worker-dev.ts
|
||||
import { Plugin } from 'vite'
|
||||
import fs from 'fs/promises'
|
||||
import { build, transform } from 'esbuild'
|
||||
import { Plugin } from "vite";
|
||||
import fs from "fs/promises";
|
||||
import { build, transform } from "esbuild";
|
||||
|
||||
export default function InlineWorkerDevPlugin(): Plugin {
|
||||
return {
|
||||
name: 'vite:inline-worker-dev',
|
||||
name: "vite:inline-worker-dev",
|
||||
async load(id) {
|
||||
if (id.includes('?inlineWorker')) {
|
||||
const [cleanPath] = id.split('?')
|
||||
console.log('cleanPath', cleanPath)
|
||||
const code = await fs.readFile(cleanPath, 'utf-8')
|
||||
if (id.includes("?inlineWorker")) {
|
||||
const [cleanPath] = id.split("?");
|
||||
console.log("cleanPath", cleanPath);
|
||||
const code = await fs.readFile(cleanPath, "utf-8");
|
||||
const result = await build({
|
||||
entryPoints: [cleanPath],
|
||||
bundle: true,
|
||||
write: false,
|
||||
platform: 'browser',
|
||||
format: 'iife',
|
||||
target: 'esnext',
|
||||
})
|
||||
|
||||
const workerCode = result.outputFiles[0].text
|
||||
platform: "browser",
|
||||
format: "iife",
|
||||
target: "esnext",
|
||||
});
|
||||
|
||||
const workerCode = result.outputFiles[0].text;
|
||||
|
||||
const workerBlobCode = `
|
||||
const code = ${JSON.stringify(workerCode)};
|
||||
@@ -28,10 +28,10 @@ export default function InlineWorkerDevPlugin(): Plugin {
|
||||
const blob = new Blob([code], { type: 'application/javascript' });
|
||||
return new Worker(URL.createObjectURL(blob), { type: 'module' });
|
||||
}
|
||||
`
|
||||
return workerBlobCode
|
||||
`;
|
||||
return workerBlobCode;
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
+72
-49
@@ -1,49 +1,63 @@
|
||||
const glob = require('glob');
|
||||
const semver = require('semver');
|
||||
const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
const glob = require("glob");
|
||||
const semver = require("semver");
|
||||
const { execSync } = require("child_process");
|
||||
const path = require("path");
|
||||
|
||||
function getLatestVersion(files) {
|
||||
console.log('Files passed to getLatestVersion:', files);
|
||||
console.log("Files passed to getLatestVersion:", files);
|
||||
|
||||
const versions = files.map(file => {
|
||||
const match = file.match(/@([\d\.]+)-/);
|
||||
console.log('Matching file:', file, 'Version found:', match ? match[1] : 'None');
|
||||
const versions = files
|
||||
.map((file) => {
|
||||
const match = file.match(/@([\d\.]+)-/);
|
||||
console.log(
|
||||
"Matching file:",
|
||||
file,
|
||||
"Version found:",
|
||||
match ? match[1] : "None",
|
||||
);
|
||||
|
||||
if (!match) return null;
|
||||
if (!match) return null;
|
||||
|
||||
const fullVersion = match[1]; // Original version (e.g., 3.4.5.1)
|
||||
const semverVersion = fullVersion.split('.').slice(0, 3).join('.'); // Trim to 3.4.5
|
||||
const fullVersion = match[1]; // Original version (e.g., 3.4.5.1)
|
||||
const semverVersion = fullVersion.split(".").slice(0, 3).join("."); // Trim to 3.4.5
|
||||
|
||||
return { fullVersion, semverVersion };
|
||||
}).filter(Boolean);
|
||||
return { fullVersion, semverVersion };
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
console.log('Extracted versions:', versions.map(v => v.semverVersion));
|
||||
console.log(
|
||||
"Extracted versions:",
|
||||
versions.map((v) => v.semverVersion),
|
||||
);
|
||||
|
||||
// Find latest version using the trimmed semver format
|
||||
const latestSemver = semver.maxSatisfying(versions.map(v => v.semverVersion), '*');
|
||||
console.log('Latest SemVer-compatible version:', latestSemver);
|
||||
const latestSemver = semver.maxSatisfying(
|
||||
versions.map((v) => v.semverVersion),
|
||||
"*",
|
||||
);
|
||||
console.log("Latest SemVer-compatible version:", latestSemver);
|
||||
|
||||
// Get the full version that matches the latest SemVer version
|
||||
const latestVersion = versions.find(v => v.semverVersion === latestSemver)?.fullVersion || null;
|
||||
const latestVersion =
|
||||
versions.find((v) => v.semverVersion === latestSemver)?.fullVersion || null;
|
||||
|
||||
console.log('Final selected latest version:', latestVersion);
|
||||
console.log("Final selected latest version:", latestVersion);
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
function getLatestFiles(browser) {
|
||||
const pattern = `dist/betterseqtaplus@*-*${browser}.zip`;
|
||||
console.log('Glob pattern:', pattern);
|
||||
|
||||
console.log("Glob pattern:", pattern);
|
||||
|
||||
const files = glob.sync(pattern);
|
||||
console.log('Files found for browser', browser, ':', files);
|
||||
|
||||
console.log("Files found for browser", browser, ":", files);
|
||||
|
||||
const latestVersion = getLatestVersion(files);
|
||||
|
||||
// Find the exact file by matching the original full version
|
||||
const latestFile = files.find(file => file.includes(`@${latestVersion}-`));
|
||||
const latestFile = files.find((file) => file.includes(`@${latestVersion}-`));
|
||||
|
||||
console.log('Latest file for browser', browser, ':', latestFile);
|
||||
console.log("Latest file for browser", browser, ":", latestFile);
|
||||
return latestFile;
|
||||
}
|
||||
|
||||
@@ -51,44 +65,53 @@ function zipSources() {
|
||||
const zipFileName = `dist/betterseqtaplus@latest-sources.zip`;
|
||||
|
||||
const excludePatterns = [
|
||||
'node_modules',
|
||||
'dist',
|
||||
'.env*',
|
||||
'.git',
|
||||
'.github',
|
||||
'.vscode',
|
||||
'LICENSE',
|
||||
'package.json'
|
||||
].map(pattern => `-x!${pattern}`).join(' ');
|
||||
"node_modules",
|
||||
"dist",
|
||||
".env*",
|
||||
".git",
|
||||
".github",
|
||||
".vscode",
|
||||
"LICENSE",
|
||||
"package.json",
|
||||
]
|
||||
.map((pattern) => `-x!${pattern}`)
|
||||
.join(" ");
|
||||
|
||||
const zipCommand = `7z a ${zipFileName} . ${excludePatterns}`;
|
||||
|
||||
console.log('Zipping project sources with command:', zipCommand);
|
||||
execSync(zipCommand, { stdio: 'inherit' });
|
||||
console.log("Zipping project sources with command:", zipCommand);
|
||||
execSync(zipCommand, { stdio: "inherit" });
|
||||
|
||||
return zipFileName;
|
||||
}
|
||||
|
||||
function runPublishCommand(browsers) {
|
||||
const chromeZip = browsers.includes('chrome') ? getLatestFiles('chrome') : null;
|
||||
const firefoxZip = browsers.includes('firefox') ? getLatestFiles('firefox') : null;
|
||||
const firefoxSourcesZip = browsers.includes('firefox') ? zipSources() : null;
|
||||
const chromeZip = browsers.includes("chrome")
|
||||
? getLatestFiles("chrome")
|
||||
: null;
|
||||
const firefoxZip = browsers.includes("firefox")
|
||||
? getLatestFiles("firefox")
|
||||
: null;
|
||||
const firefoxSourcesZip = browsers.includes("firefox") ? zipSources() : null;
|
||||
|
||||
console.log('Chrome zip:', chromeZip);
|
||||
console.log('Firefox zip:', firefoxZip);
|
||||
console.log('Firefox sources zip:', firefoxSourcesZip);
|
||||
console.log("Chrome zip:", chromeZip);
|
||||
console.log("Firefox zip:", firefoxZip);
|
||||
console.log("Firefox sources zip:", firefoxSourcesZip);
|
||||
|
||||
if (browsers.length === 0) {
|
||||
console.log('No browsers specified. Exiting.');
|
||||
console.log("No browsers specified. Exiting.");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if ((browsers.includes('chrome') && !chromeZip) || (browsers.includes('firefox') && (!firefoxZip || !firefoxSourcesZip))) {
|
||||
console.error('Could not find required zip files for specified browsers.');
|
||||
if (
|
||||
(browsers.includes("chrome") && !chromeZip) ||
|
||||
(browsers.includes("firefox") && (!firefoxZip || !firefoxSourcesZip))
|
||||
) {
|
||||
console.error("Could not find required zip files for specified browsers.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let command = 'publish-extension';
|
||||
let command = "publish-extension";
|
||||
if (chromeZip) {
|
||||
command += ` --chrome-zip ${chromeZip}`;
|
||||
}
|
||||
@@ -96,13 +119,13 @@ function runPublishCommand(browsers) {
|
||||
command += ` --firefox-zip ${firefoxZip} --firefox-sources-zip ${firefoxSourcesZip}`;
|
||||
}
|
||||
|
||||
console.log('Running command:', command);
|
||||
execSync(command, { stdio: 'inherit' });
|
||||
console.log("Running command:", command);
|
||||
execSync(command, { stdio: "inherit" });
|
||||
}
|
||||
|
||||
// Parse command-line arguments
|
||||
const args = process.argv.slice(2);
|
||||
const browserIndex = args.indexOf('--b');
|
||||
const browserIndex = args.indexOf("--b");
|
||||
const browsers = browserIndex !== -1 ? args.slice(browserIndex + 1) : [];
|
||||
|
||||
runPublishCommand(browsers);
|
||||
runPublishCommand(browsers);
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import fs from 'fs';
|
||||
import fs from "fs";
|
||||
|
||||
export default function touchGlobalCSSPlugin() {
|
||||
return {
|
||||
name: 'touch-global-css',
|
||||
name: "touch-global-css",
|
||||
handleHotUpdate({ modules }) {
|
||||
// log all of the staticImportedUrls
|
||||
const importers = modules[0]._clientModule.importers
|
||||
const importers = modules[0]._clientModule.importers;
|
||||
importers.forEach((importer) => {
|
||||
if (importer.file.includes('.css')) {
|
||||
console.log("touching", importer.file)
|
||||
fs.utimesSync(importer.file, new Date(), new Date())
|
||||
if (importer.file.includes(".css")) {
|
||||
console.log("touching", importer.file);
|
||||
fs.utimesSync(importer.file, new Date(), new Date());
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
+67
-67
@@ -1,104 +1,104 @@
|
||||
import type { ManifestV3Export } from '@crxjs/vite-plugin'
|
||||
import { type AnyCase, createEnum } from './utils'
|
||||
import type { ManifestV3Export } from "@crxjs/vite-plugin";
|
||||
import { type AnyCase, createEnum } from "./utils";
|
||||
|
||||
export const FrameworkEnum = {
|
||||
React: 'React',
|
||||
Vanilla: 'Vanilla',
|
||||
Preact: 'Preact',
|
||||
Lit: 'Lit',
|
||||
Svelte: 'Svelte',
|
||||
Vue: 'Vue',
|
||||
} as const
|
||||
React: "React",
|
||||
Vanilla: "Vanilla",
|
||||
Preact: "Preact",
|
||||
Lit: "Lit",
|
||||
Svelte: "Svelte",
|
||||
Vue: "Vue",
|
||||
} as const;
|
||||
|
||||
export const BrowserEnum = {
|
||||
Chrome: 'Chrome',
|
||||
Brave: 'Brave',
|
||||
Opera: 'Opera',
|
||||
Edge: 'Edge',
|
||||
Firefox: 'Firefox',
|
||||
Safari: 'Safari',
|
||||
} as const
|
||||
Chrome: "Chrome",
|
||||
Brave: "Brave",
|
||||
Opera: "Opera",
|
||||
Edge: "Edge",
|
||||
Firefox: "Firefox",
|
||||
Safari: "Safari",
|
||||
} as const;
|
||||
|
||||
const LanguageEnum = {
|
||||
TypeScript: 'TypeScript',
|
||||
JavaScript: 'JavaScript',
|
||||
} as const
|
||||
TypeScript: "TypeScript",
|
||||
JavaScript: "JavaScript",
|
||||
} as const;
|
||||
|
||||
export const StyleEnum = {
|
||||
Tailwind: 'Tailwind',
|
||||
} as const
|
||||
Tailwind: "Tailwind",
|
||||
} as const;
|
||||
|
||||
export const PackageManagerEnum = {
|
||||
Bun: 'Bun',
|
||||
PnPm: 'PnPm',
|
||||
Npm: 'Npm',
|
||||
Yarn: 'Yarn',
|
||||
} as const
|
||||
Bun: "Bun",
|
||||
PnPm: "PnPm",
|
||||
Npm: "Npm",
|
||||
Yarn: "Yarn",
|
||||
} as const;
|
||||
|
||||
// see: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/firefox-webext-browser/index.d.ts
|
||||
export type BrowserSpecificSettings = {
|
||||
browser_specific_settings?: {
|
||||
gecko?: {
|
||||
id: string
|
||||
strict_min_version?: string
|
||||
strict_max_version?: string
|
||||
}
|
||||
}
|
||||
}
|
||||
id: string;
|
||||
strict_min_version?: string;
|
||||
strict_max_version?: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export type Manifest = ManifestV3Export
|
||||
export type ManifestIcons = chrome.runtime.ManifestIcons
|
||||
export type ManifestBackground = chrome.runtime.ManifestV3['background']
|
||||
export type Manifest = ManifestV3Export;
|
||||
export type ManifestIcons = chrome.runtime.ManifestIcons;
|
||||
export type ManifestBackground = chrome.runtime.ManifestV3["background"];
|
||||
export type ManifestContentScripts =
|
||||
chrome.runtime.ManifestV3['content_scripts']
|
||||
chrome.runtime.ManifestV3["content_scripts"];
|
||||
export type ManifestWebAccessibleResources =
|
||||
chrome.runtime.ManifestV3['web_accessible_resources']
|
||||
export type ManifestCommands = chrome.runtime.ManifestV3['commands']
|
||||
export type ManifestAction = chrome.runtime.ManifestV3['action']
|
||||
export type ManifestPermissions = chrome.runtime.ManifestV3['permissions']
|
||||
export type ManifestOptionsUI = chrome.runtime.ManifestV3['options_ui']
|
||||
chrome.runtime.ManifestV3["web_accessible_resources"];
|
||||
export type ManifestCommands = chrome.runtime.ManifestV3["commands"];
|
||||
export type ManifestAction = chrome.runtime.ManifestV3["action"];
|
||||
export type ManifestPermissions = chrome.runtime.ManifestV3["permissions"];
|
||||
export type ManifestOptionsUI = chrome.runtime.ManifestV3["options_ui"];
|
||||
export type ManifestURLOverrides =
|
||||
chrome.runtime.ManifestV3['chrome_url_overrides']
|
||||
chrome.runtime.ManifestV3["chrome_url_overrides"];
|
||||
|
||||
export type BrowserName<T extends string> = Capitalize<T> | Lowercase<T>
|
||||
export type BrowserName<T extends string> = Capitalize<T> | Lowercase<T>;
|
||||
export type BrowserEnumType<T extends string> = {
|
||||
[browser in BrowserName<T>]: BrowserName<T>
|
||||
}
|
||||
[browser in BrowserName<T>]: BrowserName<T>;
|
||||
};
|
||||
|
||||
export type BuildMode = AnyCase<Browser>
|
||||
export type BuildMode = AnyCase<Browser>;
|
||||
export type BuildTarget = {
|
||||
manifest: Manifest
|
||||
browser: AnyCase<Browser>
|
||||
}
|
||||
manifest: Manifest;
|
||||
browser: AnyCase<Browser>;
|
||||
};
|
||||
export type BuildConfig = {
|
||||
command?: 'build' | 'serve'
|
||||
mode?: AnyCase<Browser> | string | undefined
|
||||
}
|
||||
command?: "build" | "serve";
|
||||
mode?: AnyCase<Browser> | string | undefined;
|
||||
};
|
||||
|
||||
export interface Repository {
|
||||
type: string
|
||||
url?: string
|
||||
bugs?: Bugs
|
||||
type: string;
|
||||
url?: string;
|
||||
bugs?: Bugs;
|
||||
}
|
||||
|
||||
export interface Bugs {
|
||||
url?: string
|
||||
email?: string
|
||||
url?: string;
|
||||
email?: string;
|
||||
}
|
||||
|
||||
export type Browser = (typeof BrowserEnum)[keyof typeof BrowserEnum]
|
||||
export const Browser: AnyCase<Browser> = createEnum(BrowserEnum)
|
||||
export type Browser = (typeof BrowserEnum)[keyof typeof BrowserEnum];
|
||||
export const Browser: AnyCase<Browser> = createEnum(BrowserEnum);
|
||||
|
||||
export type PackageManager =
|
||||
(typeof PackageManagerEnum)[keyof typeof PackageManagerEnum]
|
||||
(typeof PackageManagerEnum)[keyof typeof PackageManagerEnum];
|
||||
export const PackageManager: AnyCase<PackageManager> =
|
||||
createEnum(PackageManagerEnum)
|
||||
createEnum(PackageManagerEnum);
|
||||
|
||||
export type Framework = (typeof FrameworkEnum)[keyof typeof FrameworkEnum]
|
||||
export const Framework: AnyCase<Framework> = createEnum(FrameworkEnum)
|
||||
export type Framework = (typeof FrameworkEnum)[keyof typeof FrameworkEnum];
|
||||
export const Framework: AnyCase<Framework> = createEnum(FrameworkEnum);
|
||||
|
||||
export type Style = (typeof StyleEnum)[keyof typeof StyleEnum]
|
||||
export const Style: AnyCase<Style> = createEnum(StyleEnum)
|
||||
export type Style = (typeof StyleEnum)[keyof typeof StyleEnum];
|
||||
export const Style: AnyCase<Style> = createEnum(StyleEnum);
|
||||
|
||||
export type Language = (typeof LanguageEnum)[keyof typeof LanguageEnum]
|
||||
export const Language: AnyCase<Language> = createEnum(LanguageEnum)
|
||||
export type Language = (typeof LanguageEnum)[keyof typeof LanguageEnum];
|
||||
export const Language: AnyCase<Language> = createEnum(LanguageEnum);
|
||||
|
||||
+6
-6
@@ -1,21 +1,21 @@
|
||||
export type ObjectValues<T> = T[keyof T]
|
||||
export type ObjectValues<T> = T[keyof T];
|
||||
|
||||
export function createEnum<T extends Record<string, string>>(enumObj: T) {
|
||||
return Object.values(enumObj) as unknown as ObjectValues<T>
|
||||
return Object.values(enumObj) as unknown as ObjectValues<T>;
|
||||
}
|
||||
|
||||
export type AnyCase<T extends string> =
|
||||
| Uppercase<T>
|
||||
| Lowercase<T>
|
||||
| Capitalize<T>
|
||||
| Uncapitalize<T>
|
||||
| Uncapitalize<T>;
|
||||
|
||||
export type AnyCaseLanguage<T extends string, K extends string> =
|
||||
| Uppercase<T | K>
|
||||
| Lowercase<T | K>
|
||||
| Capitalize<T | K>
|
||||
| Uncapitalize<T | K>
|
||||
| Uncapitalize<T | K>;
|
||||
|
||||
export type OptionalKeys<T> = {
|
||||
[K in keyof T as undefined extends T[K] ? K : never]: T[K]
|
||||
}
|
||||
[K in keyof T as undefined extends T[K] ? K : never]: T[K];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user