@sqrzro/server 4.0.0-alpha.5 → 4.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {program}from'commander';import {spawn}from'child_process';import {dirname,resolve
|
|
3
|
-
`)}async function x(){if(!process.env.DATABASE_URL)throw new Error("DATABASE_URL is not defined");let t=process.env.APP_ENV;if(!t||!["development","test"].includes(t))throw new Error("APP_ENV is not defined, or does not support migration.");let e=new Client(process.env.DATABASE_URL);await e.connect(),await e.query("SET client_min_messages TO WARNING; DROP SCHEMA IF EXISTS auth CASCADE; DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;");let o=await C();await e.query(o),await e.end();}var f=x;T.config({path:resolve(process.cwd(),".env"),quiet:true});var p=resolve(process.cwd(),"./database/seeds");async function I(t){let e=await import(t);typeof e.default=="function"&&await e.default();}async function L(){let t=(await readdir(p)).map(e=>resolve(p,e));for(let e of t)await I(e);}var u=L;var w=dirname(fileURLToPath(import.meta.url));resolve(w,"../../node_modules/.bin/tsx");resolve(w,"./scripts");async function z(t){t().then(()=>{process.exit(0);}).catch(e=>{console.error(e),process.exit(1);});}var r=z;program.command("db:generate").action(async()=>await r(m));program.command("db:reset").action(async()=>await r(f));program.command("db:seed").action(async()=>await r(u));program.parse();//# sourceMappingURL=index.js.map
|
|
2
|
+
import {program}from'commander';import {spawn}from'child_process';import {dirname,resolve}from'path';import {fileURLToPath}from'url';var i=dirname(fileURLToPath(import.meta.url)),b=resolve(i,"../../node_modules/.bin/tsx"),f=resolve(i,"./scripts");async function u(n){let a=spawn(b,[`${resolve(f,n)}.ts`],{stdio:"inherit"});return new Promise((s,m)=>{a.on("close",o=>{o===0?s():m(new Error(`Script ${n} exited with code ${o}`));});})}var t=u;program.command("db:generate").action(async()=>await t("db-generate"));program.command("db:reset").action(async()=>await t("db-reset"));program.command("db:seed").action(async()=>await t("db-seed"));program.parse();//# sourceMappingURL=index.js.map
|
|
4
3
|
//# sourceMappingURL=index.js.map
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli/
|
|
1
|
+
{"version":3,"sources":["../../src/cli/utility/run-script.ts","../../src/cli/index.ts"],"names":["__dirname","dirname","fileURLToPath","binPath","resolve","scriptPath","runScript","file","ls","spawn","reject","code","run_script_default","program"],"mappings":";qIAIA,IAAMA,CAAAA,CAAYC,OAAAA,CAAQC,aAAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAC,CAAA,CAElDC,CAAAA,CAAUC,OAAAA,CAAQJ,CAAAA,CAAW,6BAA6B,CAAA,CAC1DK,CAAAA,CAAaD,OAAAA,CAAQJ,CAAAA,CAAW,WAAW,CAAA,CAEjD,eAAeM,CAAAA,CAAUC,CAAAA,CAAc,CACnC,IAAMC,CAAAA,CAAKC,KAAAA,CAAMN,CAAAA,CAAS,CAAC,CAAA,EAAGC,OAAAA,CAAQC,CAAAA,CAAYE,CAAI,CAAC,CAAA,GAAA,CAAK,CAAA,CAAG,CAAE,KAAA,CAAO,SAAU,CAAC,CAAA,CAEnF,OAAO,IAAI,OAAA,CAAc,CAACH,CAAAA,CAASM,CAAAA,GAAW,CAC1CF,CAAAA,CAAG,EAAA,CAAG,OAAA,CAAUG,CAAAA,EAAS,CACjBA,CAAAA,GAAS,CAAA,CACTP,CAAAA,EAAQ,CAERM,CAAAA,CAAO,IAAI,KAAA,CAAM,CAAA,OAAA,EAAUH,CAAI,CAAA,kBAAA,EAAqBI,CAAI,CAAA,CAAE,CAAC,EAEnE,CAAC,EACL,CAAC,CACL,CAEA,IAAOC,CAAAA,CAAQN,CAAAA,CCjBfO,OAAAA,CAAQ,OAAA,CAAQ,aAAa,CAAA,CAAE,MAAA,CAAO,SAAY,MAAMD,CAAAA,CAAU,aAAa,CAAC,CAAA,CAChFC,OAAAA,CAAQ,OAAA,CAAQ,UAAU,CAAA,CAAE,MAAA,CAAO,SAAY,MAAMD,CAAAA,CAAU,UAAU,CAAC,CAAA,CAC1EC,OAAAA,CAAQ,OAAA,CAAQ,SAAS,CAAA,CAAE,MAAA,CAAO,SAAY,MAAMD,CAAAA,CAAU,SAAS,CAAC,CAAA,CAExEC,OAAAA,CAAQ,KAAA,EAAM","file":"index.js","sourcesContent":["import { spawn } from 'node:child_process';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst binPath = resolve(__dirname, '../../node_modules/.bin/tsx');\nconst scriptPath = resolve(__dirname, './scripts');\n\nasync function runScript(file: string) {\n const ls = spawn(binPath, [`${resolve(scriptPath, file)}.ts`], { stdio: 'inherit' });\n\n return new Promise<void>((resolve, reject) => {\n ls.on('close', (code) => {\n if (code === 0) {\n resolve();\n } else {\n reject(new Error(`Script ${file} exited with code ${code}`));\n }\n });\n });\n}\n\nexport default runScript;\n","#!/usr/bin/env node\n\nimport { program } from 'commander';\n\nimport runScript from './utility/run-script';\n\nprogram.command('db:generate').action(async () => await runScript('db-generate'));\nprogram.command('db:reset').action(async () => await runScript('db-reset'));\nprogram.command('db:seed').action(async () => await runScript('db-seed'));\n\nprogram.parse();\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
|
|
7
|
+
const binPath = resolve(__dirname, '../../../node_modules/.bin/drizzle-kit');
|
|
8
|
+
const configPath = resolve(__dirname, '../static/drizzle.config.cjs');
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
const ls = spawn(binPath, ['generate', `--config=${configPath}`], { stdio: 'inherit' });
|
|
12
|
+
|
|
13
|
+
return new Promise<void>((resolve, reject) => {
|
|
14
|
+
ls.on('close', (code) => {
|
|
15
|
+
if (code === 0) {
|
|
16
|
+
resolve();
|
|
17
|
+
} else {
|
|
18
|
+
reject();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
main()
|
|
25
|
+
.then(() => {
|
|
26
|
+
process.exit(0);
|
|
27
|
+
})
|
|
28
|
+
.catch((err) => {
|
|
29
|
+
console.error(err);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
2
|
+
import { extname, resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { Client } from 'pg';
|
|
5
|
+
|
|
6
|
+
import dotenv from 'dotenv';
|
|
7
|
+
dotenv.config({ path: resolve(process.cwd(), '.env'), quiet: true });
|
|
8
|
+
|
|
9
|
+
const migrationPath = resolve(process.cwd(), './database/migrations');
|
|
10
|
+
|
|
11
|
+
async function getMigrationQuery(): Promise<string> {
|
|
12
|
+
const files = (await readdir(migrationPath))
|
|
13
|
+
.filter((file) => extname(file) === '.sql')
|
|
14
|
+
.map((file) => resolve(migrationPath, file));
|
|
15
|
+
|
|
16
|
+
let query = [];
|
|
17
|
+
|
|
18
|
+
for (const file of files) {
|
|
19
|
+
query.push(await readFile(file, 'utf-8'));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return query.join('\n');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function main() {
|
|
26
|
+
if (!process.env.DATABASE_URL) {
|
|
27
|
+
throw new Error('DATABASE_URL is not defined');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const environment = process.env.APP_ENV;
|
|
31
|
+
|
|
32
|
+
if (!environment || !['development', 'test'].includes(environment)) {
|
|
33
|
+
throw new Error('APP_ENV is not defined, or does not support migration.');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const client = new Client(process.env.DATABASE_URL);
|
|
37
|
+
await client.connect();
|
|
38
|
+
|
|
39
|
+
await client.query(
|
|
40
|
+
'SET client_min_messages TO WARNING; DROP SCHEMA IF EXISTS auth CASCADE; DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;'
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const query = await getMigrationQuery();
|
|
44
|
+
await client.query(query);
|
|
45
|
+
|
|
46
|
+
await client.end();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
main()
|
|
50
|
+
.then(() => {
|
|
51
|
+
process.exit(0);
|
|
52
|
+
})
|
|
53
|
+
.catch((err) => {
|
|
54
|
+
console.error(err);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { readdir } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import dotenv from 'dotenv';
|
|
5
|
+
dotenv.config({ path: resolve(process.cwd(), '.env'), quiet: true });
|
|
6
|
+
|
|
7
|
+
const seedPath = resolve(process.cwd(), './database/seeds');
|
|
8
|
+
|
|
9
|
+
async function runSeedFile(file: string) {
|
|
10
|
+
const seedModule = await import(file);
|
|
11
|
+
|
|
12
|
+
if (typeof seedModule.default === 'function') {
|
|
13
|
+
await seedModule.default();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function main() {
|
|
18
|
+
const files = (await readdir(seedPath)).map((file) => resolve(seedPath, file));
|
|
19
|
+
|
|
20
|
+
for (const file of files) {
|
|
21
|
+
await runSeedFile(file);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
main()
|
|
26
|
+
.then(() => {
|
|
27
|
+
process.exit(0);
|
|
28
|
+
})
|
|
29
|
+
.catch((err) => {
|
|
30
|
+
console.error(err);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
require('dotenv/config');
|
|
2
|
+
const { defineConfig } = require('drizzle-kit');
|
|
3
3
|
|
|
4
4
|
if (!process.env.DATABASE_URL) {
|
|
5
5
|
throw new Error('DATABASE_URL is not defined. Database migration cannot be generated.');
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
module.exports = defineConfig({
|
|
9
9
|
dbCredentials: {
|
|
10
10
|
url: process.env.DATABASE_URL,
|
|
11
11
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqrzro/server",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"pg": "^8.16.3",
|
|
53
53
|
"react-dom": "^19.2.1",
|
|
54
54
|
"redis": "^5.10.0",
|
|
55
|
+
"tsx": "^4.21.0",
|
|
55
56
|
"zod": "^4.1.13",
|
|
56
57
|
"@sqrzro/utility": "^4.0.0-alpha.1"
|
|
57
58
|
},
|
|
@@ -66,7 +67,6 @@
|
|
|
66
67
|
"rimraf": "^4.4.1",
|
|
67
68
|
"ts-jest": "^29.4.6",
|
|
68
69
|
"tsup": "^8.5.1",
|
|
69
|
-
"tsx": "^4.21.0",
|
|
70
70
|
"typescript": "^5.9.3",
|
|
71
71
|
"@sqrzro/prettier-config": "^4.0.0-alpha.1"
|
|
72
72
|
},
|