Skip to content

Commit

Permalink
[Global] Switch to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
redstonekasi committed Sep 23, 2023
1 parent 61d2c0d commit c10d872
Show file tree
Hide file tree
Showing 25 changed files with 573 additions and 575 deletions.
7 changes: 2 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
Expand Down
3 changes: 1 addition & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"printWidth": 240,
"singleQuote": false,
"jsxSingleQuote": false,
"bracketSpacing": true,
"editorconfig": true
"bracketSpacing": true
}
186 changes: 92 additions & 94 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,114 +16,112 @@ const hash = execSync("git rev-parse --short HEAD").toString().trim() + (dev ? "

/** @type import("esbuild").BuildOptions */
const options = {
entryPoints: ["./src/index.ts"],
outfile: "./dist/ropeswing.js",
minify: !dev,
bundle: true,
format: "iife",
target: "esnext",
plugins: [
alias(aliases),
sassPlugin({
type: "style",
transform: postcssModules({
localsConvention: "camelCaseOnly",
}),
}),
{
name: "extensions",
setup: (build) => {
const filter = /@ext\/all/;
build.onResolve({ filter }, ({ path }) => ({ path, namespace: "extensions" }));
build.onLoad({ filter, namespace: "extensions" }, async () => {
const exts = await readdir("./src/ext");
entryPoints: ["./src/index.ts"],
outfile: "./dist/ropeswing.js",
minify: !dev,
bundle: true,
format: "iife",
target: "esnext",
plugins: [
alias(aliases),
sassPlugin({
type: "style",
transform: postcssModules({
localsConvention: "camelCaseOnly",
}),
}),
{
name: "extensions",
setup: (build) => {
const filter = /@ext\/all/;
build.onResolve({ filter }, ({ path }) => ({ path, namespace: "extensions" }));
build.onLoad({ filter, namespace: "extensions" }, async () => {
const exts = await readdir("./src/ext");

let i = 0;
const exp = [];
const imports = exts.map((e) => (exp.push(`e${i}`), `import e${i++} from "./${e.replace(".ts", ".js")}";`)).join("\n");
let i = 0;
const exp = [];
const imports = exts.map((e) => (exp.push(`e${i}`), `import e${i++} from "./${e.replace(".ts", ".js")}";`)).join("\n");

return {
contents: `${imports}export const extensions = [${exp.join(", ")}];`,
resolveDir: "./src/ext",
};
});
},
},
],
define: {
ROPESWING_COMMIT: `"${hash}"`,
},
footer: { js: "//# sourceURL=ropeswing" },
legalComments: "none",
return {
contents: `${imports}export const extensions = [${exp.join(", ")}];`,
resolveDir: "./src/ext",
};
});
},
},
],
define: {
ROPESWING_COMMIT: `"${hash}"`,
},
footer: { js: "//# sourceURL=ropeswing" },
legalComments: "none",
};

if (!dev) {
console.log(`Building commit ${hash}...`);
try {
await build(options);
console.log("Build finished");
} catch (e) {
console.error("Build failed");
}
console.log(`Building commit ${hash}...`);
try {
await build(options);
console.log("Build finished");
} catch (e) {
console.error("Build failed");
}
} else {
console.log("Watching for changes");
const ctx = await context(options);
console.log("Watching for changes");
const ctx = await context(options);

const watcher = chokidar.watch(".", {
ignored: ["**/{.git,node_modules}/**", "dist"],
ignoreInitial: true,
ignorePermissionErrors: true,
});
const watcher = chokidar.watch(".", {
ignored: ["**/{.git,node_modules}/**", "dist"],
ignoreInitial: true,
ignorePermissionErrors: true,
});

const debouncedBuild = debouncePromise(
() => ctx.rebuild(),
100,
() => {}
);
const debouncedBuild = debouncePromise(
() => ctx.rebuild(),
100,
() => {},
);

watcher.on("all", (ev, path) => {
console.log("Changed", path);
debouncedBuild();
});
watcher.on("all", (ev, path) => {
console.log("Changed", path);
debouncedBuild();
});

const listener = await listen((req, res) => {
res.writeHead(200, {
"Access-Control-Allow-Origin": "*",
});
const stream = createReadStream("./dist/ropeswing.js");
stream.pipe(res);
}, {
showURL: false,
});
const bundle = listener.url + "ropeswing.js";
console.log(` > ${colors.cyan("https://w96.kasi.workers.dev/install?bundle=" + encodeURIComponent(bundle))}\n`);
const listener = await listen((req, res) => {
res.writeHead(200, {
"Access-Control-Allow-Origin": "*",
});
const stream = createReadStream("./dist/ropeswing.js");
stream.pipe(res);
}, { showURL: false });
const bundle = listener.url + "ropeswing.js";
console.log(` > ${colors.cyan("https://w96.kasi.workers.dev/install?bundle=" + encodeURIComponent(bundle))}\n`);

debouncedBuild();
debouncedBuild();
}

function debouncePromise(fn, delay, onError) {
let timeout;
let promiseInFly;
let callbackPending;
let timeout;
let promiseInFly;
let callbackPending;

return function debounced(...args) {
if (promiseInFly) {
callbackPending = () => {
debounced(...args);
callbackPending = undefined;
};
} else {
if (timeout != null) clearTimeout(timeout);
return function debounced(...args) {
if (promiseInFly) {
callbackPending = () => {
debounced(...args);
callbackPending = undefined;
};
} else {
if (timeout != null) clearTimeout(timeout);

timeout = setTimeout(() => {
timeout = undefined;
promiseInFly = fn(...args)
.catch(onError)
.finally(() => {
promiseInFly = undefined;
if (callbackPending) callbackPending();
});
}, delay);
}
};
timeout = setTimeout(() => {
timeout = undefined;
promiseInFly = fn(...args)
.catch(onError)
.finally(() => {
promiseInFly = undefined;
if (callbackPending) callbackPending();
});
}, delay);
}
};
}
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "ropeswing",
"description": "ropeswing kernel modifications",
"scripts": {
"build": "node build.mjs",
"dev": "node build.mjs --dev"
},
"author": "Beef",
"license": "BSD-3-Clause",
"devDependencies": {
"chokidar": "^3.5.3",
"colorette": "^2.0.20",
"esbuild": "^0.18.11",
"esbuild-plugin-alias": "^0.2.1",
"esbuild-sass-plugin": "^2.10.0",
"listhen": "^1.0.4",
"postcss": "^8.4.26",
"postcss-modules": "^6.0.0",
"typescript": "^5.1.6"
},
"dependencies": {
"spitroast": "^1.4.3",
"voby": "^0.54.0"
}
"name": "ropeswing",
"description": "ropeswing kernel modifications",
"scripts": {
"build": "node build.mjs",
"dev": "node build.mjs --dev"
},
"author": "Beef",
"license": "BSD-3-Clause",
"devDependencies": {
"chokidar": "^3.5.3",
"colorette": "^2.0.20",
"esbuild": "^0.18.11",
"esbuild-plugin-alias": "^0.2.1",
"esbuild-sass-plugin": "^2.10.0",
"listhen": "^1.0.4",
"postcss": "^8.4.26",
"postcss-modules": "^6.0.0",
"typescript": "^5.1.6"
},
"dependencies": {
"spitroast": "^1.4.3",
"voby": "^0.54.0"
}
}
6 changes: 3 additions & 3 deletions src/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as utils from "@lib/utils";
import * as console from "@lib/console";

