nomadro/apps/work/scripts/patch-planka-for-next.mjs
Eric 2b574f7957 Ship native /social/work: Planka-shaped boards + Etherpad pads on FastAPI.
Secondary-dev Next UI with DnD, labels, stopwatch, archive, activity; pads with revisions; README documents pnpm dev:work-api.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-04 01:06:26 +08:00

209 lines
5.8 KiB
JavaScript

#!/usr/bin/env node
/**
* Apply Nomadro Next.js secondary-dev patches onto synced Planka vendor.
*/
import { readFileSync, writeFileSync, existsSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const root = join(dirname(fileURLToPath(import.meta.url)), "../../..");
const vendor = join(root, "src/modules/work/planka/vendor");
function patch(rel, fn) {
const p = join(vendor, rel);
if (!existsSync(p)) {
console.warn("skip missing", rel);
return;
}
const before = readFileSync(p, "utf8");
const after = fn(before);
if (after !== before) {
writeFileSync(p, after, "utf8");
console.log("patched", rel);
} else {
console.log("unchanged", rel);
}
}
// UI under /social/work/app ; API under /work-api (proxied to Planka server)
patch("constants/Config.js", () => `/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*
* Modified for Nomadro Next.js secondary-dev (UI + API base split).
*/
const UI_BASE_PATH = '/social/work/app';
const API_BASE_PATH = '/work-api';
/** @deprecated use UI_BASE_PATH for router; kept for Paths compat */
const BASE_PATH = UI_BASE_PATH;
const ACCESS_TOKEN_KEY = 'accessToken';
const ACCESS_TOKEN_VERSION_KEY = 'accessTokenVersion';
const ACCESS_TOKEN_VERSION = '1';
const POSITION_GAP = 65536;
const CARDS_LIMIT = 50;
const COMMENTS_LIMIT = 50;
const ACTIVITIES_LIMIT = 50;
const MAX_SIZE_TO_DISPLAY_CONTENT = 256 * 1024;
const IS_MAC =
typeof navigator !== 'undefined' && navigator.platform.startsWith('Mac');
const IS_TOUCH_PRIMARY =
typeof window !== 'undefined' && window.matchMedia('(hover: none)').matches;
export default {
BASE_PATH,
UI_BASE_PATH,
API_BASE_PATH,
ACCESS_TOKEN_KEY,
ACCESS_TOKEN_VERSION_KEY,
ACCESS_TOKEN_VERSION,
POSITION_GAP,
CARDS_LIMIT,
COMMENTS_LIMIT,
ACTIVITIES_LIMIT,
MAX_SIZE_TO_DISPLAY_CONTENT,
IS_MAC,
IS_TOUCH_PRIMARY,
};
`);
patch("api/http.js", (s) =>
s
.replace(
"fetch(`${Config.BASE_PATH}/api${url}`",
"fetch(`${Config.API_BASE_PATH}/api${url}`",
)
.replace(
"Modified for Nomadro",
"Modified for Nomadro",
),
);
patch("api/socket.js", (s) =>
s
.replace(
"io.sails.path = `${Config.BASE_PATH}/socket.io`;",
"io.sails.path = `${Config.API_BASE_PATH}/socket.io`;",
)
.replace(
"io.sails.environment = import.meta.env.MODE;",
"io.sails.environment = process.env.NODE_ENV === 'production' ? 'production' : 'development';",
),
);
patch("store.js", (s) => {
let out = s.replace(
/import\.meta\.env\.DEV/g,
"process.env.NODE_ENV !== 'production'",
);
if (!out.includes("Nomadro Next may omit redux-logger")) {
out = out.replace(
/if \(process\.env\.NODE_ENV !== 'production'\) \{[\s\S]*?middlewares\.push\(require\('redux-logger'\)\);[\s\S]*?\}/,
`if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
try {
// optional — Nomadro Next may omit redux-logger
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
middlewares.push(require('redux-logger').default || require('redux-logger'));
} catch (_) {
/* ignore */
}
if (typeof window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ !== 'undefined') {
compose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
}
}`,
);
}
return out;
});
patch("i18n.js", (s) =>
s.replace(/import\.meta\.env\.DEV/g, "process.env.NODE_ENV !== 'production'"),
);
patch("components/common/Root.jsx", (s) => {
let out = s
.replace('<ThemeProvider theme="light">', '<ThemeProvider theme="dark">')
.replace(
"import '../../lib/custom-ui/styles.css';\n",
"// Nomadro: skip custom-ui/styles.css (invalid CSS for LightningCSS)\n",
);
if (!out.includes("@work/planka/bridge/nomadro-planka.css")) {
out = out.replace(
"import '../../styles.module.scss';",
"import '../../styles.module.scss';\nimport '@work/planka/bridge/nomadro-planka.css';",
);
}
return out;
});
// Vite SVG ?react → Nomadro shim
const svgFiles = [
"components/lists/List/List.jsx",
"components/common/Home/Projects.jsx",
"components/boards/Board/GridView.jsx",
"components/boards/Board/ListView.jsx",
"components/boards/Board/KanbanContent/KanbanContent.jsx",
];
for (const rel of svgFiles) {
patch(rel, (s) =>
s.replace(/from '([^']+\.svg)\?react'/g, "from '@work/planka/bridge/SvgIcon'"),
);
}
patch("components/common/AboutModal/AboutPane.jsx", (s) =>
s.replace(
/import changelogUrl from '[^']+CHANGELOG\.md\?url';/,
"const changelogUrl = 'https://github.com/plankanban/planka/blob/master/CHANGELOG.md';",
),
);
// Turbopack rejects nested `:global { .foo }` inside CSS modules
patch(
"components/common/MarkdownEditor/MarkdownEditor.module.scss",
() => `/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*
* Modified for Nomadro Next/Turbopack (flatten :global nesting).
*/
.editor {
min-height: 200px;
}
.wrapper {
--g-md-editor-padding: 6px 12px;
--g-md-toolbar-padding: 6px 12px;
--g-md-toolbar-sticky-offset: -21px;
border: 1px solid rgba(9, 30, 66, 0.13);
border-radius: 3px;
}
.wrapperError {
border: 1px solid #cf513d;
}
`,
);
// Semantic UI pack uses invalid `:activehover` — LightningCSS rejects it
{
const cssPath = join(vendor, "lib/custom-ui/styles.css");
if (existsSync(cssPath)) {
const raw = readFileSync(cssPath, "utf8");
const fixed = raw.replace(/:activehover/g, ":active:hover");
if (fixed !== raw) {
writeFileSync(cssPath, fixed, "utf8");
console.log("patched lib/custom-ui/styles.css activehover");
}
}
}
console.log("DONE patch-planka-for-next");