Skip to content

Commit

Permalink
Nixified js-polykey
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed Jan 24, 2021
1 parent e54cafe commit c2c13a2
Show file tree
Hide file tree
Showing 85 changed files with 11,347 additions and 50,397 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
trim_trailing_whitespace = true
13 changes: 0 additions & 13 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
STEP_ROOT='tmp/secrets/CA/root_ca.crt'
STEP_CA_URL='https://localhost:55555'
CERTIFICATE_AUTHORITY_PROVISIONER_PASSWORD=
CERTIFICATE_AUTHORITY_FINGERPRINT=

// Twilio STUN and TURN
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=

// Change where polykey agent
// socket and logs are created
PK_SOCKET_PATH=
PK_LOG_PATH=
15 changes: 4 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/.env
/result
/result-*

# gitlab-runner exec
/builds

# dist folder
/tmp
/dist
.env*
!.env.example
/result*

# Logs
logs
Expand Down Expand Up @@ -81,6 +77,3 @@ typings/

# Serverless directories
.serverless

# Temporary files
tmp/
35 changes: 12 additions & 23 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ variables:
stages:
- check
- build
- deploy

image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner

lint:
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
stage: check
script:
- >
Expand All @@ -16,38 +16,27 @@ lint:
npm run lint;
'
test-npm:
image: node:12
test:
stage: check
script:
- npm install
- npm run build:all
- npm run test
- >
nix-shell -I nixpkgs=./pkgs.nix --packages nodejs --run '
npm install;
npm run test;
'
nix-dry:
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
stage: check
script:
- nix-build -v -v --dry-run ./release.nix --attr application
- nix-build -v -v --dry-run ./release.nix --attr docker

nix:
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
stage: build
script:
- >
nix-build ./release.nix
--attr application
--attr docker
# TODO: get this deploy phase working
deploy_npm:
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
stage: deploy
nix-build ./release.nix
--attr application
--attr docker
only:
- tags
- triggers
script:
- nix-shell --packages nodejs --run "npm install"
- npm run build:all
# - npm publish
- master
8 changes: 3 additions & 5 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
.env
.*
/pkgs.nix
/default.nix
/shell.nix
/webpack.config.js
/release.nix
/tsconfig.json
/doc
/src
/test
/log
/tests
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"printWidth": 80,
"tabWidth": 2
}
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,37 @@ All `.proto` files are stored in the the `proto` directory. JavaScript and type
```
npm run build:proto
```

---

```
protoc \
--proto_path=src/proto/schemas \
--plugin=protoc-gen-grpc="$(which grpc_node_plugin)" \
--js_out=import_style=commonjs,binary:src/proto/js \
--ts_out="src/proto/js" \
--grpc_out=grpc_js:src/proto/js \
./src/proto/schemas/*.proto
```

or

```
protoc \
--proto_path=src/proto/schemas \
--plugin=protoc-gen-grpc="$(which grpc_node_plugin)" \
--js_out=import_style=commonjs,binary:src/proto/js \
--grpc_out=grpc_js:src/proto/js \
./src/proto/schemas/*.proto
```

Once we have grpc-tools packaged properly.

```
# builds the dependency graph
arkit ./src -o ./media/dependencies.png
typedoc --media ./media
```

Other build instructions above ^.
8 changes: 0 additions & 8 deletions bin/polykey

This file was deleted.

56 changes: 51 additions & 5 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,54 @@
{ pkgs, nix-gitignore }:
{ runCommandNoCC
, nix-gitignore
, nodejs
, nodePackages
, pkgs
, lib
}:

let
drv = (import ./nix/generated/node-composition.nix { inherit pkgs; }).package;
src = nix-gitignore.gitignoreSource [".git"] ./.;
nodeVersion = builtins.elemAt (lib.versions.splitVersion nodejs.version) 0;
node2nixDrv = dev: runCommandNoCC "node2nix" {} ''
mkdir $out
${nodePackages.node2nix}/bin/node2nix \
${lib.optionalString dev "--development"} \
--input ${src}/package.json \
--lock ${src}/package-lock.json \
--node-env $out/node-env.nix \
--output $out/node-packages.nix \
--composition $out/default.nix \
--nodejs-${nodeVersion}
'';
devPackage = (import (node2nixDrv true) { inherit pkgs nodejs; }).package;
prodDeps = (
(import (node2nixDrv false) { inherit pkgs nodejs; }).shell.override {
dontNpmInstall = true;
}
).nodeDependencies;
drv = devPackage.overrideAttrs (attrs: {
src = src;
dontNpmInstall = true;
postInstall = ''
# The dependencies were prepared in the install phase
# See `node2nix` generated `node-env.nix` for details.
npm run build
# This call does not actually install packages. The dependencies
# are present in `node_modules` already. It creates symlinks in
# $out/lib/node_modules/.bin according to `bin` section in `package.json`.
npm install
# replace dev dependencies
rm -rf $out/lib/node_modules/${attrs.packageName}/node_modules
cp -r ${prodDeps}/lib/node_modules $out/lib/node_modules/${attrs.packageName}/
# Create symlink to the deployed executable folder, if applicable
if [ -d "$out/lib/node_modules/.bin" ]
then
ln -s $out/lib/node_modules/.bin $out/bin
fi
'';
});
in
drv.overrideAttrs (attrs: {
src = nix-gitignore.gitignoreSource [] attrs.src;
})
drv
15 changes: 14 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');

module.exports = {
"verbose": true,
"roots": [
"<rootDir>/tests"
],
Expand All @@ -7,5 +11,14 @@ module.exports = {
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
}
},
setupFiles: [
"<rootDir>/tests/setup.ts"
],
globalSetup: "<rootDir>/tests/globalSetup.ts",
globalTeardown: "<rootDir>/tests/globalTeardown.ts",
moduleNameMapper: pathsToModuleNameMapper(
compilerOptions.paths,
{ prefix: "<rootDir>/src/" }
)
};
48 changes: 0 additions & 48 deletions nix/default.nix

This file was deleted.

17 changes: 0 additions & 17 deletions nix/generated/node-composition.nix

This file was deleted.

Loading

0 comments on commit c2c13a2

Please sign in to comment.