Browse Source

feat: Working nix build

tags/v0.1.0
Dale 2 months ago
parent
commit
79293bf120
10 changed files with 63 additions and 30 deletions
  1. +3
    -1
      .gitignore
  2. +3
    -6
      bin/buildServer.sh
  3. +1
    -0
      bin/miracle-tv-server
  4. +3
    -0
      config/local.json
  5. +32
    -8
      default.nix
  6. +6
    -8
      package.json
  7. +5
    -0
      src/server/config.ts
  8. +0
    -1
      src/server/db/index.ts
  9. +6
    -1
      src/server/server.ts
  10. +4
    -5
      tsconfig.json

+ 3
- 1
.gitignore View File

@@ -2,4 +2,6 @@ node_modules/
dist/
yarn-error.log
src/**/*.js
dev.sqlite3
dev.sqlite3

.types

+ 3
- 6
bin/buildServer.sh View File

@@ -1,8 +1,5 @@
#!/usr/bin/env sh

rm -rf $src/dist
tsc
cp $src/dist/* $out/
mkdir $out/bin
cp $src/bin/miracle-tv-server $out/bin
chmod +x $out/bin/*
rm -rf ./dist || true
./node_modules/.bin/tsc --build ./tsconfig.json &&
mkdir ./dist/bin

+ 1
- 0
bin/miracle-tv-server View File

@@ -2,5 +2,6 @@

BIN_PATH="$(dirname "$0")"

echo $BIN_PATH
NODE_PATH=$BIN_PATH/../src
node $BIN_PATH/../src/server/server.js "$0"

+ 3
- 0
config/local.json View File

@@ -2,6 +2,9 @@
"auth": {
"sessionTTL": 0
},
"server": {
"port": 8081
},
"database": {
"client": "pg",
"connection": {


+ 32
- 8
default.nix View File

@@ -6,11 +6,16 @@ mkYarnPackage {
version = "0.1.0";
system = builtins.currentSystem;

src = fetchgit {
url = "https://code.gensokyo.social/Gensokyo.social/miracle-tv.git";
rev = "ce1b3484939260e6e29717a49353fdab32bf6f14";
sha256 = "1abp466xrrx8fgh03q0lmjq6wqnh72hjk798c1hl7fahzqr5h796";
};
doDist = false;

# src = fetchgit {
# url = "https://code.gensokyo.social/Gensokyo.social/miracle-tv.git";
# rev = "67a47694fdd59c4e865e5e3f0d762c13b4cf9ca5";
# sha256 = "09mzgiklb8ck4i6jdfa0xf3hhl59fy9iprshjrapp0h16vg98wnv";
# };
#

src = ./.;

packageJSON = ./package.json;
yarnLock = ./yarn.lock;
@@ -20,12 +25,31 @@ mkYarnPackage {
export PATH="$PATH:$PWD/node_modules/.bin"
'';

configurePhase = ''
rm -rf ./node_modules || true
ln -s $node_modules ./node_modules
'';

buildPhase = ''
cd $src
bash $src/bin/buildServer.sh
cp dist/* $out
sh ./bin/buildServer.sh
'';

installPhase = ''
mkdir $out
cp -R ./dist/* $out
mkdir $out/node_modules
cp -R $node_modules/* $out/node_modules/
makeWrapper ${nodejs-14_x}/bin/node $out/bin/miracle-tv-server \
--add-flags $out/server/server.js \
--set NODE_PATH $NODE_PATH:$out:$node_modules
'';

distPhase = ''
true
'';

nativeBuildInputs = [ makeWrapper ];

buildInputs = with pkgs; [
yarn automake autoconf m4 git bash
nodejs-14_x libpng libGL gcc


+ 6
- 8
package.json View File

@@ -8,12 +8,12 @@
"scripts": {
"test": "./bin/testServer.sh",
"test:mocha": "NODE_PATH=./src ./node_modules/.bin/mocha",
"watch:server": "./node_modules/.bin/nodemon -e ts --exec \"yarn run:server\"",
"run:server": "./node_modules/.bin/ts-node -r ./node_modules/tsconfig-paths/register ./src/server/server.ts",
"watch:server": "$node_modules/.bin/nodemon -e ts --exec \"yarn run:server\"",
"run:server": "$node_modules/.bin/ts-node -r $node_modules/tsconfig-paths/register ./src/server/server.ts",
"build:server": "./bin/buildServer.sh",
"test:server": "NODE_PATH=./src ./node_modules/.bin/mocha -r ts-node/register -r tsconfig-paths/register test/server/**/*.spec.ts --configPath ./config/test.json",
"migrate:add": "./node_modules/.bin/knex migrate:make --migrations-directory .\\migrations",
"migrate:local": "./node_modules/.bin/knex migrate:latest",
"test:server": "NODE_PATH=./src $node_modules/.bin/mocha -r ts-node/register -r tsconfig-paths/register test/server/**/*.spec.ts --configPath ./config/test.json",
"migrate:add": "$node_modules/.bin/knex migrate:make --migrations-directory .\\migrations",
"migrate:local": "$node_modules/.bin/knex migrate:latest",
"migrate:test": "yarn migrate:local ./config/test.json"
},
"postInstall": "chmod +x ./bin/*",
@@ -31,9 +31,7 @@
"ramda": "^0.26.1",
"sqlite3": "^5.0.0",
"supertest": "^4.0.2",
"uuid": "^3.3.2"
},
"devDependencies": {
"uuid": "^3.3.2",
"@types/ajv": "^1.0.0",
"@types/chai": "^4.1.7",
"@types/cors": "^2.8.5",


+ 5
- 0
src/server/config.ts View File

@@ -13,8 +13,13 @@ interface IDBConfig {
};
}

interface IServerConfig {
port: number;
}

interface IConfig {
database: IDBConfig;
server: IServerConfig;
}
const defaultConfigPath = `${process.cwd()}/config/local.json`;
const args = minimist(process.argv.slice(2));


+ 0
- 1
src/server/db/index.ts View File

@@ -1,5 +1,4 @@
import Knex from 'knex';
import { pathOr } from 'ramda';

import config from 'server/config';



+ 6
- 1
src/server/server.ts View File

@@ -1,6 +1,9 @@
import Express from 'express';
import apiRouter from 'server/routes/api';
import db from 'server/db';
import { pathOr } from 'ramda';

import config from 'server/config';

const app = Express();
export const appDB = db;
@@ -9,6 +12,8 @@ app.use('/api', apiRouter);

export default app;

const port = pathOr(8080, ['server', 'port'], config);

if (require.main === module) {
app.listen(8080, () => console.info('Listening on 8080!'));
app.listen(port, () => console.info(`Listening on ${port}!`));
}

+ 4
- 5
tsconfig.json View File

@@ -8,16 +8,15 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"sourceMap": false,
"outDir": "dist",
"outDir": "./dist/server",
"baseUrl": "./",
"typeRoots" : ["./node_modules", "./node_modules/@types", "src/server/types"],
"types": [],
"typeRoots" : ["./node_modules", "./node_modules/@types"],
"paths": {
"server/*": [ "src/server/*" ],
"shared/*": [ "src/shared/*" ],
"server/*": [ "src/server/*" ]
}
},
"include": [
"./test/**/*",
"./src/**/*"
]
}

Loading…
Cancel
Save