feat(infra): singular dockerfile with vite bundling
Using Vite as a bundler to allow easier builds, with shared library Moved to a single dockerfile that takes an argument to specify which service to use moved some file around to faciliate bundling with vite cried a lot
This commit is contained in:
parent
bdc4616106
commit
573af0bc4b
21 changed files with 1587 additions and 1062 deletions
|
|
@ -4,12 +4,7 @@
|
|||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"description": "shared utils library",
|
||||
"scripts": {
|
||||
"embed": "npm run embed:sql",
|
||||
"embed:sql": "node scripts/embed:sql.js",
|
||||
"build:ts": "npm run embed:sql && tsc -d",
|
||||
"watch:ts": "tsc -d -w"
|
||||
},
|
||||
"scripts": {},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
|
|
@ -17,14 +12,10 @@
|
|||
"better-sqlite3": "^11.10.0",
|
||||
"fastify": "^5.0.0",
|
||||
"fastify-plugin": "^5.0.1",
|
||||
"typescript-result": "3.1.1",
|
||||
"uuidv7": "^1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/better-sqlite3": "^7.6.13",
|
||||
"@types/node": "^22.1.0",
|
||||
"c8": "^10.1.2",
|
||||
"concurrently": "^9.0.0",
|
||||
"typescript": "~5.8.2"
|
||||
"@types/node": "^22.1.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
// ************************************************************************** //
|
||||
// //
|
||||
// ::: :::::::: //
|
||||
// embed.js :+: :+: :+: //
|
||||
// +:+ +:+ +:+ //
|
||||
// By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ //
|
||||
// +#+#+#+#+#+ +#+ //
|
||||
// Created: 2025/06/19 23:32:59 by maiboyer #+# #+# //
|
||||
// Updated: 2025/06/20 00:09:04 by maiboyer ### ########.fr //
|
||||
// //
|
||||
// ************************************************************************** //
|
||||
|
||||
import { readFile, writeFile, stat } from "node:fs/promises";
|
||||
|
||||
/**
|
||||
* escape a string to be a valid js string literal
|
||||
* @param {string} input
|
||||
* @returns {string}
|
||||
*/
|
||||
function escape(input) {
|
||||
return JSON.stringify(input)
|
||||
.replace('\n', '\\n')
|
||||
.replace('\t', '\\t')
|
||||
.replace('\r', '\\r')
|
||||
.replace('\v', '\\v');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Embed {input} inside a default exported string at location {output}
|
||||
* @param {string} input
|
||||
* @param {string} output
|
||||
* @returns void
|
||||
*/
|
||||
export default async function embed(input, output) {
|
||||
const inputData = (await readFile(input)).toString('utf-8');
|
||||
const inputStat = await stat(input);
|
||||
|
||||
const escapedData = escape(inputData);
|
||||
|
||||
const fullFile = `\
|
||||
//! this file was generated automatically.
|
||||
//! it is just a string literal that is the file ${input}
|
||||
//! if you want to edit this file, DONT. edit ${input} please
|
||||
//!
|
||||
//! this file need to be regenerated on changes to ${input} manually.
|
||||
//! the \`npm run build:ts\` might regenerate it, but do check.
|
||||
//! here is the date of the last time it was generated: ${new Date(Date.now())}
|
||||
//! the file ${input} that is embeded was modified on ${inputStat.mtime}
|
||||
//! the file ${input} that is embeded was ${inputStat.size} bytes
|
||||
|
||||
|
||||
export default ${escapedData};\
|
||||
`;
|
||||
|
||||
await writeFile(output, fullFile, { flush: true, flag: "w" })
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
// ************************************************************************** //
|
||||
// //
|
||||
// ::: :::::::: //
|
||||
// embed:sql.js :+: :+: :+: //
|
||||
// +:+ +:+ +:+ //
|
||||
// By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ //
|
||||
// +#+#+#+#+#+ +#+ //
|
||||
// Created: 2025/06/19 23:30:39 by maiboyer #+# #+# //
|
||||
// Updated: 2025/07/28 15:36:11 by maiboyer ### ########.fr //
|
||||
// //
|
||||
// ************************************************************************** //
|
||||
|
||||
import embed from "./embed.js";
|
||||
|
||||
await embed('./src/database/init.sql', './src/database/init.sql.ts')
|
||||
|
|
@ -6,16 +6,15 @@
|
|||
// By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ //
|
||||
// +#+#+#+#+#+ +#+ //
|
||||
// Created: 2025/07/28 17:36:22 by maiboyer #+# #+# //
|
||||
// Updated: 2025/07/28 17:36:26 by maiboyer ### ########.fr //
|
||||
// Updated: 2025/07/30 21:19:05 by maiboyer ### ########.fr //
|
||||
// //
|
||||
// ************************************************************************** //
|
||||
|
||||
import fp from 'fastify-plugin'
|
||||
import { FastifyInstance } from 'fastify'
|
||||
import sqlite from 'better-sqlite3'
|
||||
import { Result } from 'typescript-result'
|
||||
|
||||
import initSql from "./init.sql.js"
|
||||
import initSql from "./init.sql?raw"
|
||||
import { newUUIDv7, UUIDv7 } from '@shared/uuid'
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
//! this file was generated automatically.
|
||||
//! it is just a string literal that is the file ./src/database/init.sql
|
||||
//! if you want to edit this file, DONT. edit ./src/database/init.sql please
|
||||
//!
|
||||
//! this file need to be regenerated on changes to ./src/database/init.sql manually.
|
||||
//! the `npm run build:ts` might regenerate it, but do check.
|
||||
//! here is the date of the last time it was generated: Mon Jul 28 2025 16:40:15 GMT+0200 (Central European Summer Time)
|
||||
//! the file ./src/database/init.sql that is embeded was modified on Sat Jul 19 2025 15:33:56 GMT+0200 (Central European Summer Time)
|
||||
//! the file ./src/database/init.sql that is embeded was 436 bytes
|
||||
|
||||
|
||||
export default "-- this file will make sure that the database is always up to date with the correct schema\n-- when editing this file, make sure to always include stuff like `IF NOT EXISTS` such as to not throw error\n-- NEVER DROP ANYTHING IN THIS FILE\nCREATE TABLE IF NOT EXISTS users (\n id STRING UNIQUE PRIMARY KEY, -- UUIDv7 as a string\n name STRING UNIQUE, -- name of the user\n token STRING UNIQUE, -- the token of the user (aka the cookie)\n);\n\n";
|
||||
|
|
@ -6,11 +6,10 @@
|
|||
// By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ //
|
||||
// +#+#+#+#+#+ +#+ //
|
||||
// Created: 2025/06/20 17:41:01 by maiboyer #+# #+# //
|
||||
// Updated: 2025/07/28 15:42:53 by maiboyer ### ########.fr //
|
||||
// Updated: 2025/07/30 16:08:19 by maiboyer ### ########.fr //
|
||||
// //
|
||||
// ************************************************************************** //
|
||||
|
||||
import { Result } from "typescript-result";
|
||||
import { uuidv7 } from "uuidv7";
|
||||
|
||||
export class InvalidUUID extends Error {
|
||||
|
|
@ -38,11 +37,11 @@ export function isUUIDv7(value: string): value is UUIDv7 {
|
|||
return uuidv7Regex.test(value);
|
||||
}
|
||||
|
||||
export function toUUIDv7(value: string): Result<UUIDv7, InvalidUUID> {
|
||||
if (!isUUIDv7(value)) return Result.error(new InvalidUUID());
|
||||
|
||||
return Result.ok(value.toLowerCase() as UUIDv7);
|
||||
}
|
||||
//export function toUUIDv7(value: string): Result<UUIDv7, InvalidUUID> {
|
||||
// if (!isUUIDv7(value)) return Result.error(new InvalidUUID());
|
||||
//
|
||||
// return Result.ok(value.toLowerCase() as UUIDv7);
|
||||
//}
|
||||
|
||||
export function newUUIDv7(): UUIDv7 {
|
||||
return uuidv7() as UUIDv7;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue