Skip to content

Commit

Permalink
feat: improve dev scripts (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiroaisen authored Nov 28, 2023
2 parents 8f30261 + 228c1c8 commit 21a9687
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 133 deletions.
4 changes: 4 additions & 0 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"ci:server": "cd server && npm ci",
"ci:admin": "cd admin && npm ci",
"ci:app": "cd app && npm ci",
"dev": "run-p dev:server dev:admin dev:app",
"dev:server": "cd server && npm run dev",
"dev:app": "cd app && npm run dev",
"dev:admin": "cd admin && npm run dev",
"start": "cd server && npm run start"
},
"keywords": [],
Expand Down
391 changes: 273 additions & 118 deletions front/server/package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion front/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"scripts": {
"prepare": "ts-patch install -s",
"start": "node --no-warnings --experimental-specifier-resolution=node dist/cli.js start",
"dev": "SVELTEKIT_APP_DEV=1 SVELTEKIT_APP_PORT=3100 SVETEKIT_ADMIN_DEV=1 SVELTEKIT_ADMIN_PORT=5100 nodemon --exec node --no-warnings --experimental-specifier-resolution=node --loader ts-node/esm src/cli.ts start",
"dev:run": "SVELTEKIT_APP_DEV=1 SVELTEKIT_APP_PORT=3100 SVELTEKIT_ADMIN_DEV=1 SVELTEKIT_ADMIN_PORT=5100 nodemon --no-warnings --experimental-specifier-resolution=node dist/cli.js start",
"dev:compile": "tsc -w",
"dev": "run-p dev:compile dev:run",
"build": "tsc",
"test": "npm run build && ava --match='!*integration*'"
},
Expand All @@ -27,6 +29,7 @@
"node-fetch": "^2.6.7",
"qs": "^6.11.0",
"toml": "^3.0.0",
"ts-node-dev": "^2.0.0",
"typia": "^3.4.18"
},
"devDependencies": {
Expand Down
20 changes: 16 additions & 4 deletions front/server/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,23 @@ const get_log_ts = (): boolean => {
return true;
}

const bool = (key: string, def: boolean | null = null): boolean => {
const v = process.env[key];
if(v == null) {
if(def != null) return def;
else throw new Error(`env.${key} is required`)
} else {
if(v === "1" || v === "true") return true;
else if(v === "0" || v === "false") return false;
else throw new Error(`env.${key} must be a boolean ("1", "0", "true" or "false")`)
}
}

export const env = {
SVELTEKIT_APP_DEV: ["1", "true"].includes(process.env.SVELTEKIT_APP_DEV ?? ""),
SVELTEKIT_APP_DEV: bool("SVELTEKIT_APP_DEV", false),
SVELTEKIT_APP_PORT: Number(process.env.SVELTEKIT_APP_PORT) || 3100,
SVELTEKIT_ADMIN_DEV: ["1", "true"].includes(process.env.SVELTEKIT_ADMIN_DEV ?? ""),
SVELTEKIT_ADMIN_PORT: Number(process.env.SVELTEKIT_APP_PORT) || 5100,
SVELTEKIT_ADMIN_DEV: bool("SVELTEKIT_ADMIN_DEV", false),
SVELTEKIT_ADMIN_PORT: Number(process.env.SVELTEKIT_ADMIN_PORT) || 5100,
LOG_LEVEL: get_log_level(),
LOG_TS: get_log_ts()
}
}
10 changes: 8 additions & 2 deletions front/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export const start = async ({ config, logger }: { config: Config, logger: Logger
app.use(express.static(path.resolve(__dirname, "../../../static/studio"), { etag: true, dotfiles: "allow" }))

if(env.SVELTEKIT_APP_DEV) {
app.use(sveltekit_dev_proxy(env.SVELTEKIT_APP_PORT))
app.use((req, res) => {
res.redirect(302, `http://${req.hostname}:${env.SVELTEKIT_APP_PORT}${req.url}`)
})
// app.use(sveltekit_dev_proxy(env.SVELTEKIT_APP_PORT))
} else {
process.env.APP_API_PORT = String(config.studio.port);
const { handler }: { handler: RequestHandler } = await import("" + "../../app/build/handler.js")
Expand All @@ -50,7 +53,10 @@ export const start = async ({ config, logger }: { config: Config, logger: Logger
app.use(express.static(path.resolve(__dirname, "../../../static/admin"), { etag: true, dotfiles: "allow" }))

if(env.SVELTEKIT_ADMIN_DEV) {
app.use(sveltekit_dev_proxy(env.SVELTEKIT_ADMIN_PORT))
app.use((req, res) => {
res.redirect(302, `http://${req.hostname}:${env.SVELTEKIT_ADMIN_PORT}${req.url}`)
})
//app.use(sveltekit_dev_proxy(env.SVELTEKIT_ADMIN_PORT))
} else {
process.env.ADMIN_API_PORT = String(config.admin.port);
const { handler }: { handler: RequestHandler } = await import("" + "../../admin/build/handler.js")
Expand Down
6 changes: 0 additions & 6 deletions package-lock.json

This file was deleted.

21 changes: 20 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
{}
{
"name": "openstream",
"version": "1.0.0",
"description": "Openstream Media Server",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ramiroaisen/openstream.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/ramiroaisen/openstream/issues"
},
"homepage": "https://github.com/ramiroaisen/openstream#readme"
}
2 changes: 1 addition & 1 deletion rs/packages/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl IntoExistFilter for &str {
}

pub fn init(client: Client, storage_db_name: Option<String>) {
try_init(client, storage_db_name).expect("[internal] mongodb client initialized more than once, this is a bug, please file an issue at https://github.com/ramiroaisen/openstream-rs")
try_init(client, storage_db_name).expect("[internal] mongodb client initialized more than once, this is a bug, please file an issue at https://github.com/ramiroaisen/openstream")
}

pub fn try_init(
Expand Down

0 comments on commit 21a9687

Please sign in to comment.