From 7268d8af72f82696de141f4d85301f7b19acc009 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Thu, 26 Sep 2019 21:17:39 +0200 Subject: [PATCH] cli --- old-packages/insights-server/package.json | 49 ------------- old-packages/insights-server/yarn.lock | 69 ------------------- .../insights-cli}/app/createsuperuser.js | 4 +- .../insights-cli}/app/index.js | 0 packages/insights-cli/bin/insights | 5 +- .../insights-cli}/bin/insights-createsecret | 12 +++- .../bin/insights-createsuperuser | 2 +- .../insights-cli/bin/insights-start | 0 packages/insights-cli/lib/random-string.js | 9 +++ packages/insights-cli/package.json | 9 ++- 10 files changed, 31 insertions(+), 128 deletions(-) delete mode 100644 old-packages/insights-server/package.json delete mode 100644 old-packages/insights-server/yarn.lock rename {old-packages/insights-server => packages/insights-cli}/app/createsuperuser.js (93%) rename {old-packages/insights-server => packages/insights-cli}/app/index.js (100%) rename {old-packages/insights-server => packages/insights-cli}/bin/insights-createsecret (71%) rename {old-packages/insights-server => packages/insights-cli}/bin/insights-createsuperuser (94%) rename old-packages/insights-server/bin/insights-server => packages/insights-cli/bin/insights-start (100%) create mode 100644 packages/insights-cli/lib/random-string.js diff --git a/old-packages/insights-server/package.json b/old-packages/insights-server/package.json deleted file mode 100644 index 8d8444f2..00000000 --- a/old-packages/insights-server/package.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "name": "insights-server", - "description": "Desktop and Self-Hosted \"SQL-not-required\" data analytics and visualisation tool.", - "version": "0.0.31", - "homepage": "", - "main": "app", - "license": "MIT", - "keywords": [ - "feathers", - "insights" - ], - "author": { - "name": "Marius Andra", - "email": "marius.andra@gmail.com" - }, - "contributors": [], - "repository": "mariusandra/insights", - "bugs": {}, - "directories": { - "lib": "app" - }, - "engines": { - "node": ">= 7.6.0", - "yarn": ">= 0.18.0" - }, - "scripts": { - "start": "NODE_ENV=development node --inspect app/", - "createsuperuser:dev": "NODE_ENV=development node app/createsuperuser.js", - "createsuperuser": "NODE_ENV=production node app/createsuperuser.js", - "production": "NODE_ENV=production node app/" - }, - "bin": { - "insights-server": "./bin/insights-server", - "insights-createsecret": "./bin/insights-createsecret", - "insights-createsuperuser": "./bin/insights-createsuperuser" - }, - "files": [ - "app", - "bin" - ], - "peerDependencies": { - "insights-core": "*" - }, - "dependencies": { - "commander": "^2.10.0", - "prompt-promise": "1.0.3", - "winston": "2.3.1" - } -} diff --git a/old-packages/insights-server/yarn.lock b/old-packages/insights-server/yarn.lock deleted file mode 100644 index b096f63e..00000000 --- a/old-packages/insights-server/yarn.lock +++ /dev/null @@ -1,69 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -async@~1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/async/-/async-1.0.0.tgz#f8fc04ca3a13784ade9e1641af98578cfbd647a9" - -colors@1.0.x: - version "1.0.3" - resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" - -commander@^2.10.0: - version "2.10.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.10.0.tgz#e1f5d3245de246d1a5ca04702fa1ad1bd7e405fe" - dependencies: - graceful-readlink ">= 1.0.0" - -cycle@1.0.x: - version "1.0.3" - resolved "https://registry.yarnpkg.com/cycle/-/cycle-1.0.3.tgz#21e80b2be8580f98b468f379430662b046c34ad2" - -eyes@0.1.x: - version "0.1.8" - resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0" - -"graceful-readlink@>= 1.0.0": - version "1.0.1" - resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" - -isstream@0.1.x: - version "0.1.2" - resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" - -keypress@~0.2.1: - version "0.2.1" - resolved "https://registry.yarnpkg.com/keypress/-/keypress-0.2.1.tgz#1e80454250018dbad4c3fe94497d6e67b6269c77" - -native-or-another@~2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/native-or-another/-/native-or-another-2.0.0.tgz#17a567f92beea9cd71acff96a7681a735eca3bff" - dependencies: - native-or-bluebird "^1.1.2" - -native-or-bluebird@^1.1.2: - version "1.2.0" - resolved "https://registry.yarnpkg.com/native-or-bluebird/-/native-or-bluebird-1.2.0.tgz#39c47bfd7825d1fb9ffad32210ae25daadf101c9" - -prompt-promise@1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/prompt-promise/-/prompt-promise-1.0.3.tgz#78ce4fcb9a14a108c49174f2d808c440d1bde265" - dependencies: - keypress "~0.2.1" - native-or-another "~2.0.0" - -stack-trace@0.0.x: - version "0.0.10" - resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0" - -winston@2.3.1: - version "2.3.1" - resolved "https://registry.yarnpkg.com/winston/-/winston-2.3.1.tgz#0b48420d978c01804cf0230b648861598225a119" - dependencies: - async "~1.0.0" - colors "1.0.x" - cycle "1.0.x" - eyes "0.1.x" - isstream "0.1.x" - stack-trace "0.0.x" diff --git a/old-packages/insights-server/app/createsuperuser.js b/packages/insights-cli/app/createsuperuser.js similarity index 93% rename from old-packages/insights-server/app/createsuperuser.js rename to packages/insights-cli/app/createsuperuser.js index 04bc725d..d2d87b81 100644 --- a/old-packages/insights-server/app/createsuperuser.js +++ b/packages/insights-cli/app/createsuperuser.js @@ -2,9 +2,9 @@ // - INSIGHTS_SUPERUSER_EMAIL // - INSIGHTS_SUPERUSER_PASSWORD -const app = require('insights-core/src') +const app = require('insights-api/src') const prompt = require('prompt-promise') -const randomString = require('insights-core/src/lib/random-string') +const randomString = require('../lib/random-string') const azAZ09 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' diff --git a/old-packages/insights-server/app/index.js b/packages/insights-cli/app/index.js similarity index 100% rename from old-packages/insights-server/app/index.js rename to packages/insights-cli/app/index.js diff --git a/packages/insights-cli/bin/insights b/packages/insights-cli/bin/insights index b57c2b08..2032b8be 100755 --- a/packages/insights-cli/bin/insights +++ b/packages/insights-cli/bin/insights @@ -7,11 +7,10 @@ var pkg = require(path.join(root, 'package.json')) program.version(pkg.version) .usage(' [options]') - .description('Run insights dekstop app, server or helper commands') + .description('Run insights server or helper commands') program - .command('desktop', 'run the desktop/electron app [default]', { isDefault: true }) - .command('server', 'run as a server') + .command('start', 'run as a server') .command('createsecret', 'create a new authentication secret') .command('createsuperuser', 'create a new admin user') diff --git a/old-packages/insights-server/bin/insights-createsecret b/packages/insights-cli/bin/insights-createsecret similarity index 71% rename from old-packages/insights-server/bin/insights-createsecret rename to packages/insights-cli/bin/insights-createsecret index 800dc514..9d35bf59 100755 --- a/old-packages/insights-server/bin/insights-createsecret +++ b/packages/insights-cli/bin/insights-createsecret @@ -5,7 +5,7 @@ var path = require('path') var program = require('commander') var root = path.join(__dirname, '..') var pkg = require(path.join(root, 'package.json')) -var randomString = require('insights-core/src/lib/random-string') +var randomString = require('../lib/random-string') program.version(pkg.version) .usage('[options]') @@ -15,6 +15,16 @@ program.version(pkg.version) const secretPath = program.secret || path.join(require('os').homedir(), '.insights', 'secret') +let folder = secretPath.split(path.sep) +folder.pop() +const folderPath = folder.join(path.sep) +try { + fs.mkdirSync(folderPath, { recursive: true }) +} catch (error) { + console.error(`Fatal Error! Could not create folder ${folderPath}`) + process.exit(1) +} + try { fs.writeFileSync(secretPath, randomString(64), 'utf8') console.log(`New authentication secret stored at ${secretPath}`) diff --git a/old-packages/insights-server/bin/insights-createsuperuser b/packages/insights-cli/bin/insights-createsuperuser similarity index 94% rename from old-packages/insights-server/bin/insights-createsuperuser rename to packages/insights-cli/bin/insights-createsuperuser index c8ce31e4..ba0b7218 100755 --- a/old-packages/insights-server/bin/insights-createsuperuser +++ b/packages/insights-cli/bin/insights-createsuperuser @@ -4,7 +4,7 @@ var path = require('path') var program = require('commander') var root = path.join(__dirname, '..') var pkg = require(path.join(root, 'package.json')) -var randomString = require('insights-core/src/lib/random-string') +var randomString = require('../lib/random-string') program.version(pkg.version) .usage('[options]') diff --git a/old-packages/insights-server/bin/insights-server b/packages/insights-cli/bin/insights-start similarity index 100% rename from old-packages/insights-server/bin/insights-server rename to packages/insights-cli/bin/insights-start diff --git a/packages/insights-cli/lib/random-string.js b/packages/insights-cli/lib/random-string.js new file mode 100644 index 00000000..d0794c6a --- /dev/null +++ b/packages/insights-cli/lib/random-string.js @@ -0,0 +1,9 @@ +let az09 = 'abcdefghijklmnopqrstuvwxyz0123456789' + +module.exports = function randomString (len, charset = az09) { + let text = '' + for (let i = 0; i < len; i++) { + text += charset.charAt(Math.floor(Math.random() * charset.length)) + } + return text +} diff --git a/packages/insights-cli/package.json b/packages/insights-cli/package.json index bbe1cd7d..e8b2646c 100644 --- a/packages/insights-cli/package.json +++ b/packages/insights-cli/package.json @@ -16,6 +16,12 @@ "contributors": [], "repository": "mariusandra/insights", "bugs": {}, + "bin": { + "insights": "./bin/insights", + "insights-start": "./bin/insights-start", + "insights-createsecret": "./bin/insights-createsecret", + "insights-createsuperuser": "./bin/insights-createsuperuser" + }, "directories": { "lib": "app" }, @@ -24,9 +30,6 @@ "yarn": ">= 0.18.0" }, "scripts": {}, - "bin": { - "insights": "./bin/insights" - }, "files": [ "bin" ],