From 6d70e5f1b1c59986ba6aa29ccdeece52744cd89b Mon Sep 17 00:00:00 2001 From: maksimchepelev Date: Fri, 30 Nov 2018 17:18:45 +0300 Subject: [PATCH 1/2] EWC-379 cross-platform npm scripts postinstall hasn't finished yet. there is no version migrations in it --- package.json | 186 ++++++++++++++++++++-------------------- scripts/coverage.js | 24 ++++++ scripts/init.js | 24 ++++++ scripts/postinstall.js | 47 ++++++++++ scripts/postinstall.sh | 2 + scripts/preinstall.sh | 18 ---- scripts/preuninstall.js | 47 ++++++++++ scripts/preuninstall.sh | 18 ---- scripts/start-dev.js | 24 ++++++ scripts/start.js | 24 ++++++ scripts/test.js | 24 ++++++ 11 files changed, 310 insertions(+), 128 deletions(-) create mode 100644 scripts/coverage.js create mode 100644 scripts/init.js create mode 100644 scripts/postinstall.js delete mode 100644 scripts/preinstall.sh create mode 100644 scripts/preuninstall.js delete mode 100644 scripts/preuninstall.sh create mode 100644 scripts/start-dev.js create mode 100644 scripts/start.js create mode 100644 scripts/test.js diff --git a/package.json b/package.json index 921f717cb..0e292c97f 100644 --- a/package.json +++ b/package.json @@ -1,94 +1,96 @@ { - "name": "iofogcontroller", - "version": "1.0.24", - "description": "ioFog Controller project for Eclipse IoFog @ iofog.org \\nCopyright (c) 2018 Edgeworx, Inc.", - "main": "./src/main.js", - "author": "Saeid Baghbidi", - "contributors": [ - "Kilton Hopkins ", - "Saeid Baghbidi", - "Pavel Kazlou", - "Egor Krylovich", - "Iryna Laryionava", - "Maryna Lipnitskaya", - "Dmitriy Kudasov", - "Dmitry Stolbunov", - "Darya Busel", - "Alexander Shpak", - "Kate Lukashick", - "Eugene Pankov", - "Maksim Chepelev", - "Tetiana Yatsiuk", - "Sergey Valevich" - ], - "license": { - "type": "EPL-2.0", - "url": "https://www.eclipse.org/legal/epl-v20.html" - }, - "bugs": { - "email": "edgemaster@iofog.org" - }, - "homepage": "https://www.iofog.org", - "repository": { - "type": "git", - "url": "https://github.com/ioFog/Controller" - }, - "scripts": { - "start": "NODE_ENV=production node ./src/main.js start", - "start-dev": "NODE_ENV=development node ./src/main.js start", - "build": "export NODE_ENV=production && cd src/sequelize && ../../node_modules/.bin/sequelize db:migrate && ../../node_modules/.bin/sequelize db:seed:all", - "preuninstall": "bash scripts/preuninstall.sh", - "postinstall": "bash scripts/postinstall.sh && NODE_ENV=production node ./src/main.js init", - "lint": "./node_modules/.bin/eslint \"**/*.js\"", - "automatic-release": "automatic-release", - "test": "NODE_ENV=test mocha", - "coverage": "NODE_ENV=test nyc mocha" - }, - "preferGlobal": true, - "bin": { - "iofog-controller": "src/main.js" - }, - "dependencies": { - "body-parser": "^1.18.3", - "command-line-args": "^5.0.2", - "command-line-usage": "^5.0.5", - "continuation-local-storage": "^3.2.1", - "cookie-parser": "^1.4.3", - "daemonize2": "^0.4.2", - "ejs": "^2.6.1", - "express": "^4.16.3", - "formidable": "^1.2.1", - "fs": "^0.0.1-security", - "ftp": "^0.3.10", - "helmet": "^3.13.0", - "jsonschema": "^1.2.4", - "morgan": "^1.9.1", - "nconf": "^0.10.0", - "nodemailer": "^4.6.8", - "nodemailer-smtp-transport": "^2.7.4", - "path": "^0.12.7", - "portscanner": "^2.2.0", - "retry-as-promised": "^3.1.0", - "sequelize": "^4.39.0", - "sequelize-cli": "^4.1.1", - "sqlite3": "^4.0.2", - "string-format": "^2.0.0", - "umzug": "^2.1.0", - "underscore": "^1.9.1", - "winston": "^3.1.0", - "xss-clean": "^0.1.1", - "qs": "^6.5.2" - }, - "devDependencies": { - "automatic-release": "^1.1.1", - "bdd-lazy-var": "^2.5.0", - "chai": "^4.2.0", - "chai-as-promised": "^7.1.1", - "chai-http": "^4.2.0", - "eslint": "^5.6.1", - "mocha": "^5.2.0", - "nyc": "^13.1.0", - "sinon": "^7.1.1", - "sinon-chai": "^3.2.0" - } + "name": "iofogcontroller", + "version": "1.0.24", + "description": "ioFog Controller project for Eclipse IoFog @ iofog.org \\nCopyright (c) 2018 Edgeworx, Inc.", + "main": "./src/main.js", + "author": "Saeid Baghbidi", + "contributors": [ + "Kilton Hopkins ", + "Saeid Baghbidi", + "Pavel Kazlou", + "Egor Krylovich", + "Iryna Laryionava", + "Maryna Lipnitskaya", + "Dmitriy Kudasov", + "Dmitry Stolbunov", + "Darya Busel", + "Alexander Shpak", + "Kate Lukashick", + "Eugene Pankov", + "Maksim Chepelev", + "Tetiana Yatsiuk", + "Sergey Valevich" + ], + "license": { + "type": "EPL-2.0", + "url": "https://www.eclipse.org/legal/epl-v20.html" + }, + "bugs": { + "email": "edgemaster@iofog.org" + }, + "homepage": "https://www.iofog.org", + "repository": { + "type": "git", + "url": "https://github.com/ioFog/Controller" + }, + "scripts": { + "start": "node scripts/start.js", + "start-dev": "node scripts/start-dev.js", + "build": "node scripts/init.js", + "preuninstall": "node scripts/preuninstall.js", + "postinstall": "node scripts/postinstall.js", + "lint": "./node_modules/.bin/eslint \"**/*.js\"", + "automatic-release": "automatic-release", + "test": "node scripts/test.js", + "coverage": "node scripts/coverage.js" + }, + "preferGlobal": true, + "bin": { + "iofog-controller": "src/main.js" + }, + "dependencies": { + "body-parser": "^1.18.3", + "command-line-args": "^5.0.2", + "command-line-usage": "^5.0.5", + "continuation-local-storage": "^3.2.1", + "cookie-parser": "^1.4.3", + "daemonize2": "^0.4.2", + "ejs": "^2.6.1", + "express": "^4.16.3", + "formidable": "^1.2.1", + "fs": "^0.0.1-security", + "ftp": "^0.3.10", + "helmet": "^3.13.0", + "jsonschema": "^1.2.4", + "morgan": "^1.9.1", + "nconf": "^0.10.0", + "nodemailer": "^4.6.8", + "nodemailer-smtp-transport": "^2.7.4", + "path": "^0.12.7", + "portscanner": "^2.2.0", + "retry-as-promised": "^3.1.0", + "sequelize": "^4.39.0", + "sequelize-cli": "^4.1.1", + "sqlite3": "^4.0.2", + "string-format": "^2.0.0", + "umzug": "^2.1.0", + "underscore": "^1.9.1", + "winston": "^3.1.0", + "xss-clean": "^0.1.1", + "qs": "^6.5.2", + "child_process": "^1.0.2", + "os": "^0.1.1" + }, + "devDependencies": { + "automatic-release": "^1.1.1", + "bdd-lazy-var": "^2.5.0", + "chai": "^4.2.0", + "chai-as-promised": "^7.1.1", + "chai-http": "^4.2.0", + "eslint": "^5.6.1", + "mocha": "^5.2.0", + "nyc": "^13.1.0", + "sinon": "^7.1.1", + "sinon-chai": "^3.2.0" + } } diff --git a/scripts/coverage.js b/scripts/coverage.js new file mode 100644 index 000000000..fc23b0ecd --- /dev/null +++ b/scripts/coverage.js @@ -0,0 +1,24 @@ +/* + * ******************************************************************************* + * * Copyright (c) 2018 Edgeworx, Inc. + * * + * * This program and the accompanying materials are made available under the + * * terms of the Eclipse Public License v. 2.0 which is available at + * * http://www.eclipse.org/legal/epl-2.0 + * * + * * SPDX-License-Identifier: EPL-2.0 + * ******************************************************************************* + * + */ + +const execSync = require('child_process').execSync; + +const options = { + env: { + 'NODE_ENV': 'test', + "PATH": process.env.PATH + }, + stdio: [process.stdin, process.stdout, process.stderr] +}; + +execSync('nyc mocha', options); \ No newline at end of file diff --git a/scripts/init.js b/scripts/init.js new file mode 100644 index 000000000..2c1ee958a --- /dev/null +++ b/scripts/init.js @@ -0,0 +1,24 @@ +/* + * ******************************************************************************* + * * Copyright (c) 2018 Edgeworx, Inc. + * * + * * This program and the accompanying materials are made available under the + * * terms of the Eclipse Public License v. 2.0 which is available at + * * http://www.eclipse.org/legal/epl-2.0 + * * + * * SPDX-License-Identifier: EPL-2.0 + * ******************************************************************************* + * + */ + +const execSync = require('child_process').execSync; + +const options = { + env: { + 'NODE_ENV': 'production', + "PATH": process.env.PATH + }, + stdio: [process.stdin, process.stdout, process.stderr] +}; + +execSync('node ./src/main.js init', options); \ No newline at end of file diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100644 index 000000000..004a26b0e --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,47 @@ +/* + * ******************************************************************************* + * * Copyright (c) 2018 Edgeworx, Inc. + * * + * * This program and the accompanying materials are made available under the + * * terms of the Eclipse Public License v. 2.0 which is available at + * * http://www.eclipse.org/legal/epl-2.0 + * * + * * SPDX-License-Identifier: EPL-2.0 + * ******************************************************************************* + * + */ + + +const os = require('os'); +const execSync = require('child_process').execSync; +const fs = require('fs'); + +const rootDir = `${__dirname}/../`; +let installation_variables_file_name = 'iofogcontroller_install_variables'; +let installation_variables_file; +let tempDir; + +if (os.type() === 'Linux') { + tempDir = '/tmp/'; +} else if (os.type() === 'Darwin') { + tempDir = '/tmp/'; +} else if (os.type() === 'Windows_NT') { + tempDir = process.env.APPDATA; +} else { + throw new Error("Unsupported OS found: " + os.type()); +} + +installation_variables_file = tempDir + installation_variables_file_name; + + +const devDbBackup = `${tempDir}dev_database.sqlite`; +if (fs.existsSync(devDbBackup)) { + fs.renameSync(devDbBackup, `${rootDir}/src/sequelize/dev_database.sqlite`) +} + +const prodDbBackup = `${tempDir}prod_database.sqlite`; +if (fs.existsSync(prodDbBackup)) { + fs.renameSync(prodDbBackup, `${rootDir}/src/sequelize/prod_database.sqlite`) +} + +//TODO: add version migrations diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh index c2883c62d..c0d4e8555 100644 --- a/scripts/postinstall.sh +++ b/scripts/postinstall.sh @@ -1,5 +1,7 @@ #!/bin/bash +##TODO: remove after js scripts finished + vercomp () { if [[ $1 == $2 ]] then diff --git a/scripts/preinstall.sh b/scripts/preinstall.sh deleted file mode 100644 index 06e305749..000000000 --- a/scripts/preinstall.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -#store prev ver number -export PREV_IOFOG_CONTROLLER_VER=$(npm list --depth=0 -g --silent | grep iofogcontroller | awk -F "@" '{print $2}') -printf 'prev_ver: '$PREV_IOFOG_CONTROLLER_VER > /tmp/iofogcontroller_install_variables - -#backup db -IOFOG_CONTROLLER_NODE_MODULES=$(npm root -g iofog-controller) -IOFOG_CONTROLLER_SEQUELIZE_DIR=$IOFOG_CONTROLLER_NODE_MODULES'/iofogcontroller/src/sequelize' - -DEV_DB_FILE=$IOFOG_CONTROLLER_SEQUELIZE_DIR'/dev_database.sqlite' -if [ -f $DEV_DB_FILE ]; then - mv $DEV_DB_FILE /tmp/ -fi -PROD_DB_FILE=$IOFOG_CONTROLLER_SEQUELIZE_DIR'/prod_database.sqlite' -if [ -f $PROD_DB_FILE ]; then - mv $PROD_DB_FILE /tmp/ -fi \ No newline at end of file diff --git a/scripts/preuninstall.js b/scripts/preuninstall.js new file mode 100644 index 000000000..26c86eded --- /dev/null +++ b/scripts/preuninstall.js @@ -0,0 +1,47 @@ +/* + * ******************************************************************************* + * * Copyright (c) 2018 Edgeworx, Inc. + * * + * * This program and the accompanying materials are made available under the + * * terms of the Eclipse Public License v. 2.0 which is available at + * * http://www.eclipse.org/legal/epl-2.0 + * * + * * SPDX-License-Identifier: EPL-2.0 + * ******************************************************************************* + * + */ + +const os = require('os'); +const execSync = require('child_process').execSync; +const fs = require('fs'); +const version = require('../package').version; + +const rootDir = `${__dirname}/../`; +let installation_variables_file_name = 'iofogcontroller_install_variables'; +let installation_variables_file; +let tempDir; + +if (os.type() === 'Linux') { + tempDir = '/tmp/'; +} else if (os.type() === 'Darwin') { + tempDir = '/tmp/'; +} else if (os.type() === 'Windows_NT') { + tempDir = process.env.APPDATA; +} else { + throw new Error("Unsupported OS found: " + os.type()); +} + +installation_variables_file = tempDir + installation_variables_file_name; + +fs.writeFileSync(installation_variables_file, `prev_ver: ${version}`); + +const devDb = `${rootDir}/src/sequelize/dev_database.sqlite`; +if (fs.existsSync(devDb)) { + fs.renameSync(devDb, `${tempDir}dev_database.sqlite`) +} + +const prodDb = `${rootDir}/src/sequelize/prod_database.sqlite`; +if (fs.existsSync(prodDb)) { + fs.renameSync(prodDb, `${tempDir}prod_database.sqlite`) +} + diff --git a/scripts/preuninstall.sh b/scripts/preuninstall.sh deleted file mode 100644 index 06e305749..000000000 --- a/scripts/preuninstall.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -#store prev ver number -export PREV_IOFOG_CONTROLLER_VER=$(npm list --depth=0 -g --silent | grep iofogcontroller | awk -F "@" '{print $2}') -printf 'prev_ver: '$PREV_IOFOG_CONTROLLER_VER > /tmp/iofogcontroller_install_variables - -#backup db -IOFOG_CONTROLLER_NODE_MODULES=$(npm root -g iofog-controller) -IOFOG_CONTROLLER_SEQUELIZE_DIR=$IOFOG_CONTROLLER_NODE_MODULES'/iofogcontroller/src/sequelize' - -DEV_DB_FILE=$IOFOG_CONTROLLER_SEQUELIZE_DIR'/dev_database.sqlite' -if [ -f $DEV_DB_FILE ]; then - mv $DEV_DB_FILE /tmp/ -fi -PROD_DB_FILE=$IOFOG_CONTROLLER_SEQUELIZE_DIR'/prod_database.sqlite' -if [ -f $PROD_DB_FILE ]; then - mv $PROD_DB_FILE /tmp/ -fi \ No newline at end of file diff --git a/scripts/start-dev.js b/scripts/start-dev.js new file mode 100644 index 000000000..709f4d371 --- /dev/null +++ b/scripts/start-dev.js @@ -0,0 +1,24 @@ +/* + * ******************************************************************************* + * * Copyright (c) 2018 Edgeworx, Inc. + * * + * * This program and the accompanying materials are made available under the + * * terms of the Eclipse Public License v. 2.0 which is available at + * * http://www.eclipse.org/legal/epl-2.0 + * * + * * SPDX-License-Identifier: EPL-2.0 + * ******************************************************************************* + * + */ + +const execSync = require('child_process').execSync; + +const options = { + env: { + 'NODE_ENV': 'development', + "PATH": process.env.PATH + }, + stdio: [process.stdin, process.stdout, process.stderr] +}; + +execSync('node ./src/main.js start', options); \ No newline at end of file diff --git a/scripts/start.js b/scripts/start.js new file mode 100644 index 000000000..f8f2f1f3f --- /dev/null +++ b/scripts/start.js @@ -0,0 +1,24 @@ +/* + * ******************************************************************************* + * * Copyright (c) 2018 Edgeworx, Inc. + * * + * * This program and the accompanying materials are made available under the + * * terms of the Eclipse Public License v. 2.0 which is available at + * * http://www.eclipse.org/legal/epl-2.0 + * * + * * SPDX-License-Identifier: EPL-2.0 + * ******************************************************************************* + * + */ + +const execSync = require('child_process').execSync; + +const options = { + env: { + 'NODE_ENV': 'production', + "PATH": process.env.PATH + }, + stdio: [process.stdin, process.stdout, process.stderr] +}; + +execSync('node ./src/main.js start', options); \ No newline at end of file diff --git a/scripts/test.js b/scripts/test.js new file mode 100644 index 000000000..fc27d1aac --- /dev/null +++ b/scripts/test.js @@ -0,0 +1,24 @@ +/* + * ******************************************************************************* + * * Copyright (c) 2018 Edgeworx, Inc. + * * + * * This program and the accompanying materials are made available under the + * * terms of the Eclipse Public License v. 2.0 which is available at + * * http://www.eclipse.org/legal/epl-2.0 + * * + * * SPDX-License-Identifier: EPL-2.0 + * ******************************************************************************* + * + */ + +const execSync = require('child_process').execSync; + +const options = { + env: { + 'NODE_ENV': 'test', + "PATH": process.env.PATH + }, + stdio: [process.stdin, process.stdout, process.stderr] +}; + +execSync('mocha', options); \ No newline at end of file From 57072c71c99853076ce3126ac41fa3f246f1f7b4 Mon Sep 17 00:00:00 2001 From: maksimchepelev Date: Fri, 30 Nov 2018 17:44:21 +0300 Subject: [PATCH 2/2] EWC-379 windows path fix --- scripts/postinstall.js | 2 +- scripts/preuninstall.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 004a26b0e..58d051a50 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -26,7 +26,7 @@ if (os.type() === 'Linux') { } else if (os.type() === 'Darwin') { tempDir = '/tmp/'; } else if (os.type() === 'Windows_NT') { - tempDir = process.env.APPDATA; + tempDir = `${process.env.APPDATA}/`; } else { throw new Error("Unsupported OS found: " + os.type()); } diff --git a/scripts/preuninstall.js b/scripts/preuninstall.js index 26c86eded..0cec350a3 100644 --- a/scripts/preuninstall.js +++ b/scripts/preuninstall.js @@ -26,7 +26,7 @@ if (os.type() === 'Linux') { } else if (os.type() === 'Darwin') { tempDir = '/tmp/'; } else if (os.type() === 'Windows_NT') { - tempDir = process.env.APPDATA; + tempDir = `${process.env.APPDATA}/`; } else { throw new Error("Unsupported OS found: " + os.type()); }