docs(rewrite): Better setup instructions that *should* work, etc.

This commit is contained in:
tecc 2023-09-14 18:20:24 +02:00
parent cc32163e19
commit fbacef16ec
No known key found for this signature in database
GPG Key ID: 622EEC5BAE5EBD3A
3 changed files with 43 additions and 4 deletions

View File

@ -2,6 +2,17 @@
This is the working directory for the Pronouns.page rewrite.
## Setup instructions
> Note that this section will assume you are using [pnpm](https://pnpm.io).
1. Install dependencies using `pnpm install`.
2. Run the `setup.mjs` script using `node ./setup.mjs`.
3. Build the `common` package (`pnpm build`). This step has to be done every time you change it.
4. The next step depends _entirely_ on what part of the project you're working on:
1. For the backend: Run `pnpm dev`. This will automatically build and restart the server when you change the code.
It's actually quite fast.
## Development environment
### `setup.mjs`
@ -22,6 +33,8 @@ Just use pnpm for as little friction as possible.
Prettier and ESLint are used for formatting and linting respectively.
You can run `pnpm format` from the top-level directory of the rewrite to format all the code easily.
### Other notes
Currently, the packages here are using `"type": "module"`. This is mostly experimental and can be changed if it turns out to be annoying/code-breaking.

View File

@ -1,4 +1,5 @@
{
"private": true,
"scripts": {
"format": "prettier -w ."
},

View File

@ -4,6 +4,8 @@ import path from "node:path";
console.log("Setting up project");
let currentlySettingUp = "";
const url = new URL(import.meta.url);
const projectDir = path.dirname(
path.resolve(
@ -15,6 +17,14 @@ const projectDir = path.dirname(
);
const legacyDir = path.resolve(projectDir, "..");
function message(str) {
let prefix = "";
if (!!currentlySettingUp && currentlySettingUp.trim().length >= 0) {
prefix = `[${currentlySettingUp}]`;
}
console.log(" " + str);
}
console.log(`
Project directory: ${projectDir}
Legacy directory: ${legacyDir}
@ -22,20 +32,35 @@ console.log(`
async function symlink(to, from) {
if (!fs.existsSync(from)) {
console.log(` Creating symlink from ${from} to ${to}`);
message(`Creating symlink from ${from} to ${to}`);
await fsp.symlink(to, from, "dir");
} else {
console.log(` File ${from} already exists - not symlinking to ${to}`);
message(`File ${from} already exists - not symlinking to ${to}`);
}
}
// Create temporary symlinks
// This step may very well be removed in the future.
{
currentlySettingUp = "locales";
const to = path.resolve(legacyDir, "locale"),
from = path.resolve(projectDir, "locales");
await symlink(to, from);
}
console.log(`
Done!`);
{
currentlySettingUp = "backend";
const backendDir = path.resolve(projectDir, "backend");
const envFile = path.resolve(backendDir, ".env"),
exampleEnvFile = path.resolve(backendDir, "example.env");
if (!fs.existsSync(envFile)) {
message(`Missing .env file for backend, creating from example.env`);
await fsp.cp(exampleEnvFile, envFile);
} else {
message(`[backend] Environment file already exists, continuing`);
}
}
console.log(`\nDone!`);