export default () => ({
console,
utils,
extensions: Object.fromEntries([...extensions].map((e) => [e.manifest.name, { ...e }])),
console,
utils,
extensions: Object.fromEntries([...extensions].map((e) => [e.manifest.name, { ...e }])),
});
60 changes: 30 additions & 30 deletions src/core/patcher.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import { extensions } from "@ext/all";

export function contextify(replace: Replacer, extName: string): Replacer {
const self = `ropeswing.extensions["${extName}"]`;
switch (typeof replace) {
case "string":
return replace.replaceAll("$self", self);
case "function":
return (...args) => replace(...args).replaceAll("$self", self);
}
const self = `ropeswing.extensions["${extName}"]`;
switch (typeof replace) {
case "string":
return replace.replaceAll("$self", self);
case "function":
return (...args) => replace(...args).replaceAll("$self", self);
}
}

export function applyPatches(mainScript: HTMLScriptElement) {
if (!mainScript.textContent) throw new Error("Script doesn't have textContent, what?");

console.group("[ ropeswing-patcher ]");

for (let extension of extensions) {
if (!extension.patches) continue;
for (let patch of extension.patches) {
if (patch.executable) continue;
// TODO: Using `as string` is bad, but TypeScript wasn't having it with my replace typings, and this works
mainScript.textContent = mainScript.textContent.replace(patch.find, contextify(patch.replace, extension.manifest.name) as string);
console.log(`applied patch ${extension.patches.indexOf(patch) + 1} of ${extension.patches.length} from ${extension.manifest.name}`);
}
}

console.groupEnd();
if (!mainScript.textContent) throw new Error("Script doesn't have textContent, what?");

console.group("[ ropeswing-patcher ]");

for (let extension of extensions) {
if (!extension.patches) continue;

for (let patch of extension.patches) {
if (patch.executable) continue;
// TODO: Using `as string` is bad, but TypeScript wasn't having it with my replace typings, and this works
mainScript.textContent = mainScript.textContent.replace(patch.find, contextify(patch.replace, extension.manifest.name) as string);
console.log(`applied patch ${extension.patches.indexOf(patch) + 1} of ${extension.patches.length} from ${extension.manifest.name}`);
}
}

console.groupEnd();
}

export function executePostload() {
console.group("[ ropeswing-postload ]");
console.group("[ ropeswing-postload ]");

for (let extension of extensions) {
if (!extension.onLoad) continue;
for (let extension of extensions) {
if (!extension.onLoad) continue;

extension.onLoad();
console.log(`executed onLoad of ${extension.manifest.name}`);
}
extension.onLoad();
console.log(`executed onLoad of ${extension.manifest.name}`);
}

console.groupEnd();
console.groupEnd();
}
26 changes: 13 additions & 13 deletions src/ext/forcereboot.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { defineExt } from "@lib/utils"
import { defineExt } from "@lib/utils";

export default defineExt({
patches: [
{
executable: "C:/system/local/bin/shell36",
find: /document\.addEventListener\("keydown",/,
replace: () => "(",
},
],
manifest: {
name: "forcereboot",
description: "Removes the reboot confirmation when pressing Ctrl+R or F5",
authors: ["redstonekasi"],
},
patches: [
{
executable: "C:/system/local/bin/shell36",
find: /document\.addEventListener\("keydown",/,
replace: () => "(",
},
],
manifest: {
name: "forcereboot",
description: "Removes the reboot confirmation when pressing Ctrl+R or F5",
authors: ["redstonekasi"],
},
});
Loading

0 comments on commit c10d872

Please sign in to comment.