2020-05-05 14:21:23 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const fs = require('fs');
|
2022-04-26 17:00:23 +03:00
|
|
|
const path = require('path');
|
|
|
|
const tsUtils = require('@strapi/typescript-utils');
|
2022-04-25 19:11:33 +03:00
|
|
|
const strapi = require('../index');
|
2022-04-26 17:00:23 +03:00
|
|
|
|
2020-05-06 18:49:36 +02:00
|
|
|
const CHUNK_SIZE = 100;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will dump configurations to a file or stdout
|
|
|
|
* @param {string} file filepath to use as output
|
|
|
|
*/
|
2022-04-26 17:00:23 +03:00
|
|
|
module.exports = async function({ file: filePath, pretty }) {
|
2020-05-12 12:47:23 +02:00
|
|
|
const output = filePath ? fs.createWriteStream(filePath) : process.stdout;
|
2020-05-05 14:21:23 +02:00
|
|
|
|
2022-04-25 19:11:33 +03:00
|
|
|
const appDir = process.cwd();
|
|
|
|
|
2022-04-26 17:00:23 +03:00
|
|
|
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
2022-04-29 14:52:45 +03:00
|
|
|
|
|
|
|
if (isTSProject) await tsUtils.compile(appDir, { watch: false });
|
|
|
|
|
2022-04-25 19:11:33 +03:00
|
|
|
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
|
|
|
|
|
|
|
const app = await strapi({ appDir, distDir }).load();
|
2020-05-05 14:21:23 +02:00
|
|
|
|
2021-06-22 17:13:11 +02:00
|
|
|
const count = await app.query('strapi::core-store').count();
|
2020-05-06 18:49:36 +02:00
|
|
|
|
|
|
|
const exportData = [];
|
2020-05-05 14:21:23 +02:00
|
|
|
|
2020-05-12 12:47:23 +02:00
|
|
|
const pageCount = Math.ceil(count / CHUNK_SIZE);
|
2020-05-05 14:21:23 +02:00
|
|
|
|
2020-05-06 18:49:36 +02:00
|
|
|
for (let page = 0; page < pageCount; page++) {
|
|
|
|
const results = await app
|
2021-06-22 17:13:11 +02:00
|
|
|
.query('strapi::core-store')
|
|
|
|
.findMany({ limit: CHUNK_SIZE, offset: page * CHUNK_SIZE, orderBy: 'key' });
|
2020-05-06 18:49:36 +02:00
|
|
|
|
|
|
|
results
|
|
|
|
.filter(result => result.key.startsWith('plugin_'))
|
|
|
|
.forEach(result => {
|
|
|
|
exportData.push({
|
|
|
|
key: result.key,
|
|
|
|
value: result.value,
|
|
|
|
type: result.type,
|
|
|
|
environment: result.environment,
|
|
|
|
tag: result.tag,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-14 15:50:43 +00:00
|
|
|
output.write(JSON.stringify(exportData, null, pretty ? 2 : null));
|
2020-05-05 14:21:23 +02:00
|
|
|
output.write('\n');
|
|
|
|
output.end();
|
2020-05-06 18:49:36 +02:00
|
|
|
|
|
|
|
// log success only when writting to file
|
2020-05-12 12:47:23 +02:00
|
|
|
if (filePath) {
|
2020-05-06 18:49:36 +02:00
|
|
|
console.log(`Successfully exported ${exportData.length} configuration entries`);
|
|
|
|
}
|
|
|
|
process.exit(0);
|
2020-05-05 14:21:23 +02:00
|
|
|
};
|