UNPKG

@strapi/strapi

Version:

An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite

1 lines 4.79 kB
{"version":3,"file":"dump.mjs","sources":["../../../../../src/cli/commands/configuration/dump.ts"],"sourcesContent":["import fs from 'fs';\nimport { createCommand } from 'commander';\nimport { createStrapi, compileStrapi } from '@strapi/core';\n\nimport type { StrapiCommand } from '../../types';\nimport { runAction } from '../../utils/helpers';\n\ninterface CmdOptions {\n file?: string;\n pretty?: boolean;\n}\n\ninterface ExportItem {\n key: string;\n value: string;\n type: string;\n environment: string;\n tag: string;\n}\n\ninterface Output {\n write(str: string): void;\n end(): void;\n}\n\nconst CHUNK_SIZE = 100;\n\n/**\n * Will dump configurations to a file or stdout\n * @param {string} file filepath to use as output\n */\nconst action = async ({ file: filePath, pretty }: CmdOptions) => {\n const output: Output = filePath ? fs.createWriteStream(filePath) : process.stdout;\n\n const appContext = await compileStrapi();\n const app = await createStrapi(appContext).load();\n\n const count = await app.query('strapi::core-store').count();\n\n const exportData: ExportItem[] = [];\n\n const pageCount = Math.ceil(count / CHUNK_SIZE);\n\n for (let page = 0; page < pageCount; page += 1) {\n const results = await app\n .query('strapi::core-store')\n .findMany({ limit: CHUNK_SIZE, offset: page * CHUNK_SIZE, orderBy: 'key' });\n\n results\n .filter((result) => result.key.startsWith('plugin_'))\n .forEach((result) => {\n exportData.push({\n key: result.key,\n value: result.value,\n type: result.type,\n environment: result.environment,\n tag: result.tag,\n });\n });\n }\n\n const str = JSON.stringify(exportData, null, pretty ? 2 : undefined);\n\n output.write(str);\n output.write('\\n');\n output.end();\n\n // log success only when writting to file\n if (filePath) {\n console.log(`Successfully exported ${exportData.length} configuration entries`);\n }\n process.exit(0);\n};\n\n/**\n * `$ strapi configuration:dump`\n */\nconst command: StrapiCommand = () => {\n return createCommand('configuration:dump')\n .alias('config:dump')\n .description('Dump configurations of your application')\n .option('-f, --file <file>', 'Output file, default output is stdout')\n .option('-p, --pretty', 'Format the output JSON with indentation and line breaks', false)\n .action(runAction('configuration:dump', action));\n};\n\nexport { action, command };\n"],"names":["CHUNK_SIZE","action","file","filePath","pretty","output","fs","createWriteStream","process","stdout","appContext","compileStrapi","app","createStrapi","load","count","query","exportData","pageCount","Math","ceil","page","results","findMany","limit","offset","orderBy","filter","result","key","startsWith","forEach","push","value","type","environment","tag","str","JSON","stringify","undefined","write","end","console","log","length","exit","command","createCommand","alias","description","option","runAction"],"mappings":";;;;;AAyBA,MAAMA,UAAa,GAAA,GAAA;AAEnB;;;IAIA,MAAMC,SAAS,OAAO,EAAEC,MAAMC,QAAQ,EAAEC,MAAM,EAAc,GAAA;AAC1D,IAAA,MAAMC,SAAiBF,QAAWG,GAAAA,EAAAA,CAAGC,iBAAiB,CAACJ,QAAAA,CAAAA,GAAYK,QAAQC,MAAM;AAEjF,IAAA,MAAMC,aAAa,MAAMC,aAAAA,EAAAA;AACzB,IAAA,MAAMC,GAAM,GAAA,MAAMC,YAAaH,CAAAA,UAAAA,CAAAA,CAAYI,IAAI,EAAA;AAE/C,IAAA,MAAMC,QAAQ,MAAMH,GAAAA,CAAII,KAAK,CAAC,sBAAsBD,KAAK,EAAA;AAEzD,IAAA,MAAME,aAA2B,EAAE;AAEnC,IAAA,MAAMC,SAAYC,GAAAA,IAAAA,CAAKC,IAAI,CAACL,KAAQf,GAAAA,UAAAA,CAAAA;AAEpC,IAAA,IAAK,IAAIqB,IAAO,GAAA,CAAA,EAAGA,IAAOH,GAAAA,SAAAA,EAAWG,QAAQ,CAAG,CAAA;AAC9C,QAAA,MAAMC,UAAU,MAAMV,GAAAA,CACnBI,KAAK,CAAC,oBAAA,CAAA,CACNO,QAAQ,CAAC;YAAEC,KAAOxB,EAAAA,UAAAA;AAAYyB,YAAAA,MAAAA,EAAQJ,IAAOrB,GAAAA,UAAAA;YAAY0B,OAAS,EAAA;AAAM,SAAA,CAAA;AAE3EJ,QAAAA,OAAAA,CACGK,MAAM,CAAC,CA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