diff --git a/cli/.gitignore b/cli/.gitignore index c2658d7d1..940d56a2d 100644 --- a/cli/.gitignore +++ b/cli/.gitignore @@ -1 +1,2 @@ node_modules/ +dist diff --git a/cli/.vscode/launch.json b/cli/.vscode/launch.json index 5f8af4725..8d6934e31 100644 --- a/cli/.vscode/launch.json +++ b/cli/.vscode/launch.json @@ -5,7 +5,7 @@ "version": "0.2.0", "configurations": [ { - "console": "externalTerminal", + "console": "integratedTerminal", "type": "pwa-node", "request": "launch", "name": "Launch Program", diff --git a/cli/dist/main.d.ts b/cli/dist/main.d.ts deleted file mode 100644 index 5d7cc144e..000000000 --- a/cli/dist/main.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node -export {}; -//# sourceMappingURL=main.d.ts.map \ No newline at end of file diff --git a/cli/dist/main.d.ts.map b/cli/dist/main.d.ts.map deleted file mode 100644 index 28b87d893..000000000 --- a/cli/dist/main.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/cli/dist/main.js b/cli/dist/main.js deleted file mode 100644 index 2b26f1bd2..000000000 --- a/cli/dist/main.js +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env node -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const tslib_1 = require("tslib"); -const fs_1 = (0, tslib_1.__importDefault)(require("fs")); -const path_1 = (0, tslib_1.__importDefault)(require("path")); -const axios_1 = (0, tslib_1.__importDefault)(require("axios")); -const readline_sync_1 = (0, tslib_1.__importDefault)(require("readline-sync")); -const https_1 = (0, tslib_1.__importDefault)(require("https")); -const mkdirp_1 = (0, tslib_1.__importDefault)(require("mkdirp")); -function getUserHome() { - const ret = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']; - if (!ret) - throw new Error('Neither USERPROFILE or HOME are defined.'); - return ret; -} -const axiosConfig = { - httpsAgent: new https_1.default.Agent({ - rejectUnauthorized: false - }) -}; -function main() { - return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { - if (process.argv[2] === 'install') { - const ip = process.argv[4] || '127.0.0.1'; - const pkg = process.argv[3]; - if (!pkg) { - console.log('usage: npx scrypted install npm-package-name [ip]'); - process.exit(1); - } - const scryptedHome = path_1.default.join(getUserHome(), '.scrypted'); - const loginPath = path_1.default.join(scryptedHome, 'login.json'); - let login; - try { - login = JSON.parse(fs_1.default.readFileSync(loginPath).toString()); - } - catch (e) { - const username = readline_sync_1.default.question('username: '); - const password = readline_sync_1.default.question('password: ', { - hideEchoBack: true, - }); - const url = `https://${ip}:9443/login`; - const authedConfig = Object.assign({ - method: 'GET', - auth: { - username, - password, - }, - url, - }, axiosConfig); - const response = yield (0, axios_1.default)(authedConfig); - mkdirp_1.default.sync(scryptedHome); - login = login || {}; - login[ip] = response.data; - fs_1.default.writeFileSync(loginPath, JSON.stringify(loginPath)); - } - const url = `https://${ip}:9443/web/component/script/install/${pkg}`; - const response = yield axios_1.default.post(url, undefined, axiosConfig); - console.log('install successful. id:', response.data.id); - } - else { - console.log('usage: npx scrypted install npm-package-name'); - process.exit(1); - } - }); -} -main(); -//# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/cli/dist/main.js.map b/cli/dist/main.js.map deleted file mode 100644 index 6cabe865f..000000000 --- a/cli/dist/main.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;AAEA,yDAAoB;AACpB,6DAAwB;AACxB,+DAAkD;AAElD,+EAAuD;AACvD,+DAA0B;AAC1B,iEAA4B;AAE5B,SAAS,WAAW;IAChB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAChF,IAAI,CAAC,GAAG;QACJ,MAAM,IAAI,KAAK,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,QAAQ;qBACX;oBACD,GAAG;iBACN,EAAE,WAAW,CAAC,CAAC;gBAChB,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAK,EAAC,YAAY,CAAC,CAAC;gBAE3C,gBAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBAC1B,KAAK,GAAG,KAAK,IAAI,EAAE,CAAC;gBACpB,KAAK,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC;gBAC1B,YAAE,CAAC,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;aAC1D;YAED,MAAM,GAAG,GAAG,WAAW,EAAE,sCAAsC,GAAG,EAAE,CAAC;YACrE,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;YAC/D,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SAC5D;aACK;YACD,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;YAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACnB;IACL,CAAC;CAAA;AAED,IAAI,EAAE,CAAC"} \ No newline at end of file diff --git a/cli/package-lock.json b/cli/package-lock.json index 956f5a7c8..cd4ce75c2 100644 --- a/cli/package-lock.json +++ b/cli/package-lock.json @@ -1,12 +1,12 @@ { "name": "scrypted", - "version": "1.0.13", + "version": "1.0.14", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "scrypted", - "version": "1.0.13", + "version": "1.0.14", "license": "ISC", "dependencies": { "@scrypted/sdk": "^0.0.79", diff --git a/cli/package.json b/cli/package.json index fa56196f7..54a4ea108 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "scrypted", - "version": "1.0.13", + "version": "1.0.14", "description": "", "main": "dist/main.js", "bin": { diff --git a/cli/src/main.ts b/cli/src/main.ts index 381e0af15..140e30fc6 100644 --- a/cli/src/main.ts +++ b/cli/src/main.ts @@ -33,13 +33,22 @@ async function main() { const scryptedHome = path.join(getUserHome(), '.scrypted'); const loginPath = path.join(scryptedHome, 'login.json'); + let username: string; + let password: string; let login: any; try { login = JSON.parse(fs.readFileSync(loginPath).toString()); + if (typeof login !== 'object') + login = {}; + + if (!login[ip].username || !login[ip].token) + throw new Error(); + username = login[ip].username; + password = login[ip].token; } catch (e) { - const username = readline.question('username: '); - const password = readline.question('password: ', { + username = readline.question('username: '); + password = readline.question('password: ', { hideEchoBack: true, }); @@ -57,11 +66,19 @@ async function main() { mkdirp.sync(scryptedHome); login = login || {}; login[ip] = response.data; - fs.writeFileSync(loginPath, JSON.stringify(loginPath)); + fs.writeFileSync(loginPath, JSON.stringify(login)); } const url = `https://${ip}:9443/web/component/script/install/${pkg}`; - const response = await axios.post(url, undefined, axiosConfig); + const response = await axios.post(url, undefined, Object.assign({ + method: 'GET', + auth: { + username: login[ip].username, + password: login[ip].token, + }, + url, + }, axiosConfig)); + console.log('install successful. id:',response.data.id); } else {