Skip to content

Commit

Permalink
Merge pull request #115 from casanet/development
Browse files Browse the repository at this point in the history
Fix packaging to match 'arm' machines
  • Loading branch information
haimkastner authored Mar 1, 2020
2 parents 2b04007 + db87e17 commit 1df21f0
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 3,322 deletions.
3,549 changes: 249 additions & 3,300 deletions backend/package-lock.json

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,34 @@
},
"scripts": {
"version": "node ./scripts/buildVersion.js",
"bundle": "cd ../frontend && npm run build:internal && cd ../backend && npm run build && copyfiles package.json dist && copyfiles .env.example casanet.json bundle && cd dist && pkg . --out-path ../bundle",
"pack:arm": "pkg . -t node12-linux-armv7 --no-bytecode --output ../bundle/casanet_linux_arm",
"pack:win64": "pkg . -t node12-win-x64 --output ../bundle/casanet_win_x64.exe",
"pack:lin64": "pkg . -t node12-linux-x64 --output ../bundle/casanet_linux_x64",
"pack:mac64": "pkg . -t node12-macos-x64 --output ../bundle/casanet_macos_x64",
"pack": "cd dist && npm run pack:arm && npm run pack:win64 && npm run pack:lin64 && npm run pack:mac64",
"prepack": "node ./scripts/fixPkgLicence.js && copyfiles package.json dist && copyfiles .env.example casanet.json bundle",
"bundle": "npm run build:front && npm run build && npm run prepack && npm run pack",
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
"lint": "tslint -p tsconfig.json",
"lint:fix": "tslint --fix -p tsconfig.json",
"jscopy": "copyfiles -u 1 src/**/*.js dist",
"build": "tsoa routes && tsoa swagger && tsc && npm run jscopy && npm run version",
"serve": "npm run build && node dist/index.js",
"build:prod": "npm run format && npm run lint && npm run build",
"build:front": "cd ../frontend && npm run build:internal && cd ../backend",
"test:unit": "del-cli data/test -f && npm run build && cross-env NODE_ENV=test mocha --exit --require ts-node/register tests/unit/**/*.spec.ts",
"test:e2e": "del-cli data/test -f && npm run build && cross-env NODE_ENV=test mocha --exit --require ts-node/register tests/e2e/**/*.spec.ts",
"test": "del-cli data/test -f && npm run build && cross-env NODE_ENV=test mocha --exit --require ts-node/register tests/**/*.spec.ts",
"cover": "node \"node_modules/nyc/bin/nyc.js\" --reporter=lcov npm run test"
},
"license": "GNU",
"license": "ISC",
"dependencies": {
"async-mqtt": "^2.3.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"check-internet-connected": "^2.0.4",
"child-process-promise": "^2.2.1",
"cookie-parser": "^1.4.4",
"crypto-js": "^3.1.9-1",
Expand All @@ -51,9 +59,7 @@
"helmet": "^3.20.0",
"http": "0.0.0",
"https": "^1.0.0",
"i": "^0.3.6",
"ip": "^1.1.5",
"is-online": "^8.2.0",
"joi": "^14.3.0",
"log4js": "^3.0.6",
"macaddress": "^0.2.9",
Expand All @@ -64,7 +70,6 @@
"node-orvibo-2": "^1.1.5",
"node-yeelight-wifi": "^0.1.2",
"nodemailer": "^5.1.1",
"npm": "^6.13.7",
"path": "^0.12.7",
"promise-with-timeout": "^1.0.1",
"pull-behavior": "^1.1.0",
Expand Down Expand Up @@ -104,13 +109,13 @@
"del-cli": "^1.1.0",
"mocha": "^6.1.4",
"nyc": "^15.0.0",
"pkg": "^4.4.3",
"prettier": "^1.19.1",
"simple-git": "^1.121.0",
"pkg": "^4.4.3",
"ts-node": "^7.0.1",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.8.2",
"simple-git": "^1.121.0",
"ws": "^6.2.1"
}
}
29 changes: 29 additions & 0 deletions backend/scripts/fixPkgLicence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const fse = require('fs-extra');
const path = require('path');

const fixModulesLicenceSection = async modulesPath => {
try {
const nodeModulesDirs = await fse.promises.readdir(modulesPath);

const dirs = [...nodeModulesDirs];
for (const dir of dirs) {
try {
const packagePath = path.join(modulesPath, dir, 'package.json');
const package = await fse.readJSON(packagePath);
if (package.license) {
continue;
}
package.license = 'ISC';
fse.writeJSON(packagePath, package);
console.log(`package '${packagePath}' fixed`);
} catch (error) {}
}
} catch (error) {}
};

const fixProjectModules = async () => {
await fixModulesLicenceSection('node_modules');
await fixModulesLicenceSection(path.join('node_modules', 'npm', 'node_modules'));
};

