Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better discord plugin #357

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions build/metadata-bd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// const pkg = require('../package.json');
import pkg from '../package.json';

//
// Generate BetterDiscord metadata block with information from package.json
// https://github.com/BetterDiscord/BetterDiscord/wiki/Plugin-and-Theme-METAs
// @author victornpb
//

const production = !process.env.ROLLUP_WATCH;

function generateComment(manifest) {
const largestKey = Object.keys(manifest).reduce((a, b) => a.length > b.length ? a : b).length;
const generateLine = (key, value) => ` * @${key.padEnd(largestKey, ' ')} ${value}`;
const lines = Object.entries(manifest).map(([key, value]) => {
if (Array.isArray(value))
return value.map(subVal => generateLine(key, subVal)).join('\n');
return generateLine(key, value);
}).join('\n');
return [
'/**',
lines,
' */',
'',
].join('\n');
}

function publicKeys(obj) {
const keys = Object.keys(obj).filter(key => !key.startsWith('_'));
return Object.fromEntries(keys.map(key => [key, obj[key]]));
}

export default () => {
const metadata = {
name: pkg.nameFull,
description: pkg.description,
version: pkg.version,
author: pkg.author,
website: pkg.homepage,
// license: pkg.license,
...publicKeys(pkg.betterDiscord),
};

if (!production) {
delete metadata.source;
delete metadata.updateUrl;
metadata.version = new Date().toISOString();
// metadata.namespace = 'foobar';
}

return generateComment(metadata);
};
9 changes: 7 additions & 2 deletions build/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pkg from '../package.json';

//
// Generate metadata block with information from package.json
// Generate userscript metadata block with information from package.json
// https://sourceforge.net/p/greasemonkey/wiki/Metadata_Block/
// @author victornpb
//
Expand All @@ -25,6 +25,11 @@ function generateComment(manifest) {
].join('\n');
}

function publicKeys(obj) {
const keys = Object.keys(obj).filter(key => !key.startsWith('_'));
return Object.fromEntries(keys.map(key => [key, obj[key]]));
}

export default () => {
const metadata = {
name: pkg.nameFull,
Expand All @@ -35,7 +40,7 @@ export default () => {
supportURL: pkg.bugs.url,
match: pkg.userScript.match,
license: pkg.license,
...pkg.userScript,
...publicKeys(pkg.userScript),
};

if (!production) {
Expand Down
39 changes: 37 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"contributionURL": "https://www.buymeacoffee.com/vitim",
"grant": "none"
},
"betterDiscord": {
"source": "https://raw.githubusercontent.com/victornpb/deleteDiscordMessages/master/deleteDiscordMessages.user.js",
"updateUrl": "https://raw.githubusercontent.com/victornpb/deleteDiscordMessages/master/deleteDiscordMessages.user.js",
"donate": "https://www.buymeacoffee.com/vitim",
"_dist": "undiscord.plugin.js"
},
"version": "5.0.1",
"description": "Delete all messages in a Discord channel or DM (Bulk deletion)",
"license": "MIT",
Expand All @@ -28,9 +34,6 @@
"homepage": "https://github.com/victornpb/undiscord",
"author": "victornpb",
"main": "deleteDiscordMessages.user.js",
"module": "dist/foo-bar.esm.js",
"unpkg": "dist/foo-bar.js",
"globalVar": "FooBar",
"scripts": {
"start": "npm run watch",
"build": "rollup -c",
Expand Down Expand Up @@ -61,21 +64,23 @@
"@rollup/plugin-json": "^4.1.0",
"asciitable.js": "^1.0.3",
"eslint": "^8.13.0",
"http-serve": "^1.0.1",
"husky": "^7.0.4",
"lint-staged": "^12.4.0",
"np": "^7.6.1",
"postcss": "^8.4.12",
"rimraf": "^3.0.2",
"rollup": "^2.70.2",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-baked-env": "^0.1.0",
"rollup-plugin-banner2": "^1.2.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-inject-process-env": "^1.3.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-terser": "^7.0.2",
"tiny-dedent": "^1.0.2",
"http-serve": "^1.0.1"
"tiny-dedent": "^1.0.2"
},
"husky": {
"hooks": {
Expand Down
36 changes: 33 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import banner from 'rollup-plugin-banner2';
import bakedEnv from 'rollup-plugin-baked-env';

import json from '@rollup/plugin-json';
import packageJson from './package.json';
// import { string } from "rollup-plugin-string";
import { string } from "./build/strings-plugin";
import { string } from './build/strings-plugin';

import userScriptMetadataBlock from './build/metadata.js';
import betterDiscordMetadataBlock from './build/metadata-bd.js';

const production = !process.env.ROLLUP_WATCH;
const sourcemap = production ? true : 'inline';
const entry = 'src/index.js';

process.env.production = production;

// const assumptions = {
// constantSuper: true,
// enumerableModuleMeta: true,
Expand All @@ -30,7 +35,7 @@ const entry = 'src/index.js';

const config = [

// Modern Module (No babel preset)
// Generate a user script
{
input: entry,
output: [
Expand All @@ -45,10 +50,35 @@ const config = [
json(),
resolve(),
commonjs(),
bakedEnv(),
banner(userScriptMetadataBlock),
string({
// Required to be specified
include: ["**/*.html", '**/*.css'],
include: ['**/*.html', '**/*.css'],
})
]
},

// BetterDiscord Plugin
{
input: 'src/index-bd.js',
output: [
{
file: packageJson.betterDiscord._dist,
format: 'cjs',
sourcemap: false,
exports: 'default',
},
],
plugins: [
json(),
resolve(),
commonjs(),
bakedEnv(),
banner(betterDiscordMetadataBlock),
string({
// Required to be specified
include: ['**/*.html', '**/*.css'],
})
]
},
Expand Down
17 changes: 17 additions & 0 deletions src/index-bd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { initUI, destroy, toggleWindow } from './undiscord';

export default class Undiscord {
// Required function. Called when the plugin is activated (including after reloads)
start() {
initUI();
}

getSettingsPanel() {
toggleWindow(true);
}

// Required function. Called when the plugin is deactivated
stop() {
destroy();
}
}
Loading