chore: add directoryMode flag to enhanceApp for notion-repackaged

This commit is contained in:
dragonwocky 2024-11-19 21:48:14 +11:00
parent 9f8d9030ae
commit dae9700b0b
Signed by: dragonwocky
GPG Key ID: 7998D08F7D7BD7A8
2 changed files with 43 additions and 35 deletions

View File

@ -93,27 +93,42 @@ const backupApp = async () => {
await fsp.rename(archive + ".bak", archive);
return true;
},
enhanceApp = async (debug = false) => {
enhanceApp = async (debug = false, directoryMode = false) => {
const app = getResourcePath("app"),
archive = getResourcePath("app.asar");
if (!existsSync(archive)) return false;
if (existsSync(app)) await fsp.rm(app, { recursive: true, force: true });
await fsp.mkdir(app);
// extract archive to folder and apply patches
for (let file of asar.listPackage(archive)) {
file = file.replace(/^\//g, "");
const stat = asar.statFile(archive, file),
isFolder = !!stat.files,
isSymlink = !!stat.link,
isExecutable = stat.executable,
appPath = resolve(app, file);
if (isFolder) {
await fsp.mkdir(appPath);
} else if (isSymlink) {
await fsp.symlink(appPath, resolve(app, link));
} else {
await fsp.writeFile(appPath, patch(file, extractFile(file)));
if (isExecutable) await fsp.chmod(appPath, "755");
// directory mode acts on pre-extracted sources
// as part of the notion-repackaged build process
if (directoryMode) {
if (!existsSync(app)) return false;
for (let file of await fsp.readdir(app, { recursive: true })) {
file = file.replace(/^\//g, "");
const appPath = resolve(app, file),
stat = await fsp.stat(appPath);
if (stat.isFile()) {
const content = await fsp.readFile(appPath);
await fsp.writeFile(appPath, patch(file, content));
}
}
} else {
if (!existsSync(archive)) return false;
if (existsSync(app)) await fsp.rm(app, { recursive: true, force: true });
await fsp.mkdir(app);
// extract archive to folder and apply patches
for (let file of asar.listPackage(archive)) {
file = file.replace(/^\//g, "");
const stat = asar.statFile(archive, file),
isFolder = !!stat.files,
isSymlink = !!stat.link,
isExecutable = stat.executable,
appPath = resolve(app, file);
if (isFolder) {
await fsp.mkdir(appPath);
} else if (isSymlink) {
await fsp.symlink(appPath, resolve(app, link));
} else {
await fsp.writeFile(appPath, patch(file, extractFile(file)));
if (isExecutable) await fsp.chmod(appPath, "755");
}
}
}
// insert the notion-enhancer/src folder into notion's node_modules
@ -126,10 +141,12 @@ const backupApp = async () => {
excludes = ["bin", "type", "scripts", "engines", "dependencies"];
for (const key of excludes) delete manifest[key];
await fsp.writeFile(insertManifest, JSON.stringify(manifest));
// re-package enhanced sources into executable archive
await asar.createPackage(app, archive);
// cleanup extracted files unless in debug mode
if (!debug) await fsp.rm(app, { recursive: true });
if (!directoryMode) {
// re-package enhanced sources into executable archive
await asar.createPackage(app, archive);
// cleanup extracted files unless in debug mode
if (!debug) await fsp.rm(app, { recursive: true });
}
return true;
};

View File

@ -38,18 +38,9 @@ export default async function (api, db) {
--guide--opacity: 1;
}`;
if (rainbowMode) {
const selector = `:is(${nestedTargets.join(",")})`,
opacity = `--guide--opacity: 0.5;`,
colours = [
"red",
"pink",
"purple",
"blue",
"green",
"yellow",
"orange",
"brown",
];
const opacity = `--guide--opacity: 0.5;`,
selector = `:is(${nestedTargets.join(",")})`,
colours = ["green", "blue", "purple", "pink", "red", "orange", "yellow"];
colours.push(...colours, ...colours, ...colours, "gray");
for (let i = 0; i < colours.length; i++) {
css += `${(selector + " ").repeat(i + 1)} {