fixProjectModules();
8 changes: 4 additions & 4 deletions backend/src/business-layer/versionsBl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { logger } from '../utilities/logger';
export class VersionsBl {
private updateStatus: ProgressStatus = 'finished';

constructor() {
}
constructor() {}

/**
* Update CASA-net application to the latest version.
Expand Down Expand Up @@ -98,13 +97,14 @@ export class VersionsBl {
osExtension = 'macos';
break;
case 'win32':
osExtension = 'win.exe';
osExtension = 'win';
break;
case 'linux':
osExtension = 'linux';
break;
}
return `casanet-local-server-${osExtension}`;

return `casanet_${osExtension}_${process.arch}${process.platform === 'win32' ? '.exe' : ''}`;
}

private async downloadNewVersion(newVersion: string) {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Config, RunningMode } from './models/backendInterfaces';
import { logger } from './utilities/logger';

// load environment variable from .env file
if (existsSync('.env')) {
if (existsSync('./.env')) {
dotenv.config();
}

Expand All @@ -28,7 +28,7 @@ const rawSubnetToScan = process.env.SUBNET_TO_SCAN;
*/
let configuration: Config;
try {
configuration = fse.readJSONSync('casanet.json');
configuration = fse.readJSONSync('./casanet.json');
} catch (error) {
logger.error('Fail to read casanet.json configuration file. exit...');
process.exit();
Expand Down
6 changes: 3 additions & 3 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ http.createServer(app).listen(Configuration.http.httpPort, () => {
// SSL/HTTPS
if (Configuration.http.useHttps) {
try {
const key = fs.readFileSync(path.join(__dirname, '/../encryption/private.key'));
const cert = fs.readFileSync(path.join(__dirname, '/../encryption/certificate.crt'));
const ca = fs.readFileSync(path.join(__dirname, '/../encryption/ca_bundle.crt'));
const key = fs.readFileSync('./encryption/private.key');
const cert = fs.readFileSync('./encryption/certificate.crt');
const ca = fs.readFileSync('./encryption/ca_bundle.crt');

const sslOptions: https.ServerOptions = {
key,
Expand Down
6 changes: 3 additions & 3 deletions backend/src/utilities/lanManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as checkInternetConnected from 'check-internet-connected';
import * as ip from 'ip';
import * as isOnline from 'is-online';
import * as networkList2 from 'network-list2';
import { Configuration } from '../config';
import { LocalNetworkDevice } from '../models/sharedInterfaces';
Expand All @@ -14,8 +14,8 @@ export const LocalNetworkReader = (): Promise<LocalNetworkDevice[]> => {
return new Promise(async (resolve, reject) => {
const ops: { ip?: string; vendor?: boolean } = {};

/** Ceck if internet connection is online, otherways dont try to get vendor name. */
const isInternetOnline = await isOnline();
/** Check if internet connection is online, otherwise don't try to get vendor name. */
const isInternetOnline = await checkInternetConnected();

if (Configuration.scanSubnet) {
ops.ip = Configuration.scanSubnet;
Expand Down
2 changes: 1 addition & 1 deletion backend/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ info:
version: 2.0.0
description: 'IoT server for local home network. hosted in [GitHub repo](https://github.com/casanet/casanet-server).'
license:
name: GNU
name: ISC
paths:
'/auth/logout-sessions/{userId}':
post:
Expand Down
4 changes: 2 additions & 2 deletions docs/LINUX.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Then
### Connect to the new window
```tmux a -t casanet```
### Get the server
- Download the linux binary execution (`casanet-local-server-linux` file) from [here](https://github.com/casanet/casanet-server/releases)
- Download the arm linux binary execution (`casanet_linux_arm` file) from [here](https://github.com/casanet/casanet-server/releases)
- Download the `casanet.json` configuration file from [here](https://github.com/casanet/casanet-server/releases)
- Download the environments example file from [here](https://github.com/casanet/casanet-server/releases)
- Give `casanet-local-server-linux` file an execute permission (using `chmod -R 0777 ./casanet-local-server-linux`)
Expand Down Expand Up @@ -80,7 +80,7 @@ case "$1" in
tmux kill-session -t "casanet"
tmux new -s "casanet" -d
tmux send-keys -t "casanet" "cd /root" C-m m # Or the "./casanet-server/backend" if you use the source-code
tmux send-keys -t "casanet" "sudo node ./casanet-local-server-linux" C-m # Or the "./dist/index.js" if you use the source-code
tmux send-keys -t "casanet" "sudo ./casanet_linux_arm" C-m # Or the "node ./dist/index.js" if you use the source-code
;;
'stop')
killall node
Expand Down

0 comments on commit 1df21f0

Please sign in to comment.