@rockcarver/frodo-cli 2.0.0-37 → 2.0.0-39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/esm/cli/_template/something-else-export.js +1 -1
- package/esm/cli/_template/something-else-export.js.map +1 -1
- package/esm/cli/_template/something-export.js +1 -1
- package/esm/cli/_template/something-export.js.map +1 -1
- package/esm/cli/_template/something-other-export.js +1 -1
- package/esm/cli/_template/something-other-export.js.map +1 -1
- package/esm/cli/admin/admin-federation-export.js +4 -4
- package/esm/cli/admin/admin-federation-export.js.map +1 -1
- package/esm/cli/agent/agent-export.js +4 -4
- package/esm/cli/agent/agent-export.js.map +1 -1
- package/esm/cli/agent/agent-gateway-export.js +4 -4
- package/esm/cli/agent/agent-gateway-export.js.map +1 -1
- package/esm/cli/agent/agent-java-export.js +4 -4
- package/esm/cli/agent/agent-java-export.js.map +1 -1
- package/esm/cli/agent/agent-web-export.js +4 -4
- package/esm/cli/agent/agent-web-export.js.map +1 -1
- package/esm/cli/app/app-export.js +4 -4
- package/esm/cli/app/app-export.js.map +1 -1
- package/esm/cli/authn/authn-export.js +2 -2
- package/esm/cli/authn/authn-export.js.map +1 -1
- package/esm/cli/authz/authz-policy-export.js +6 -6
- package/esm/cli/authz/authz-policy-export.js.map +1 -1
- package/esm/cli/authz/authz-set-export.js +4 -4
- package/esm/cli/authz/authz-set-export.js.map +1 -1
- package/esm/cli/authz/authz-type-export.js +5 -5
- package/esm/cli/authz/authz-type-export.js.map +1 -1
- package/esm/cli/config/config-export.js +3 -3
- package/esm/cli/config/config-export.js.map +1 -1
- package/esm/cli/email/email-template-export.js +4 -4
- package/esm/cli/email/email-template-export.js.map +1 -1
- package/esm/cli/esv/esv-secret-export.js +4 -4
- package/esm/cli/esv/esv-secret-export.js.map +1 -1
- package/esm/cli/esv/esv-secret-list.js +2 -2
- package/esm/cli/esv/esv-secret-list.js.map +1 -1
- package/esm/cli/esv/esv-variable-export.js +4 -4
- package/esm/cli/esv/esv-variable-export.js.map +1 -1
- package/esm/cli/esv/esv-variable-list.js +2 -2
- package/esm/cli/esv/esv-variable-list.js.map +1 -1
- package/esm/cli/idp/idp-export.js +4 -4
- package/esm/cli/idp/idp-export.js.map +1 -1
- package/esm/cli/journey/journey-describe.js +3 -1
- package/esm/cli/journey/journey-describe.js.map +1 -1
- package/esm/cli/journey/journey-export.js +4 -4
- package/esm/cli/journey/journey-export.js.map +1 -1
- package/esm/cli/oauth/oauth-client-export.js +4 -4
- package/esm/cli/oauth/oauth-client-export.js.map +1 -1
- package/esm/cli/saml/saml-cot-export.js +4 -4
- package/esm/cli/saml/saml-cot-export.js.map +1 -1
- package/esm/cli/saml/saml-export.js +4 -4
- package/esm/cli/saml/saml-export.js.map +1 -1
- package/esm/cli/script/script-export.js +4 -4
- package/esm/cli/script/script-export.js.map +1 -1
- package/esm/cli/script/script-list.js +2 -2
- package/esm/cli/script/script-list.js.map +1 -1
- package/esm/cli/service/service-export.js +4 -4
- package/esm/cli/service/service-export.js.map +1 -1
- package/esm/cli/theme/theme-export.js +5 -5
- package/esm/cli/theme/theme-export.js.map +1 -1
- package/esm/ops/AdminFederationOps.js +11 -7
- package/esm/ops/AdminFederationOps.js.map +1 -1
- package/esm/ops/AgentOps.js +39 -25
- package/esm/ops/AgentOps.js.map +1 -1
- package/esm/ops/ApplicationOps.js +11 -8
- package/esm/ops/ApplicationOps.js.map +1 -1
- package/esm/ops/AuthenticationSettingsOps.js +4 -3
- package/esm/ops/AuthenticationSettingsOps.js.map +1 -1
- package/esm/ops/CirclesOfTrustOps.js +12 -7
- package/esm/ops/CirclesOfTrustOps.js.map +1 -1
- package/esm/ops/ConfigOps.js +9 -7
- package/esm/ops/ConfigOps.js.map +1 -1
- package/esm/ops/EmailTemplateOps.js +11 -7
- package/esm/ops/EmailTemplateOps.js.map +1 -1
- package/esm/ops/IdmOps.js +3 -2
- package/esm/ops/IdmOps.js.map +1 -1
- package/esm/ops/IdpOps.js +14 -7
- package/esm/ops/IdpOps.js.map +1 -1
- package/esm/ops/JourneyOps.js +15 -6
- package/esm/ops/JourneyOps.js.map +1 -1
- package/esm/ops/OAuth2ClientOps.js +10 -7
- package/esm/ops/OAuth2ClientOps.js.map +1 -1
- package/esm/ops/PolicyOps.js +18 -11
- package/esm/ops/PolicyOps.js.map +1 -1
- package/esm/ops/PolicySetOps.js +12 -7
- package/esm/ops/PolicySetOps.js.map +1 -1
- package/esm/ops/ResourceTypeOps.js +15 -9
- package/esm/ops/ResourceTypeOps.js.map +1 -1
- package/esm/ops/Saml2Ops.js +10 -7
- package/esm/ops/Saml2Ops.js.map +1 -1
- package/esm/ops/ScriptOps.js +73 -36
- package/esm/ops/ScriptOps.js.map +1 -1
- package/esm/ops/SecretsOps.js +76 -48
- package/esm/ops/SecretsOps.js.map +1 -1
- package/esm/ops/ServiceOps.js +10 -9
- package/esm/ops/ServiceOps.js.map +1 -1
- package/esm/ops/ThemeOps.js +15 -9
- package/esm/ops/ThemeOps.js.map +1 -1
- package/esm/ops/VariablesOps.js +49 -23
- package/esm/ops/VariablesOps.js.map +1 -1
- package/esm/utils/Config.js +147 -1
- package/esm/utils/Config.js.map +1 -1
- package/package.json +2 -2
- package/esm/utils/ExportImportUtils.js +0 -48
- package/esm/utils/ExportImportUtils.js.map +0 -1
package/esm/ops/ServiceOps.js
CHANGED
|
@@ -2,9 +2,7 @@ import { frodo, state } from '@rockcarver/frodo-lib';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { createTable, debugMessage, failSpinner, printMessage, showSpinner, succeedSpinner } from '../utils/Console';
|
|
4
4
|
const {
|
|
5
|
-
getRealmName
|
|
6
|
-
} = frodo.utils;
|
|
7
|
-
const {
|
|
5
|
+
getRealmName,
|
|
8
6
|
getTypedFilename,
|
|
9
7
|
titleCase,
|
|
10
8
|
saveJsonToFile,
|
|
@@ -50,34 +48,37 @@ export async function listServices(long = false, globalConfig = false) {
|
|
|
50
48
|
/**
|
|
51
49
|
* Export all services to file
|
|
52
50
|
* @param {string} file file name
|
|
51
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
53
52
|
*/
|
|
54
|
-
export async function exportServicesToFile(file, globalConfig = false) {
|
|
53
|
+
export async function exportServicesToFile(file, globalConfig = false, includeMeta = true) {
|
|
55
54
|
const exportData = await exportServices(globalConfig);
|
|
56
55
|
let fileName = getTypedFilename(`all${globalConfig ? 'Global' : titleCase(getRealmName(state.getRealm()))}Services`, `service`);
|
|
57
56
|
if (file) {
|
|
58
57
|
fileName = file;
|
|
59
58
|
}
|
|
60
|
-
saveJsonToFile(exportData, getFilePath(fileName, true));
|
|
59
|
+
saveJsonToFile(exportData, getFilePath(fileName, true), includeMeta);
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
/**
|
|
64
63
|
* Export service to file
|
|
65
64
|
* @param {string} serviceId service id
|
|
66
65
|
* @param {string} file file name
|
|
66
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
67
67
|
*/
|
|
68
|
-
export async function exportServiceToFile(serviceId, file, globalConfig = false) {
|
|
68
|
+
export async function exportServiceToFile(serviceId, file, globalConfig = false, includeMeta = true) {
|
|
69
69
|
const exportData = await exportService(serviceId, globalConfig);
|
|
70
70
|
let fileName = getTypedFilename(serviceId, `service`);
|
|
71
71
|
if (file) {
|
|
72
72
|
fileName = file;
|
|
73
73
|
}
|
|
74
|
-
saveJsonToFile(exportData, getFilePath(fileName, true));
|
|
74
|
+
saveJsonToFile(exportData, getFilePath(fileName, true), includeMeta);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Export all services to separate files
|
|
79
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
79
80
|
*/
|
|
80
|
-
export async function exportServicesToFiles(globalConfig = false) {
|
|
81
|
+
export async function exportServicesToFiles(globalConfig = false, includeMeta = true) {
|
|
81
82
|
debugMessage(`cli.ServiceOps.exportServicesToFiles: start`);
|
|
82
83
|
const services = await getFullServices(globalConfig);
|
|
83
84
|
for (const service of services) {
|
|
@@ -86,7 +87,7 @@ export async function exportServicesToFiles(globalConfig = false) {
|
|
|
86
87
|
const exportData = createServiceExportTemplate();
|
|
87
88
|
exportData.service[service._type._id] = service;
|
|
88
89
|
debugMessage(`cli.ServiceOps.exportServicesToFiles: exporting ${service._type._id} to ${filePath}`);
|
|
89
|
-
saveJsonToFile(exportData, filePath);
|
|
90
|
+
saveJsonToFile(exportData, filePath, includeMeta);
|
|
90
91
|
}
|
|
91
92
|
debugMessage(`cli.ServiceOps.exportServicesToFiles: end.`);
|
|
92
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceOps.js","names":["frodo","state","fs","createTable","debugMessage","failSpinner","printMessage","showSpinner","succeedSpinner","getRealmName","utils","getTypedFilename","titleCase","saveJsonToFile","getFilePath","getWorkingDirectory","getListOfServices","exportServices","exportService","getFullServices","createServiceExportTemplate","importService","importServices","deleteFullService","deleteFullServices","service","listServices","long","globalConfig","services","sort","a","b","_id","localeCompare","table","push","name","toString","error","stack","exportServicesToFile","file","exportData","fileName","getRealm","exportServiceToFile","serviceId","exportServicesToFiles","_type","filePath","importServiceFromFile","clean","verbose","getVerbose","readFile","err","data","importData","JSON","parse","importError","_importError$response","_importError$response2","message","response","detail","importFirstServiceFromFile","Object","keys","length","_importError$response3","_importError$response4","importServicesFromFile","status","importServicesFromFiles","names","readdirSync","agentFiles","filter","toLowerCase","endsWith","map","deleteService","_error$response","deleteServices"],"sources":["../../src/ops/ServiceOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type ServiceExportInterface } from '@rockcarver/frodo-lib/types/ops/ServiceOps';\nimport fs from 'fs';\n\nimport {\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n succeedSpinner,\n} from '../utils/Console';\n\nconst { getRealmName } = frodo.utils;\nconst {\n getTypedFilename,\n titleCase,\n saveJsonToFile,\n getFilePath,\n getWorkingDirectory,\n} = frodo.utils;\nconst {\n getListOfServices,\n exportServices,\n exportService,\n getFullServices,\n createServiceExportTemplate,\n importService,\n importServices,\n deleteFullService,\n deleteFullServices,\n} = frodo.service;\n\n/**\n * List services\n */\nexport async function listServices(long = false, globalConfig = false) {\n try {\n const services = await getListOfServices(globalConfig);\n services.sort((a, b) => a._id.localeCompare(b._id));\n if (long) {\n const table = createTable(['Service Id', 'Service Name']);\n for (const service of services) {\n table.push([\n service._id,\n globalConfig ? service['_type'].name : service.name,\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n for (const service of services) {\n printMessage(`${service._id}`, 'data');\n }\n }\n } catch (error) {\n printMessage(`Error listing agents - ${error}`, 'error');\n printMessage(error.stack, 'error');\n }\n}\n\n/**\n * Export all services to file\n * @param {string} file file name\n */\nexport async function exportServicesToFile(file, globalConfig = false) {\n const exportData = await exportServices(globalConfig);\n let fileName = getTypedFilename(\n `all${\n globalConfig ? 'Global' : titleCase(getRealmName(state.getRealm()))\n }Services`,\n `service`\n );\n if (file) {\n fileName = file;\n }\n saveJsonToFile(exportData, getFilePath(fileName, true));\n}\n\n/**\n * Export service to file\n * @param {string} serviceId service id\n * @param {string} file file name\n */\nexport async function exportServiceToFile(\n serviceId: string,\n file: string,\n globalConfig = false\n) {\n const exportData = await exportService(serviceId, globalConfig);\n let fileName = getTypedFilename(serviceId, `service`);\n if (file) {\n fileName = file;\n }\n saveJsonToFile(exportData, getFilePath(fileName, true));\n}\n\n/**\n * Export all services to separate files\n */\nexport async function exportServicesToFiles(globalConfig = false) {\n debugMessage(`cli.ServiceOps.exportServicesToFiles: start`);\n const services = await getFullServices(globalConfig);\n for (const service of services) {\n const fileName = getTypedFilename(service._type._id, `service`);\n const filePath = getFilePath(fileName, true);\n const exportData = createServiceExportTemplate();\n exportData.service[service._type._id] = service;\n debugMessage(\n `cli.ServiceOps.exportServicesToFiles: exporting ${service._type._id} to ${filePath}`\n );\n saveJsonToFile(exportData, filePath);\n }\n debugMessage(`cli.ServiceOps.exportServicesToFiles: end.`);\n}\n\n/**\n * Import a service from file\n * @param {string} serviceId service id/name\n * @param {string} file import file name\n * @param {boolean} clean remove existing service\n */\nexport async function importServiceFromFile(\n serviceId: string,\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n const filePath = getFilePath(file);\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: start [serviceId=${serviceId}, file=${filePath}]`\n );\n const verbose = state.getVerbose();\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n const importData = JSON.parse(data);\n if (importData && importData.service[serviceId]) {\n if (!verbose) showSpinner(`Importing ${serviceId}...`);\n try {\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n await importService(serviceId, importData, clean, globalConfig);\n succeedSpinner(`Imported ${serviceId}.`);\n } catch (importError) {\n const message = importError.response?.data?.message;\n const detail = importError.response?.data?.detail;\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${detail ? message + ' - ' + detail : message}`);\n }\n } else {\n showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${serviceId} not found!`);\n }\n });\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: end [serviceId=${serviceId}, file=${filePath}]`\n );\n}\n\n/**\n * Import first service from file\n * @param {string} file import file name\n * @param {boolean} clean remove existing service\n */\nexport async function importFirstServiceFromFile(\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n const filePath = getFilePath(file);\n debugMessage(\n `cli.ServiceOps.importFirstServiceFromFile: start [file=${filePath}]`\n );\n const verbose = state.getVerbose();\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n const importData = JSON.parse(data);\n if (importData && Object.keys(importData.service).length) {\n const serviceId = Object.keys(importData.service)[0];\n if (!verbose) showSpinner(`Importing ${serviceId}...`);\n try {\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n await importService(serviceId, importData, clean, globalConfig);\n succeedSpinner(`Imported ${serviceId}.`);\n } catch (importError) {\n const message = importError.response?.data?.message;\n const detail = importError.response?.data?.detail;\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${detail ? message + ' - ' + detail : message}`);\n }\n } else {\n showSpinner(`Importing service...`);\n failSpinner(`No service found in ${filePath}!`);\n }\n debugMessage(\n `cli.ServiceOps.importFirstServiceFromFile: end [file=${filePath}]`\n );\n });\n}\n\n/**\n * Import services from file\n * @param {String} file file name\n * @param {boolean} clean remove existing service\n */\nexport async function importServicesFromFile(\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n const filePath = getFilePath(file);\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: start [file=${filePath}]`\n );\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n debugMessage(`cli.ServiceOps.importServiceFromFile: importing ${filePath}`);\n const importData = JSON.parse(data) as ServiceExportInterface;\n try {\n await importServices(importData, clean, globalConfig);\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n printMessage(error.response.status, 'error');\n }\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: end [file=${filePath}]`\n );\n });\n}\n\n/**\n * Import all services from separate files\n * @param {boolean} clean remove existing service\n */\nexport async function importServicesFromFiles(\n clean: boolean,\n globalConfig = false\n) {\n debugMessage(`cli.ServiceOps.importServicesFromFiles: start`);\n const names = fs.readdirSync(getWorkingDirectory());\n const agentFiles = names\n .filter((name) => name.toLowerCase().endsWith('.service.json'))\n .map((name) => getFilePath(name));\n for (const file of agentFiles) {\n await importServicesFromFile(file, clean, globalConfig);\n }\n debugMessage(`cli.ServiceOps.importServicesFromFiles: end`);\n}\n\n/**\n * Delete a service by id/name\n * @param {string} serviceId Reference to the service to delete\n */\nexport async function deleteService(serviceId: string, globalConfig = false) {\n try {\n await deleteFullService(serviceId, globalConfig);\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage(`Delete service '${serviceId}': ${message}`, 'error');\n }\n}\n\n/**\n * Delete all services\n */\nexport async function deleteServices(globalConfig = false) {\n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mB,CAAC,CAAC,CAAC;EACnD,MAAM+D,UAAU,GAAGF,KAAK,CACrBG,MAAM,CAAE1C,IAAI,IAAKA,IAAI,CAAC2C,WAAW,CAAC,CAAC,CAACC,QAAQ,CAAC,eAAe,CAAC,CAAC,CAC9DC,GAAG,CAAE7C,IAAI,IAAKvB,WAAW,CAACuB,IAAI,CAAC,CAAC;EACnC,KAAK,MAAMK,IAAI,IAAIoC,UAAU,EAAE;IAC7B,MAAML,sBAAsB,CAAC/B,IAAI,EAAEU,KAAK,EAAExB,YAAY,CAAC;EACzD;EACAxB,YAAY,CAAE,6CAA4C,CAAC;AAC7D;;AAEA;AACA;AACA;AACA;AACA,OAAO,eAAe+E,aAAaA,CAACpC,SAAiB,EAAEnB,YAAY,GAAG,KAAK,EAAE;EAC3E,IAAI;IACF,MAAML,iBAAiB,CAACwB,SAAS,EAAEnB,YAAY,CAAC;EAClD,CAAC,CAAC,OAAOW,KAAK,EAAE;IAAA,IAAA6C,eAAA;IACd,MAAMpB,OAAO,IAAAoB,eAAA,GAAG7C,KAAK,CAAC0B,QAAQ,cAAAmB,eAAA,gBAAAA,eAAA,GAAdA,eAAA,CAAgB3B,IAAI,cAAA2B,eAAA,uBAApBA,eAAA,CAAsBpB,OAAO;IAC7C1D,YAAY,CAAE,mBAAkByC,SAAU,MAAKiB,OAAQ,EAAC,EAAE,OAAO,CAAC;EACpE;AACF;;AAEA;AACA;AACA;AACA,OAAO,eAAeqB,cAAcA,CAACzD,YAAY,GAAG,KAAK,EAAE;EACzD,MAAMJ,kBAAkB,CAACI,YAAY,CAAC;AACxC"}
|
|
1
|
+
{"version":3,"file":"ServiceOps.js","names":["frodo","state","fs","createTable","debugMessage","failSpinner","printMessage","showSpinner","succeedSpinner","getRealmName","getTypedFilename","titleCase","saveJsonToFile","getFilePath","getWorkingDirectory","utils","getListOfServices","exportServices","exportService","getFullServices","createServiceExportTemplate","importService","importServices","deleteFullService","deleteFullServices","service","listServices","long","globalConfig","services","sort","a","b","_id","localeCompare","table","push","name","toString","error","stack","exportServicesToFile","file","includeMeta","exportData","fileName","getRealm","exportServiceToFile","serviceId","exportServicesToFiles","_type","filePath","importServiceFromFile","clean","verbose","getVerbose","readFile","err","data","importData","JSON","parse","importError","_importError$response","_importError$response2","message","response","detail","importFirstServiceFromFile","Object","keys","length","_importError$response3","_importError$response4","importServicesFromFile","status","importServicesFromFiles","names","readdirSync","agentFiles","filter","toLowerCase","endsWith","map","deleteService","_error$response","deleteServices"],"sources":["../../src/ops/ServiceOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type ServiceExportInterface } from '@rockcarver/frodo-lib/types/ops/ServiceOps';\nimport fs from 'fs';\n\nimport {\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n succeedSpinner,\n} from '../utils/Console';\n\nconst {\n getRealmName,\n getTypedFilename,\n titleCase,\n saveJsonToFile,\n getFilePath,\n getWorkingDirectory,\n} = frodo.utils;\nconst {\n getListOfServices,\n exportServices,\n exportService,\n getFullServices,\n createServiceExportTemplate,\n importService,\n importServices,\n deleteFullService,\n deleteFullServices,\n} = frodo.service;\n\n/**\n * List services\n */\nexport async function listServices(long = false, globalConfig = false) {\n try {\n const services = await getListOfServices(globalConfig);\n services.sort((a, b) => a._id.localeCompare(b._id));\n if (long) {\n const table = createTable(['Service Id', 'Service Name']);\n for (const service of services) {\n table.push([\n service._id,\n globalConfig ? service['_type'].name : service.name,\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n for (const service of services) {\n printMessage(`${service._id}`, 'data');\n }\n }\n } catch (error) {\n printMessage(`Error listing agents - ${error}`, 'error');\n printMessage(error.stack, 'error');\n }\n}\n\n/**\n * Export all services to file\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n */\nexport async function exportServicesToFile(\n file,\n globalConfig = false,\n includeMeta = true\n) {\n const exportData = await exportServices(globalConfig);\n let fileName = getTypedFilename(\n `all${\n globalConfig ? 'Global' : titleCase(getRealmName(state.getRealm()))\n }Services`,\n `service`\n );\n if (file) {\n fileName = file;\n }\n saveJsonToFile(exportData, getFilePath(fileName, true), includeMeta);\n}\n\n/**\n * Export service to file\n * @param {string} serviceId service id\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n */\nexport async function exportServiceToFile(\n serviceId: string,\n file: string,\n globalConfig = false,\n includeMeta = true\n) {\n const exportData = await exportService(serviceId, globalConfig);\n let fileName = getTypedFilename(serviceId, `service`);\n if (file) {\n fileName = file;\n }\n saveJsonToFile(exportData, getFilePath(fileName, true), includeMeta);\n}\n\n/**\n * Export all services to separate files\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n */\nexport async function exportServicesToFiles(\n globalConfig = false,\n includeMeta = true\n) {\n debugMessage(`cli.ServiceOps.exportServicesToFiles: start`);\n const services = await getFullServices(globalConfig);\n for (const service of services) {\n const fileName = getTypedFilename(service._type._id, `service`);\n const filePath = getFilePath(fileName, true);\n const exportData = createServiceExportTemplate();\n exportData.service[service._type._id] = service;\n debugMessage(\n `cli.ServiceOps.exportServicesToFiles: exporting ${service._type._id} to ${filePath}`\n );\n saveJsonToFile(exportData, filePath, includeMeta);\n }\n debugMessage(`cli.ServiceOps.exportServicesToFiles: end.`);\n}\n\n/**\n * Import a service from file\n * @param {string} serviceId service id/name\n * @param {string} file import file name\n * @param {boolean} clean remove existing service\n */\nexport async function importServiceFromFile(\n serviceId: string,\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n const filePath = getFilePath(file);\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: start [serviceId=${serviceId}, file=${filePath}]`\n );\n const verbose = state.getVerbose();\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n const importData = JSON.parse(data);\n if (importData && importData.service[serviceId]) {\n if (!verbose) showSpinner(`Importing ${serviceId}...`);\n try {\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n await importService(serviceId, importData, clean, globalConfig);\n succeedSpinner(`Imported ${serviceId}.`);\n } catch (importError) {\n const message = importError.response?.data?.message;\n const detail = importError.response?.data?.detail;\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${detail ? message + ' - ' + detail : message}`);\n }\n } else {\n showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${serviceId} not found!`);\n }\n });\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: end [serviceId=${serviceId}, file=${filePath}]`\n );\n}\n\n/**\n * Import first service from file\n * @param {string} file import file name\n * @param {boolean} clean remove existing service\n */\nexport async function importFirstServiceFromFile(\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n const filePath = getFilePath(file);\n debugMessage(\n `cli.ServiceOps.importFirstServiceFromFile: start [file=${filePath}]`\n );\n const verbose = state.getVerbose();\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n const importData = JSON.parse(data);\n if (importData && Object.keys(importData.service).length) {\n const serviceId = Object.keys(importData.service)[0];\n if (!verbose) showSpinner(`Importing ${serviceId}...`);\n try {\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n await importService(serviceId, importData, clean, globalConfig);\n succeedSpinner(`Imported ${serviceId}.`);\n } catch (importError) {\n const message = importError.response?.data?.message;\n const detail = importError.response?.data?.detail;\n if (verbose) showSpinner(`Importing ${serviceId}...`);\n failSpinner(`${detail ? message + ' - ' + detail : message}`);\n }\n } else {\n showSpinner(`Importing service...`);\n failSpinner(`No service found in ${filePath}!`);\n }\n debugMessage(\n `cli.ServiceOps.importFirstServiceFromFile: end [file=${filePath}]`\n );\n });\n}\n\n/**\n * Import services from file\n * @param {String} file file name\n * @param {boolean} clean remove existing service\n */\nexport async function importServicesFromFile(\n file: string,\n clean: boolean,\n globalConfig = false\n) {\n const filePath = getFilePath(file);\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: start [file=${filePath}]`\n );\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n debugMessage(`cli.ServiceOps.importServiceFromFile: importing ${filePath}`);\n const importData = JSON.parse(data) as ServiceExportInterface;\n try {\n await importServices(importData, clean, globalConfig);\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n printMessage(error.response.status, 'error');\n }\n debugMessage(\n `cli.ServiceOps.importServiceFromFile: end [file=${filePath}]`\n );\n });\n}\n\n/**\n * Import all services from separate files\n * @param {boolean} clean remove existing service\n */\nexport async function importServicesFromFiles(\n clean: boolean,\n globalConfig = false\n) {\n debugMessage(`cli.ServiceOps.importServicesFromFiles: start`);\n const names = fs.readdirSync(getWorkingDirectory());\n const agentFiles = names\n .filter((name) => name.toLowerCase().endsWith('.service.json'))\n .map((name) => getFilePath(name));\n for (const file of agentFiles) {\n await importServicesFromFile(file, clean, globalConfig);\n }\n debugMessage(`cli.ServiceOps.importServicesFromFiles: end`);\n}\n\n/**\n * Delete a service by id/name\n * @param {string} serviceId Reference to the service to delete\n */\nexport async function deleteService(serviceId: string, globalConfig = false) {\n try {\n await deleteFullService(serviceId, globalConfig);\n } catch (error) {\n const message = error.response?.data?.message;\n printMessage(`Delete service '${serviceId}': ${message}`, 'error');\n }\n}\n\n/**\n * Delete all services\n */\nexport async function deleteServices(globalConfig = false) {\n await deleteFullServices(globalConfig);\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAEpD,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,cAAc,QACT,kBAAkB;AAEzB,MAAM;EACJC,YAAY;EACZC,gBAAgB;EAChBC,SAAS;EACTC,cAAc;EACdC,WAAW;EACXC;AACF,CAAC,GAAGd,KAAK,CAACe,KAAK;AACf,MAAM;EACJC,iBAAiB;EACjBC,cAAc;EACdC,aAAa;EACbC,eAAe;EACfC,2BAA2B;EAC3BC,aAAa;EACbC,cAAc;EACdC,iBAAiB;EACjBC;AACF,CAAC,GAAGxB,KAAK,CAACyB,OAAO;;AAEjB;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,OAAO,eAAegF,aAAaA,CAACpC,SAAiB,EAAEpB,YAAY,GAAG,KAAK,EAAE;EAC3E,IAAI;IACF,MAAML,iBAAiB,CAACyB,SAAS,EAAEpB,YAAY,CAAC;EAClD,CAAC,CAAC,OAAOW,KAAK,EAAE;IAAA,IAAA8C,eAAA;IACd,MAAMpB,OAAO,IAAAoB,eAAA,GAAG9C,KAAK,CAAC2B,QAAQ,cAAAmB,eAAA,gBAAAA,eAAA,GAAdA,eAAA,CAAgB3B,IAAI,cAAA2B,eAAA,uBAApBA,eAAA,CAAsBpB,OAAO;IAC7C3D,YAAY,CAAE,mBAAkB0C,SAAU,MAAKiB,OAAQ,EAAC,EAAE,OAAO,CAAC;EACpE;AACF;;AAEA;AACA;AACA;AACA,OAAO,eAAeqB,cAAcA,CAAC1D,YAAY,GAAG,KAAK,EAAE;EACzD,MAAMJ,kBAAkB,CAACI,YAAY,CAAC;AACxC"}
|
package/esm/ops/ThemeOps.js
CHANGED
|
@@ -2,10 +2,12 @@ import { frodo } from '@rockcarver/frodo-lib';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
4
4
|
import { createProgressIndicator, createTable, printMessage, stopProgressIndicator, updateProgressIndicator } from '../utils/Console';
|
|
5
|
-
import { getTypedFilename, saveJsonToFile, saveToFile } from '../utils/ExportImportUtils';
|
|
6
5
|
const {
|
|
7
6
|
getRealmString,
|
|
8
7
|
validateImport,
|
|
8
|
+
getTypedFilename,
|
|
9
|
+
saveJsonToFile,
|
|
10
|
+
saveToFile,
|
|
9
11
|
getFilePath,
|
|
10
12
|
getWorkingDirectory
|
|
11
13
|
} = frodo.utils;
|
|
@@ -77,8 +79,9 @@ export async function listThemes(long = false) {
|
|
|
77
79
|
* Export theme by name to file
|
|
78
80
|
* @param {String} name theme name
|
|
79
81
|
* @param {String} file optional export file name
|
|
82
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
80
83
|
*/
|
|
81
|
-
export async function exportThemeByName(name, file) {
|
|
84
|
+
export async function exportThemeByName(name, file, includeMeta = true) {
|
|
82
85
|
let fileName = getTypedFilename(name, 'theme');
|
|
83
86
|
if (file) {
|
|
84
87
|
fileName = file;
|
|
@@ -89,7 +92,7 @@ export async function exportThemeByName(name, file) {
|
|
|
89
92
|
const themeData = await readThemeByName(name);
|
|
90
93
|
if (!themeData._id) themeData._id = uuidv4();
|
|
91
94
|
updateProgressIndicator(indicatorId, `Writing file to ${filePath}`);
|
|
92
|
-
saveToFile('theme', [themeData], '_id', filePath);
|
|
95
|
+
saveToFile('theme', [themeData], '_id', filePath, includeMeta);
|
|
93
96
|
stopProgressIndicator(indicatorId, `Successfully exported theme ${name}.`);
|
|
94
97
|
} catch (error) {
|
|
95
98
|
stopProgressIndicator(indicatorId, `${error.message}`);
|
|
@@ -101,8 +104,9 @@ export async function exportThemeByName(name, file) {
|
|
|
101
104
|
* Export theme by uuid to file
|
|
102
105
|
* @param {String} id theme uuid
|
|
103
106
|
* @param {String} file optional export file name
|
|
107
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
104
108
|
*/
|
|
105
|
-
export async function exportThemeById(id, file) {
|
|
109
|
+
export async function exportThemeById(id, file, includeMeta = true) {
|
|
106
110
|
let fileName = getTypedFilename(id, 'theme');
|
|
107
111
|
if (file) {
|
|
108
112
|
fileName = file;
|
|
@@ -112,7 +116,7 @@ export async function exportThemeById(id, file) {
|
|
|
112
116
|
try {
|
|
113
117
|
const themeData = await readTheme(id);
|
|
114
118
|
updateProgressIndicator(indicatorId, `Writing file to ${filePath}`);
|
|
115
|
-
saveToFile('theme', [themeData], '_id', filePath);
|
|
119
|
+
saveToFile('theme', [themeData], '_id', filePath, includeMeta);
|
|
116
120
|
stopProgressIndicator(indicatorId, `Successfully exported theme ${id}.`);
|
|
117
121
|
} catch (error) {
|
|
118
122
|
stopProgressIndicator(indicatorId, `${error.message}`);
|
|
@@ -123,21 +127,23 @@ export async function exportThemeById(id, file) {
|
|
|
123
127
|
/**
|
|
124
128
|
* Export all themes to file
|
|
125
129
|
* @param {String} file optional export file name
|
|
130
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
126
131
|
*/
|
|
127
|
-
export async function exportThemesToFile(file) {
|
|
132
|
+
export async function exportThemesToFile(file, includeMeta = true) {
|
|
128
133
|
let fileName = getTypedFilename(`all${getRealmString()}Themes`, 'theme');
|
|
129
134
|
if (file) {
|
|
130
135
|
fileName = file;
|
|
131
136
|
}
|
|
132
137
|
const filePath = getFilePath(fileName, true);
|
|
133
138
|
const exportData = await exportThemes();
|
|
134
|
-
saveJsonToFile(exportData, filePath);
|
|
139
|
+
saveJsonToFile(exportData, filePath, includeMeta);
|
|
135
140
|
}
|
|
136
141
|
|
|
137
142
|
/**
|
|
138
143
|
* Export all themes to separate files
|
|
144
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
139
145
|
*/
|
|
140
|
-
export async function exportThemesToFiles() {
|
|
146
|
+
export async function exportThemesToFiles(includeMeta = true) {
|
|
141
147
|
const themes = await readThemes();
|
|
142
148
|
const barId = createProgressIndicator('determinate', themes.length, 'Exporting themes');
|
|
143
149
|
for (const theme of themes) {
|
|
@@ -145,7 +151,7 @@ export async function exportThemesToFiles() {
|
|
|
145
151
|
const fileBarId = createProgressIndicator('determinate', 1, `Exporting theme ${theme.name}...`);
|
|
146
152
|
updateProgressIndicator(barId, `Exporting theme ${theme.name}`);
|
|
147
153
|
const file = getFilePath(getTypedFilename(theme.name, 'theme'), true);
|
|
148
|
-
saveToFile('theme', theme, '_id', file);
|
|
154
|
+
saveToFile('theme', theme, '_id', file, includeMeta);
|
|
149
155
|
updateProgressIndicator(fileBarId, `${theme.name} saved to ${file}`);
|
|
150
156
|
stopProgressIndicator(fileBarId, `${theme.name} saved to ${file}.`);
|
|
151
157
|
}
|
package/esm/ops/ThemeOps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeOps.js","names":["frodo","fs","v4","uuidv4","createProgressIndicator","createTable","printMessage","stopProgressIndicator","updateProgressIndicator","getTypedFilename","saveJsonToFile","saveToFile","getRealmString","validateImport","getFilePath","getWorkingDirectory","utils","readThemes","readThemeByName","readTheme","updateThemeByName","updateTheme","updateThemes","exportThemes","deleteTheme","deleteThemeByName","deleteThemes","theme","getOneLineDescription","themeObj","description","_id","name","linkedTrees","join","getTableHeaderMd","markdown","getTableRowMd","row","listThemes","long","themeList","sort","a","b","localeCompare","forEach","isDefault","table","push","toString","exportThemeByName","file","fileName","filePath","indicatorId","themeData","error","message","exportThemeById","id","exportThemesToFile","exportData","exportThemesToFiles","themes","barId","length","fileBarId","importThemeByName","data","readFileSync","themeExport","JSON","parse","found","Object","keys","importThemeById","themeId","importThemesFromFile","result","importThemesFromFiles","names","readdirSync","jsonFiles","filter","toLowerCase","endsWith","map","fileData","count","total","files","meta","importFirstThemeFromFile","then","deleteThemeCmd","undefined","deleteThemeByNameCmd","deleteAllThemes","deleteThemesCmd"],"sources":["../../src/ops/ThemeOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport {\n ThemeExportInterface,\n type ThemeSkeleton,\n} from '@rockcarver/frodo-lib/types/ops/ThemeOps';\nimport fs from 'fs';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n createProgressIndicator,\n createTable,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\nimport {\n getTypedFilename,\n saveJsonToFile,\n saveToFile,\n} from '../utils/ExportImportUtils';\n\nconst { getRealmString, validateImport, getFilePath, getWorkingDirectory } =\n frodo.utils;\nconst {\n readThemes,\n readThemeByName,\n readTheme,\n updateThemeByName,\n updateTheme,\n updateThemes,\n exportThemes,\n deleteTheme,\n deleteThemeByName,\n deleteThemes,\n} = frodo.theme;\n\n/**\n * Get a one-line description of the theme\n * @param {ThemeSkeleton} themeObj theme object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(themeObj: ThemeSkeleton): string {\n const description = `[${themeObj._id['brightCyan']}] ${themeObj.name}${\n themeObj.linkedTrees\n ? ' (' + themeObj.linkedTrees.join(', ')['brightCyan'] + ')'\n : ''\n }`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Name | Linked Journey(s) | Id |\\n';\n markdown += '| ---- | ----------------- | ---|';\n return markdown;\n}\n\n/**\n * Get a table-row of the theme in markdown\n * @param {ThemeSkeleton} themeObj theme object to describe\n * @returns {string} a table-row of the theme in markdown\n */\nexport function getTableRowMd(themeObj: ThemeSkeleton): string {\n const row = `| ${themeObj.name} | ${\n themeObj.linkedTrees ? themeObj.linkedTrees.join(', ') : ''\n } | \\`${themeObj._id}\\` |`;\n return row;\n}\n\n/**\n * List all the themes\n * @param {boolean} long Long version, more fields\n */\nexport async function listThemes(long = false) {\n const themeList = await readThemes();\n themeList.sort((a, b) => a.name.localeCompare(b.name));\n if (!long) {\n themeList.forEach((theme) => {\n printMessage(\n `${theme.isDefault ? theme.name['brightCyan'] : theme.name}`,\n 'data'\n );\n });\n } else {\n const table = createTable([\n 'Name'['brightCyan'],\n 'Id'['brightCyan'],\n 'Default'['brightCyan'],\n ]);\n themeList.forEach((theme) => {\n table.push([\n `${theme.name}`,\n `${theme._id}`,\n `${theme.isDefault ? 'Yes'['brightGreen'] : ''}`,\n ]);\n });\n printMessage(table.toString(), 'data');\n }\n}\n\n/**\n * Export theme by name to file\n * @param {String} name theme name\n * @param {String} file optional export file name\n */\nexport async function exportThemeByName(name, file) {\n let fileName = getTypedFilename(name, 'theme');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${name}`\n );\n try {\n const themeData = await readThemeByName(name);\n if (!themeData._id) themeData._id = uuidv4();\n updateProgressIndicator(indicatorId, `Writing file to ${filePath}`);\n saveToFile('theme', [themeData], '_id', filePath);\n stopProgressIndicator(indicatorId, `Successfully exported theme ${name}.`);\n } catch (error) {\n stopProgressIndicator(indicatorId, `${error.message}`);\n printMessage(`${error.message}`, 'error');\n }\n}\n\n/**\n * Export theme by uuid to file\n * @param {String} id theme uuid\n * @param {String} file optional export file name\n */\nexport async function exportThemeById(id, file) {\n let fileName = getTypedFilename(id, 'theme');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${id}`\n );\n try {\n const themeData = await readTheme(id);\n updateProgressIndicator(indicatorId, `Writing file to ${filePath}`);\n saveToFile('theme', [themeData], '_id', filePath);\n stopProgressIndicator(indicatorId, `Successfully exported theme ${id}.`);\n } catch (error) {\n stopProgressIndicator(indicatorId, `${error.message}`);\n printMessage(`${error.message}`, 'error');\n }\n}\n\n/**\n * Export all themes to file\n * @param {String} file optional export file name\n */\nexport async function exportThemesToFile(file) {\n let fileName = getTypedFilename(`all${getRealmString()}Themes`, 'theme');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportThemes();\n saveJsonToFile(exportData, filePath);\n}\n\n/**\n * Export all themes to separate files\n */\nexport async function exportThemesToFiles() {\n const themes = await readThemes();\n const barId = createProgressIndicator(\n 'determinate',\n themes.length,\n 'Exporting themes'\n );\n for (const theme of themes) {\n if (!theme._id) theme._id = uuidv4();\n const fileBarId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting theme ${theme.name}...`\n );\n updateProgressIndicator(barId, `Exporting theme ${theme.name}`);\n const file = getFilePath(getTypedFilename(theme.name, 'theme'), true);\n saveToFile('theme', theme, '_id', file);\n updateProgressIndicator(fileBarId, `${theme.name} saved to ${file}`);\n stopProgressIndicator(fileBarId, `${theme.name} saved to ${file}.`);\n }\n stopProgressIndicator(barId, `${themes.length} themes exported.`);\n}\n\n/**\n * Import theme by name from file\n * @param {String} name theme name\n * @param {String} file import file name\n */\nexport async function importThemeByName(name, file) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const themeExport: ThemeExportInterface = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n 'Importing theme...'\n );\n let found = false;\n for (const id of Object.keys(themeExport.theme)) {\n if (themeExport.theme[id].name === name) {\n found = true;\n updateProgressIndicator(\n indicatorId,\n `Importing ${themeExport.theme[id].name}`\n );\n try {\n await updateThemeByName(name, themeExport.theme[id]);\n stopProgressIndicator(\n indicatorId,\n `Successfully imported theme ${name}.`\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing theme ${themeExport.theme[id].name}: ${error.message}`\n );\n printMessage(\n `Error importing theme ${themeExport.theme[id].name}: ${error.message}`,\n 'error'\n );\n }\n break;\n }\n }\n if (!found) {\n stopProgressIndicator(indicatorId, `Theme ${name} not found!`);\n }\n } catch (error) {\n printMessage(`Error importing theme ${name}: ${error}`, 'error');\n }\n}\n\n/**\n * Import theme by uuid from file\n * @param {String} id theme uuid\n * @param {String} file import file name\n */\nexport async function importThemeById(id, file) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const themeExport: ThemeExportInterface = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n 'Importing theme...'\n );\n let found = false;\n for (const themeId of Object.keys(themeExport.theme)) {\n if (themeId === id) {\n found = true;\n updateProgressIndicator(\n indicatorId,\n `Importing ${themeExport.theme[themeId]._id}`\n );\n try {\n await updateTheme(themeId, themeExport.theme[themeId]);\n stopProgressIndicator(\n indicatorId,\n `Successfully imported theme ${id}.`\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing theme ${themeExport.theme[themeId]._id}: ${error.message}`\n );\n printMessage(\n `Error importing theme ${themeExport.theme[themeId]._id}: ${error.message}`,\n 'error'\n );\n }\n break;\n }\n }\n if (!found) {\n stopProgressIndicator(indicatorId, `Theme ${id} not found!`);\n }\n } catch (error) {\n printMessage(`Error importing theme ${id}: ${error}`, 'error');\n }\n}\n\n/**\n * Import all themes from single file\n * @param {String} file import file name\n */\nexport async function importThemesFromFile(file) {\n const filePath = getFilePath(file);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const themeExport: ThemeExportInterface = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n Object.keys(themeExport.theme).length,\n 'Importing themes...'\n );\n for (const id of Object.keys(themeExport.theme)) {\n updateProgressIndicator(\n indicatorId,\n `Importing ${themeExport.theme[id].name}`\n );\n }\n const result = await updateThemes(themeExport.theme);\n if (result == null) {\n stopProgressIndicator(\n indicatorId,\n `Error importing ${Object.keys(themeExport.theme).length} themes!`\n );\n printMessage(\n `Error importing ${\n Object.keys(themeExport.theme).length\n } themes from ${filePath}`,\n 'error'\n );\n } else {\n stopProgressIndicator(\n indicatorId,\n `Successfully imported ${Object.keys(themeExport.theme).length} themes.`\n );\n }\n } catch (error) {\n printMessage(`Error importing themes: ${error}`, 'error');\n }\n}\n\n/**\n * Import themes from separate files\n */\nexport async function importThemesFromFiles() {\n const names = fs.readdirSync(getWorkingDirectory());\n const jsonFiles = names\n .filter((name) => name.toLowerCase().endsWith('.theme.json'))\n .map((name) => getFilePath(name));\n\n const indicatorId = createProgressIndicator(\n 'determinate',\n jsonFiles.length,\n 'Importing themes...'\n );\n let fileData = null;\n let count = 0;\n let total = 0;\n let files = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n count = Object.keys(fileData.theme).length;\n // eslint-disable-next-line no-await-in-loop\n const result = await updateThemes(fileData.theme);\n if (result == null) {\n printMessage(`Error importing ${count} themes from ${file}`, 'error');\n } else {\n files += 1;\n total += count;\n updateProgressIndicator(\n indicatorId,\n `Imported ${count} theme(s) from ${file}`\n );\n }\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\n `Finished importing ${total} theme(s) from ${files} file(s).`\n );\n}\n\n/**\n * Import first theme from file\n * @param {String} file import file name\n */\nexport async function importFirstThemeFromFile(file) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const themeExport = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n 'Importing theme...'\n );\n for (const id of Object.keys(themeExport.theme)) {\n updateProgressIndicator(\n indicatorId,\n `Importing ${themeExport.theme[id].name}`\n );\n updateTheme(id, themeExport.theme[id]).then((result) => {\n if (result == null) {\n stopProgressIndicator(\n indicatorId,\n `Error importing theme ${themeExport.theme[id].name}`\n );\n printMessage(\n `Error importing theme ${themeExport.theme[id].name}`,\n 'error'\n );\n } else {\n stopProgressIndicator(\n indicatorId,\n `Successfully imported theme ${themeExport.theme[id].name}`\n );\n }\n });\n break;\n }\n } catch (error) {\n printMessage(`Error importing themes: ${error}`, 'error');\n }\n}\n\n/**\n * Delete theme by id\n * @param {String} id theme id\n */\nexport async function deleteThemeCmd(id) {\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n undefined,\n `Deleting ${id}...`\n );\n try {\n await deleteTheme(id);\n stopProgressIndicator(indicatorId, `Deleted ${id}.`, 'success');\n } catch (error) {\n stopProgressIndicator(indicatorId, `Error: ${error.message}`, 'fail');\n }\n}\n\n/**\n * Delete theme by name\n * @param {String} name theme name\n */\nexport async function deleteThemeByNameCmd(name) {\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n undefined,\n `Deleting ${name}...`\n );\n try {\n await deleteThemeByName(name);\n stopProgressIndicator(indicatorId, `Deleted ${name}.`, 'success');\n } catch (error) {\n stopProgressIndicator(indicatorId, `Error: ${error.message}`, 'fail');\n }\n}\n\n/**\n * Delete all themes\n */\nexport async function deleteAllThemes() {\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n undefined,\n `Deleting all realm themes...`\n );\n try {\n await deleteThemes();\n stopProgressIndicator(indicatorId, `Deleted all realm themes.`, 'success');\n } catch (error) {\n stopProgressIndicator(indicatorId, `Error: ${error.message}`, 'fail');\n }\n}\n\n/**\n * Delete all themes\n * @deprecated since version 0.14.0\n */\nexport async function deleteThemesCmd() {\n return deleteAllThemes();\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAK7C,OAAOC,EAAE,MAAM,IAAI;AACnB,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AAEnC,SACEC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AACzB,SACEC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,QACL,4BAA4B;AAEnC,MAAM;EAAEC,cAAc;EAAEC,cAAc;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GACxEf,KAAK,CAACgB,KAAK;AACb,MAAM;EACJC,UAAU;EACVC,eAAe;EACfC,SAAS;EACTC,iBAAiB;EACjBC,WAAW;EACXC,YAAY;EACZC,YAAY;EACZC,WAAW;EACXC,iBAAiB;EACjBC;AACF,CAAC,GAAG1B,KAAK,CAAC2B,KAAK;;AAEf;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAACC,QAAuB,EAAU;EACrE,MAAMC,WAAW,GAAI,IAAGD,QAAQ,CAACE,GAAG,CAAC,YAAY,CAAE,KAAIF,QAAQ,CAACG,IAAK,GACnEH,QAAQ,CAACI,WAAW,GAChB,IAAI,GAAGJ,QAAQ,CAACI,WAAW,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,GAAG,GAC1D,EACL,EAAC;EACF,OAAOJ,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASK,gBAAgBA,CAAA,EAAW;EACzC,IAAIC,QAAQ,GAAG,EAAE;EACjBA,QAAQ,IAAI,qCAAqC;EACjDA,QAAQ,IAAI,mCAAmC;EAC/C,OAAOA,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACR,QAAuB,EAAU;E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AI;IACF,MAAMpC,WAAW,CAACoC,EAAE,CAAC;IACrBrD,qBAAqB,CAACgD,WAAW,EAAG,WAAUK,EAAG,GAAE,EAAE,SAAS,CAAC;EACjE,CAAC,CAAC,OAAOH,KAAK,EAAE;IACdlD,qBAAqB,CAACgD,WAAW,EAAG,UAASE,KAAK,CAACC,OAAQ,EAAC,EAAE,MAAM,CAAC;EACvE;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,eAAewC,oBAAoBA,CAAClE,IAAI,EAAE;EAC/C,MAAMuB,WAAW,GAAGnD,uBAAuB,CACzC,eAAe,EACf6F,SAAS,EACR,YAAWjE,IAAK,KACnB,CAAC;EACD,IAAI;IACF,MAAMP,iBAAiB,CAACO,IAAI,CAAC;IAC7BzB,qBAAqB,CAACgD,WAAW,EAAG,WAAUvB,IAAK,GAAE,EAAE,SAAS,CAAC;EACnE,CAAC,CAAC,OAAOyB,KAAK,EAAE;IACdlD,qBAAqB,CAACgD,WAAW,EAAG,UAASE,KAAK,CAACC,OAAQ,EAAC,EAAE,MAAM,CAAC;EACvE;AACF;;AAEA;AACA;AACA;AACA,OAAO,eAAeyC,eAAeA,CAAA,EAAG;EACtC,MAAM5C,WAAW,GAAGnD,uBAAuB,CACzC,eAAe,EACf6F,SAAS,EACR,8BACH,CAAC;EACD,IAAI;IACF,MAAMvE,YAAY,CAAC,CAAC;IACpBnB,qBAAqB,CAACgD,WAAW,EAAG,2BAA0B,EAAE,SAAS,CAAC;EAC5E,CAAC,CAAC,OAAOE,KAAK,EAAE;IACdlD,qBAAqB,CAACgD,WAAW,EAAG,UAASE,KAAK,CAACC,OAAQ,EAAC,EAAE,MAAM,CAAC;EACvE;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,eAAe0C,eAAeA,CAAA,EAAG;EACtC,OAAOD,eAAe,CAAC,CAAC;AAC1B"}
|
|
1
|
+
{"version":3,"file":"ThemeOps.js","names":["frodo","fs","v4","uuidv4","createProgressIndicator","createTable","printMessage","stopProgressIndicator","updateProgressIndicator","getRealmString","validateImport","getTypedFilename","saveJsonToFile","saveToFile","getFilePath","getWorkingDirectory","utils","readThemes","readThemeByName","readTheme","updateThemeByName","updateTheme","updateThemes","exportThemes","deleteTheme","deleteThemeByName","deleteThemes","theme","getOneLineDescription","themeObj","description","_id","name","linkedTrees","join","getTableHeaderMd","markdown","getTableRowMd","row","listThemes","long","themeList","sort","a","b","localeCompare","forEach","isDefault","table","push","toString","exportThemeByName","file","includeMeta","fileName","filePath","indicatorId","themeData","error","message","exportThemeById","id","exportThemesToFile","exportData","exportThemesToFiles","themes","barId","length","fileBarId","importThemeByName","data","readFileSync","themeExport","JSON","parse","found","Object","keys","importThemeById","themeId","importThemesFromFile","result","importThemesFromFiles","names","readdirSync","jsonFiles","filter","toLowerCase","endsWith","map","fileData","count","total","files","meta","importFirstThemeFromFile","then","deleteThemeCmd","undefined","deleteThemeByNameCmd","deleteAllThemes","deleteThemesCmd"],"sources":["../../src/ops/ThemeOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport {\n ThemeExportInterface,\n type ThemeSkeleton,\n} from '@rockcarver/frodo-lib/types/ops/ThemeOps';\nimport fs from 'fs';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n createProgressIndicator,\n createTable,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\n\nconst {\n getRealmString,\n validateImport,\n getTypedFilename,\n saveJsonToFile,\n saveToFile,\n getFilePath,\n getWorkingDirectory,\n} = frodo.utils;\nconst {\n readThemes,\n readThemeByName,\n readTheme,\n updateThemeByName,\n updateTheme,\n updateThemes,\n exportThemes,\n deleteTheme,\n deleteThemeByName,\n deleteThemes,\n} = frodo.theme;\n\n/**\n * Get a one-line description of the theme\n * @param {ThemeSkeleton} themeObj theme object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(themeObj: ThemeSkeleton): string {\n const description = `[${themeObj._id['brightCyan']}] ${themeObj.name}${\n themeObj.linkedTrees\n ? ' (' + themeObj.linkedTrees.join(', ')['brightCyan'] + ')'\n : ''\n }`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Name | Linked Journey(s) | Id |\\n';\n markdown += '| ---- | ----------------- | ---|';\n return markdown;\n}\n\n/**\n * Get a table-row of the theme in markdown\n * @param {ThemeSkeleton} themeObj theme object to describe\n * @returns {string} a table-row of the theme in markdown\n */\nexport function getTableRowMd(themeObj: ThemeSkeleton): string {\n const row = `| ${themeObj.name} | ${\n themeObj.linkedTrees ? themeObj.linkedTrees.join(', ') : ''\n } | \\`${themeObj._id}\\` |`;\n return row;\n}\n\n/**\n * List all the themes\n * @param {boolean} long Long version, more fields\n */\nexport async function listThemes(long = false) {\n const themeList = await readThemes();\n themeList.sort((a, b) => a.name.localeCompare(b.name));\n if (!long) {\n themeList.forEach((theme) => {\n printMessage(\n `${theme.isDefault ? theme.name['brightCyan'] : theme.name}`,\n 'data'\n );\n });\n } else {\n const table = createTable([\n 'Name'['brightCyan'],\n 'Id'['brightCyan'],\n 'Default'['brightCyan'],\n ]);\n themeList.forEach((theme) => {\n table.push([\n `${theme.name}`,\n `${theme._id}`,\n `${theme.isDefault ? 'Yes'['brightGreen'] : ''}`,\n ]);\n });\n printMessage(table.toString(), 'data');\n }\n}\n\n/**\n * Export theme by name to file\n * @param {String} name theme name\n * @param {String} file optional export file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n */\nexport async function exportThemeByName(name, file, includeMeta = true) {\n let fileName = getTypedFilename(name, 'theme');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${name}`\n );\n try {\n const themeData = await readThemeByName(name);\n if (!themeData._id) themeData._id = uuidv4();\n updateProgressIndicator(indicatorId, `Writing file to ${filePath}`);\n saveToFile('theme', [themeData], '_id', filePath, includeMeta);\n stopProgressIndicator(indicatorId, `Successfully exported theme ${name}.`);\n } catch (error) {\n stopProgressIndicator(indicatorId, `${error.message}`);\n printMessage(`${error.message}`, 'error');\n }\n}\n\n/**\n * Export theme by uuid to file\n * @param {String} id theme uuid\n * @param {String} file optional export file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n */\nexport async function exportThemeById(id, file, includeMeta = true) {\n let fileName = getTypedFilename(id, 'theme');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${id}`\n );\n try {\n const themeData = await readTheme(id);\n updateProgressIndicator(indicatorId, `Writing file to ${filePath}`);\n saveToFile('theme', [themeData], '_id', filePath, includeMeta);\n stopProgressIndicator(indicatorId, `Successfully exported theme ${id}.`);\n } catch (error) {\n stopProgressIndicator(indicatorId, `${error.message}`);\n printMessage(`${error.message}`, 'error');\n }\n}\n\n/**\n * Export all themes to file\n * @param {String} file optional export file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n */\nexport async function exportThemesToFile(file, includeMeta = true) {\n let fileName = getTypedFilename(`all${getRealmString()}Themes`, 'theme');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportThemes();\n saveJsonToFile(exportData, filePath, includeMeta);\n}\n\n/**\n * Export all themes to separate files\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n */\nexport async function exportThemesToFiles(includeMeta = true) {\n const themes = await readThemes();\n const barId = createProgressIndicator(\n 'determinate',\n themes.length,\n 'Exporting themes'\n );\n for (const theme of themes) {\n if (!theme._id) theme._id = uuidv4();\n const fileBarId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting theme ${theme.name}...`\n );\n updateProgressIndicator(barId, `Exporting theme ${theme.name}`);\n const file = getFilePath(getTypedFilename(theme.name, 'theme'), true);\n saveToFile('theme', theme, '_id', file, includeMeta);\n updateProgressIndicator(fileBarId, `${theme.name} saved to ${file}`);\n stopProgressIndicator(fileBarId, `${theme.name} saved to ${file}.`);\n }\n stopProgressIndicator(barId, `${themes.length} themes exported.`);\n}\n\n/**\n * Import theme by name from file\n * @param {String} name theme name\n * @param {String} file import file name\n */\nexport async function importThemeByName(name, file) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const themeExport: ThemeExportInterface = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n 'Importing theme...'\n );\n let found = false;\n for (const id of Object.keys(themeExport.theme)) {\n if (themeExport.theme[id].name === name) {\n found = true;\n updateProgressIndicator(\n indicatorId,\n `Importing ${themeExport.theme[id].name}`\n );\n try {\n await updateThemeByName(name, themeExport.theme[id]);\n stopProgressIndicator(\n indicatorId,\n `Successfully imported theme ${name}.`\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing theme ${themeExport.theme[id].name}: ${error.message}`\n );\n printMessage(\n `Error importing theme ${themeExport.theme[id].name}: ${error.message}`,\n 'error'\n );\n }\n break;\n }\n }\n if (!found) {\n stopProgressIndicator(indicatorId, `Theme ${name} not found!`);\n }\n } catch (error) {\n printMessage(`Error importing theme ${name}: ${error}`, 'error');\n }\n}\n\n/**\n * Import theme by uuid from file\n * @param {String} id theme uuid\n * @param {String} file import file name\n */\nexport async function importThemeById(id, file) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const themeExport: ThemeExportInterface = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n 'Importing theme...'\n );\n let found = false;\n for (const themeId of Object.keys(themeExport.theme)) {\n if (themeId === id) {\n found = true;\n updateProgressIndicator(\n indicatorId,\n `Importing ${themeExport.theme[themeId]._id}`\n );\n try {\n await updateTheme(themeId, themeExport.theme[themeId]);\n stopProgressIndicator(\n indicatorId,\n `Successfully imported theme ${id}.`\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing theme ${themeExport.theme[themeId]._id}: ${error.message}`\n );\n printMessage(\n `Error importing theme ${themeExport.theme[themeId]._id}: ${error.message}`,\n 'error'\n );\n }\n break;\n }\n }\n if (!found) {\n stopProgressIndicator(indicatorId, `Theme ${id} not found!`);\n }\n } catch (error) {\n printMessage(`Error importing theme ${id}: ${error}`, 'error');\n }\n}\n\n/**\n * Import all themes from single file\n * @param {String} file import file name\n */\nexport async function importThemesFromFile(file) {\n const filePath = getFilePath(file);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const themeExport: ThemeExportInterface = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n Object.keys(themeExport.theme).length,\n 'Importing themes...'\n );\n for (const id of Object.keys(themeExport.theme)) {\n updateProgressIndicator(\n indicatorId,\n `Importing ${themeExport.theme[id].name}`\n );\n }\n const result = await updateThemes(themeExport.theme);\n if (result == null) {\n stopProgressIndicator(\n indicatorId,\n `Error importing ${Object.keys(themeExport.theme).length} themes!`\n );\n printMessage(\n `Error importing ${\n Object.keys(themeExport.theme).length\n } themes from ${filePath}`,\n 'error'\n );\n } else {\n stopProgressIndicator(\n indicatorId,\n `Successfully imported ${Object.keys(themeExport.theme).length} themes.`\n );\n }\n } catch (error) {\n printMessage(`Error importing themes: ${error}`, 'error');\n }\n}\n\n/**\n * Import themes from separate files\n */\nexport async function importThemesFromFiles() {\n const names = fs.readdirSync(getWorkingDirectory());\n const jsonFiles = names\n .filter((name) => name.toLowerCase().endsWith('.theme.json'))\n .map((name) => getFilePath(name));\n\n const indicatorId = createProgressIndicator(\n 'determinate',\n jsonFiles.length,\n 'Importing themes...'\n );\n let fileData = null;\n let count = 0;\n let total = 0;\n let files = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n count = Object.keys(fileData.theme).length;\n // eslint-disable-next-line no-await-in-loop\n const result = await updateThemes(fileData.theme);\n if (result == null) {\n printMessage(`Error importing ${count} themes from ${file}`, 'error');\n } else {\n files += 1;\n total += count;\n updateProgressIndicator(\n indicatorId,\n `Imported ${count} theme(s) from ${file}`\n );\n }\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\n `Finished importing ${total} theme(s) from ${files} file(s).`\n );\n}\n\n/**\n * Import first theme from file\n * @param {String} file import file name\n */\nexport async function importFirstThemeFromFile(file) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const themeExport = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n 'Importing theme...'\n );\n for (const id of Object.keys(themeExport.theme)) {\n updateProgressIndicator(\n indicatorId,\n `Importing ${themeExport.theme[id].name}`\n );\n updateTheme(id, themeExport.theme[id]).then((result) => {\n if (result == null) {\n stopProgressIndicator(\n indicatorId,\n `Error importing theme ${themeExport.theme[id].name}`\n );\n printMessage(\n `Error importing theme ${themeExport.theme[id].name}`,\n 'error'\n );\n } else {\n stopProgressIndicator(\n indicatorId,\n `Successfully imported theme ${themeExport.theme[id].name}`\n );\n }\n });\n break;\n }\n } catch (error) {\n printMessage(`Error importing themes: ${error}`, 'error');\n }\n}\n\n/**\n * Delete theme by id\n * @param {String} id theme id\n */\nexport async function deleteThemeCmd(id) {\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n undefined,\n `Deleting ${id}...`\n );\n try {\n await deleteTheme(id);\n stopProgressIndicator(indicatorId, `Deleted ${id}.`, 'success');\n } catch (error) {\n stopProgressIndicator(indicatorId, `Error: ${error.message}`, 'fail');\n }\n}\n\n/**\n * Delete theme by name\n * @param {String} name theme name\n */\nexport async function deleteThemeByNameCmd(name) {\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n undefined,\n `Deleting ${name}...`\n );\n try {\n await deleteThemeByName(name);\n stopProgressIndicator(indicatorId, `Deleted ${name}.`, 'success');\n } catch (error) {\n stopProgressIndicator(indicatorId, `Error: ${error.message}`, 'fail');\n }\n}\n\n/**\n * Delete all themes\n */\nexport async function deleteAllThemes() {\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n undefined,\n `Deleting all realm themes...`\n );\n try {\n await deleteThemes();\n stopProgressIndicator(indicatorId, `Deleted all realm themes.`, 'success');\n } catch (error) {\n stopProgressIndicator(indicatorId, `Error: ${error.message}`, 'fail');\n }\n}\n\n/**\n * Delete all themes\n * @deprecated since version 0.14.0\n */\nexport async function deleteThemesCmd() {\n return deleteAllThemes();\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAK7C,OAAOC,EAAE,MAAM,IAAI;AACnB,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AAEnC,SACEC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AAEzB,MAAM;EACJC,cAAc;EACdC,cAAc;EACdC,gBAAgB;EAChBC,cAAc;EACdC,UAAU;EACVC,WAAW;EACXC;AACF,CAAC,GAAGf,KAAK,CAACgB,KAAK;AACf,MAAM;EACJC,UAAU;EACVC,eAAe;EACfC,SAAS;EACTC,iBAAiB;EACjBC,WAAW;EACXC,YAAY;EACZC,YAAY;EACZC,WAAW;EACXC,iBAAiB;EACjBC;AACF,CAAC,GAAG1B,KAAK,CAAC2B,KAAK;;AAEf;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAACC,QAAuB,EAAU;EACrE,MAAMC,WAAW,GAAI,IAAGD,QAAQ,CAACE,GAAG,CAAC,YAAY,CAAE,KAAIF,QAAQ,CAACG,IAAK,GACnEH,QAAQ,CAACI,WAAW,GAChB,IAAI,GAAGJ,QAAQ,CAACI,WAAW,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,GAAG,GAC1D,EACL,EAAC;EACF,OAAOJ,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASK,gBAAgBA,CAAA,EAAW;EACzC,IAAIC,QAAQ,GAAG,EAAE;EACjBA,QAAQ,IAAI,qCAAqC;EACjDA,QAA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K,EAAE;IACdnD,qBAAqB,CAACiD,WAAW,EAAG,UAASE,KAAK,CAACC,OAAQ,EAAC,EAAE,MAAM,CAAC;EACvE;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,eAAe0C,eAAeA,CAAA,EAAG;EACtC,OAAOD,eAAe,CAAC,CAAC;AAC1B"}
|
package/esm/ops/VariablesOps.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { frodo, state } from '@rockcarver/frodo-lib';
|
|
2
|
+
import { getFullExportConfig, isIdUsed } from '../utils/Config';
|
|
2
3
|
import { createKeyValueTable, createProgressIndicator, createTable, debugMessage, printMessage, stopProgressIndicator, updateProgressIndicator } from '../utils/Console';
|
|
3
|
-
import { getTypedFilename, saveJsonToFile, saveToFile, titleCase } from '../utils/ExportImportUtils';
|
|
4
4
|
import wordwrap from './utils/Wordwrap';
|
|
5
5
|
const {
|
|
6
6
|
decodeBase64,
|
|
7
|
-
getFilePath
|
|
7
|
+
getFilePath,
|
|
8
|
+
getTypedFilename,
|
|
9
|
+
saveJsonToFile,
|
|
10
|
+
saveToFile,
|
|
11
|
+
titleCase
|
|
8
12
|
} = frodo.utils;
|
|
9
13
|
const {
|
|
10
14
|
resolvePerpetratorUuid
|
|
@@ -21,11 +25,12 @@ const {
|
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* List variables
|
|
24
|
-
* @param {boolean} long Long version, all the fields
|
|
28
|
+
* @param {boolean} long Long version, all the fields besides usage
|
|
29
|
+
* @param {boolean} usage Display usage field
|
|
30
|
+
* @param {String | null} file Optional filename to determine usage
|
|
25
31
|
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
26
32
|
*/
|
|
27
|
-
export async function listVariables(long) {
|
|
28
|
-
let outcome = false;
|
|
33
|
+
export async function listVariables(long = false, usage = false, file = null) {
|
|
29
34
|
let spinnerId;
|
|
30
35
|
let variables = [];
|
|
31
36
|
try {
|
|
@@ -36,21 +41,39 @@ export async function listVariables(long) {
|
|
|
36
41
|
} catch (error) {
|
|
37
42
|
var _error$response;
|
|
38
43
|
stopProgressIndicator(spinnerId, `Error reading variables: ${((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data) || error.message}`, 'fail');
|
|
44
|
+
return false;
|
|
39
45
|
}
|
|
40
|
-
if (long) {
|
|
41
|
-
const table = createTable(['Id'['brightCyan'], 'Value'['brightCyan'], 'Status'['brightCyan'], 'Description'['brightCyan'], 'Modifier'['brightCyan'], 'Modified (UTC)'['brightCyan']]);
|
|
42
|
-
for (const variable of variables) {
|
|
43
|
-
table.push([variable._id, wordwrap(decodeBase64(variable.valueBase64), 40), variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'], wordwrap(variable.description, 40), state.getUseBearerTokenForAmApis() ? variable.lastChangedBy : await resolvePerpetratorUuid(variable.lastChangedBy), new Date(variable.lastChangeDate).toUTCString()]);
|
|
44
|
-
}
|
|
45
|
-
printMessage(table.toString(), 'data');
|
|
46
|
-
outcome = true;
|
|
47
|
-
} else {
|
|
46
|
+
if (!long && !usage) {
|
|
48
47
|
variables.forEach(variable => {
|
|
49
48
|
printMessage(variable._id, 'data');
|
|
50
49
|
});
|
|
51
|
-
|
|
50
|
+
return true;
|
|
52
51
|
}
|
|
53
|
-
|
|
52
|
+
let fullExport = null;
|
|
53
|
+
const headers = long ? ['Id'['brightCyan'], 'Value'['brightCyan'], 'Status'['brightCyan'], 'Description'['brightCyan'], 'Modifier'['brightCyan'], 'Modified (UTC)'['brightCyan']] : ['Id'['brightCyan']];
|
|
54
|
+
if (usage) {
|
|
55
|
+
try {
|
|
56
|
+
fullExport = await getFullExportConfig(file);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
var _error$response2;
|
|
59
|
+
printMessage(`Error getting full export: ${((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data) || error.message}`, 'error');
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
//Delete variables from full export so they aren't mistakenly used for determining usage
|
|
63
|
+
delete fullExport.variables;
|
|
64
|
+
headers.push('Used'['brightCyan']);
|
|
65
|
+
}
|
|
66
|
+
const table = createTable(headers);
|
|
67
|
+
for (const variable of variables) {
|
|
68
|
+
const values = long ? [variable._id, wordwrap(decodeBase64(variable.valueBase64), 40), variable.loaded ? 'loaded'['brightGreen'] : 'unloaded'['brightRed'], wordwrap(variable.description, 40), state.getUseBearerTokenForAmApis() ? variable.lastChangedBy : await resolvePerpetratorUuid(variable.lastChangedBy), new Date(variable.lastChangeDate).toUTCString()] : [variable._id];
|
|
69
|
+
if (usage) {
|
|
70
|
+
const isEsvUsed = isIdUsed(fullExport, variable._id, true);
|
|
71
|
+
values.push(isEsvUsed.used ? `${'yes'['brightGreen']} (at ${isEsvUsed.location})` : 'no'['brightRed']);
|
|
72
|
+
}
|
|
73
|
+
table.push(values);
|
|
74
|
+
}
|
|
75
|
+
printMessage(table.toString(), 'data');
|
|
76
|
+
return true;
|
|
54
77
|
}
|
|
55
78
|
|
|
56
79
|
/**
|
|
@@ -203,9 +226,10 @@ export async function describeVariable(variableId, json = false) {
|
|
|
203
226
|
* @param {String} variableId Variable id
|
|
204
227
|
* @param {String} file Optional filename
|
|
205
228
|
* @param {boolean} noDecode Do not include decoded variable value in export
|
|
229
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
206
230
|
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
207
231
|
*/
|
|
208
|
-
export async function exportVariableToFile(variableId, file, noDecode) {
|
|
232
|
+
export async function exportVariableToFile(variableId, file, noDecode, includeMeta) {
|
|
209
233
|
debugMessage(`Cli.VariablesOps.exportVariableToFile: start [variableId=${variableId}, file=${file}]`);
|
|
210
234
|
let outcome = false;
|
|
211
235
|
let fileName = file;
|
|
@@ -217,7 +241,7 @@ export async function exportVariableToFile(variableId, file, noDecode) {
|
|
|
217
241
|
try {
|
|
218
242
|
indicatorId = createProgressIndicator('determinate', 1, `Exporting variable ${variableId}`);
|
|
219
243
|
const fileData = await exportVariable(variableId, noDecode);
|
|
220
|
-
saveJsonToFile(fileData, filePath);
|
|
244
|
+
saveJsonToFile(fileData, filePath, includeMeta);
|
|
221
245
|
updateProgressIndicator(indicatorId, `Exported variable ${variableId}`);
|
|
222
246
|
stopProgressIndicator(indicatorId,
|
|
223
247
|
// @ts-expect-error - brightCyan colors the string, even though it is not a property of string
|
|
@@ -235,9 +259,10 @@ export async function exportVariableToFile(variableId, file, noDecode) {
|
|
|
235
259
|
* Export all variables to single file
|
|
236
260
|
* @param {string} file Optional filename
|
|
237
261
|
* @param {boolean} noDecode Do not include decoded variable value in export
|
|
262
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
238
263
|
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
239
264
|
*/
|
|
240
|
-
export async function exportVariablesToFile(file, noDecode) {
|
|
265
|
+
export async function exportVariablesToFile(file, noDecode, includeMeta) {
|
|
241
266
|
debugMessage(`Cli.VariablesOps.exportVariablesToFile: start [file=${file}]`);
|
|
242
267
|
let outcome = false;
|
|
243
268
|
const spinnerId = createProgressIndicator('indeterminate', 0, `Exporting variables...`);
|
|
@@ -246,12 +271,12 @@ export async function exportVariablesToFile(file, noDecode) {
|
|
|
246
271
|
}
|
|
247
272
|
try {
|
|
248
273
|
const variablesExport = await exportVariables(noDecode);
|
|
249
|
-
saveJsonToFile(variablesExport, getFilePath(file, true));
|
|
274
|
+
saveJsonToFile(variablesExport, getFilePath(file, true), includeMeta);
|
|
250
275
|
stopProgressIndicator(spinnerId, `Exported variables to ${file}`, 'success');
|
|
251
276
|
outcome = true;
|
|
252
277
|
} catch (error) {
|
|
253
|
-
var _error$
|
|
254
|
-
stopProgressIndicator(spinnerId, `Error exporting variables: ${((_error$
|
|
278
|
+
var _error$response3;
|
|
279
|
+
stopProgressIndicator(spinnerId, `Error exporting variables: ${((_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.status) || error.message}`, 'fail');
|
|
255
280
|
}
|
|
256
281
|
debugMessage(`Cli.VariablesOps.exportVariablesToFile: end [outcome=${outcome}, file=${file}]`);
|
|
257
282
|
return outcome;
|
|
@@ -260,9 +285,10 @@ export async function exportVariablesToFile(file, noDecode) {
|
|
|
260
285
|
/**
|
|
261
286
|
* Export all variables to seperate files
|
|
262
287
|
* @param {boolean} noDecode Do not include decoded variable value in export
|
|
288
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
263
289
|
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
264
290
|
*/
|
|
265
|
-
export async function exportVariablesToFiles(noDecode) {
|
|
291
|
+
export async function exportVariablesToFiles(noDecode, includeMeta) {
|
|
266
292
|
let outcome = false;
|
|
267
293
|
let spinnerId;
|
|
268
294
|
let indicatorId;
|
|
@@ -282,7 +308,7 @@ export async function exportVariablesToFiles(noDecode) {
|
|
|
282
308
|
}
|
|
283
309
|
updateProgressIndicator(indicatorId, `Writing variable ${variable._id}`);
|
|
284
310
|
const fileName = getTypedFilename(variable._id, 'variable');
|
|
285
|
-
saveToFile('variable', variable, '_id', getFilePath(fileName, true));
|
|
311
|
+
saveToFile('variable', variable, '_id', getFilePath(fileName, true), includeMeta);
|
|
286
312
|
}
|
|
287
313
|
stopProgressIndicator(indicatorId, `${variableList.length} variables exported`);
|
|
288
314
|
outcome = true;
|