@cap-js-community/mtx-tool
Advanced tools
Comparing version 0.9.2 to 0.9.3
{ | ||
"name": "@cap-js-community/mtx-tool", | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"lockfileVersion": 3, | ||
@@ -9,3 +9,3 @@ "requires": true, | ||
"name": "@cap-js-community/mtx-tool", | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"license": "Apache-2.0", | ||
@@ -12,0 +12,0 @@ "dependencies": { |
{ | ||
"name": "@cap-js-community/mtx-tool", | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"description": "Multitenancy and Extensibility Tool is a cli to reduce operational overhead for multitenant Cloud Foundry applications", | ||
@@ -17,6 +17,4 @@ "bin": { | ||
"test": "jest", | ||
"test:coverage": "jest --coverageReporters=html", | ||
"test:coverage": "jest --runInBand --coverageReporters=html --coverageReporters=text-summary", | ||
"test:remove-inline-snapshots": "npx replace '\\.toMatchInlineSnapshot\\(\\s*`[\\s\\S]*?`\\s*\\);' '.toMatchInlineSnapshot();' test -r --include='*.test.js'", | ||
"test:record": "npm run test:record:reg && npm run test:record:cds && npm run test:record:hdi", | ||
"test:update": "jest --updateSnapshot", | ||
"test:record:reg": "jest --runInBand --config jest-nock-record.config.js test-nock-record/tenantRegistry.nock.test.js", | ||
@@ -23,0 +21,0 @@ "test:record:cds": "jest --runInBand --config jest-nock-record.config.js test-nock-record/capMultitenancy.nock.test.js", |
@@ -27,3 +27,3 @@ # MTX Tool | ||
# ad-hoc with fixed version, e.g. for stable pipelines | ||
npx @cap-js-community/mtx-tool@0.9.2 | ||
npx @cap-js-community/mtx-tool@0.9.3 | ||
``` | ||
@@ -30,0 +30,0 @@ |
@@ -5,6 +5,2 @@ "use strict"; | ||
const pathlib = require("path"); | ||
const { | ||
writeFileSync, | ||
constants: { R_OK }, | ||
} = require("fs"); | ||
const { version } = require("../package.json"); | ||
@@ -15,2 +11,3 @@ | ||
tryAccessSync, | ||
writeJsonSync, | ||
spawnAsync, | ||
@@ -138,3 +135,3 @@ safeUnshift, | ||
const filepath = dir + pathlib.sep + filename; | ||
if (tryAccessSync(filepath, R_OK)) { | ||
if (tryAccessSync(filepath)) { | ||
return { | ||
@@ -193,3 +190,3 @@ dir, | ||
try { | ||
writeFileSync(filepath, JSON.stringify(fullCache, null, 2) + "\n"); | ||
writeJsonSync(filepath, fullCache); | ||
} catch (err) { | ||
@@ -221,2 +218,3 @@ fail("caught error while writing app cache:", err.message); | ||
stdout && logger.info(stdout); | ||
return [stdout, stderr]; | ||
} catch (err) { | ||
@@ -223,0 +221,0 @@ return fail( |
@@ -6,3 +6,9 @@ "use strict"; | ||
const readline = require("readline"); | ||
const { accessSync, readFileSync } = require("fs"); | ||
const { | ||
accessSync, | ||
readFileSync, | ||
writeFileSync, | ||
unlinkSync, | ||
constants: { R_OK }, | ||
} = require("fs"); | ||
const net = require("net"); | ||
@@ -52,3 +58,3 @@ const childProcess = require("child_process"); | ||
const tryAccessSync = (filepath, mode) => { | ||
const tryAccessSync = (filepath, mode = R_OK) => { | ||
try { | ||
@@ -70,2 +76,8 @@ accessSync(filepath, mode); | ||
const writeTextSync = (filepath, data) => writeFileSync(filepath, data); | ||
const writeJsonSync = (filepath, data) => writeFileSync(filepath, JSON.stringify(data, null, 2) + "\n"); | ||
const deleteFileSync = (filepath) => unlinkSync(filepath); | ||
const tableList = (table, { sortCol = 0, noHeader = false, withRowNumber = true } = {}) => { | ||
@@ -377,2 +389,5 @@ if (!table || !table.length || !table[0] || !table[0].length) { | ||
tryReadJsonSync, | ||
writeTextSync, | ||
writeJsonSync, | ||
deleteFileSync, | ||
tryAccessSync, | ||
@@ -379,0 +394,0 @@ tryJsonParse, |
"use strict"; | ||
const { writeFileSync } = require("fs"); | ||
const { orderedStringify } = require("../shared/static"); | ||
const { orderedStringify, writeTextSync } = require("../shared/static"); | ||
const { assert } = require("../shared/error"); | ||
@@ -17,3 +16,3 @@ const { request } = require("../shared/request"); | ||
const _serverDebug = async (context, { appName, appInstance = 0 } = {}) => { | ||
const _serverDebug = async (context, { appName, appInstance } = {}) => { | ||
const { cfBuildpack, cfAppGuid, cfRouteUrl, cfSsh } = appName | ||
@@ -39,7 +38,5 @@ ? await context.getAppNameInfoCached(appName) | ||
auth: { token }, | ||
...(Number.isInteger(appInstance) && { | ||
headers: { | ||
"X-Cf-App-Instance": `${cfAppGuid}:${appInstance}`, | ||
}, | ||
}), | ||
headers: { | ||
"X-Cf-App-Instance": `${cfAppGuid}:${appInstance}`, | ||
}, | ||
logged: false, | ||
@@ -52,4 +49,3 @@ checkStatus: false, | ||
} | ||
const { instance, debugPort } = responseData; | ||
appInstance = instance || appInstance || 0; | ||
const { debugPort } = responseData; | ||
const remotePort = debugPort || inferredPort; | ||
@@ -67,6 +63,9 @@ assert(remotePort, `could not determine remote debugPort from /info or infer from buildpack`); | ||
logger.info(); | ||
return cfSsh({ localPort, remotePort, appInstance }); | ||
await cfSsh({ localPort, remotePort, appInstance }); | ||
}; | ||
const serverDebug = async (context, [appName, appInstance]) => _serverDebug(context, { appName, appInstance }); | ||
const serverDebug = async (context, [appName, appInstance = "0"]) => { | ||
assert(/\d+/.test(appInstance), `argument "${appInstance}" is not a valid app instance`); | ||
return _serverDebug(context, { appName, appInstance }); | ||
}; | ||
@@ -77,3 +76,3 @@ const serverEnvironment = async (context, [appName]) => { | ||
: await context.getSrvInfo(); | ||
writeFileSync( | ||
writeTextSync( | ||
DEFAULT_ENV_FILENAME, | ||
@@ -84,7 +83,8 @@ orderedStringify({ VCAP_SERVICES: cfEnvServices, VCAP_APPLICATION: cfEnvApp, ...cfEnvVariables }, null, 2) + "\n" | ||
}; | ||
const serverCertificates = async (context, [appName, appInstance = 0]) => { | ||
const serverCertificates = async (context, [appName, appInstance = "0"]) => { | ||
assert(/\d+/.test(appInstance), `argument "${appInstance}" is not a valid app instance`); | ||
const { cfSsh, cfAppName } = appName ? await context.getAppNameInfoCached(appName) : await context.getSrvInfo(); | ||
const dumpFile = async (cfFilename, localFilename) => { | ||
const [file] = await cfSsh({ command: `cat ${cfFilename}`, appInstance }); | ||
writeFileSync(localFilename, file); | ||
writeTextSync(localFilename, file); | ||
}; | ||
@@ -96,5 +96,6 @@ await dumpFile("$CF_INSTANCE_CERT", `certificate-${cfAppName}-${appInstance}.crt`); | ||
const serverStartDebugger = async (context, [appName, appInstance]) => { | ||
const serverStartDebugger = async (context, [appName, appInstance = "0"]) => { | ||
assert(/\d+/.test(appInstance), `argument "${appInstance}" is not a valid app instance`); | ||
const { cfSsh } = appName ? await context.getAppNameInfoCached(appName) : await context.getSrvInfo(); | ||
return cfSsh({ command: "pkill --signal SIGUSR1 node", appInstance }); | ||
await cfSsh({ command: "pkill --signal SIGUSR1 node", appInstance }); | ||
}; | ||
@@ -101,0 +102,0 @@ |
"use strict"; | ||
const pathlib = require("path"); | ||
const { | ||
writeFileSync, | ||
unlinkSync, | ||
constants: { R_OK }, | ||
} = require("fs"); | ||
const { question, tryAccessSync } = require("../shared/static"); | ||
const { question, tryAccessSync, writeJsonSync, deleteFileSync } = require("../shared/static"); | ||
const { fail } = require("../shared/error"); | ||
@@ -39,3 +34,3 @@ const { SETTING } = require("../setting"); | ||
const filepath = dir + pathlib.sep + filename; | ||
if (tryAccessSync(filepath, R_OK)) { | ||
if (tryAccessSync(filepath)) { | ||
return { | ||
@@ -56,3 +51,3 @@ dir, | ||
try { | ||
writeFileSync(filepath, JSON.stringify(runtimeConfig, null, 2) + "\n"); | ||
writeJsonSync(filepath, runtimeConfig); | ||
logger.info("wrote runtime config"); | ||
@@ -118,3 +113,3 @@ } catch (err) { | ||
try { | ||
unlinkSync(filepath); | ||
deleteFileSync(filepath); | ||
logger.info(`removed ${location.toLowerCase()} cache`, filepath); | ||
@@ -121,0 +116,0 @@ } catch (err) { |
137911
3383
15