Skip to content

Commit

Permalink
Merge pull request #187 from pluginpal/feature/171-generate-cli-error
Browse files Browse the repository at this point in the history
feat: fix generate cli commando with getStrapiApp
  • Loading branch information
boazpoolman authored Oct 20, 2024
2 parents b2fc270 + 9e55b37 commit a37f91a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion admin/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {
const importedTrads = await Promise.all(
locales.map(async (locale) => {
try {
// eslint-disable-next-line import/no-dynamic-require
// eslint-disable-next-line import/no-dynamic-require, global-require
const data = require(`./translations/${locale}.json`);
return {
data: prefixPluginTranslations(data, pluginId),
Expand Down
32 changes: 31 additions & 1 deletion server/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,42 @@

const { Command } = require('commander');
const chalk = require('chalk');
const fs = require('fs');
const strapi = require('@strapi/strapi'); // eslint-disable-line

const packageJSON = require('../package.json');

const program = new Command();

const getStrapiApp = async () => {
try {
const tsUtils = require('@strapi/typescript-utils'); // eslint-disable-line

const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
const outDir = await tsUtils.resolveOutDir(appDir);
const alreadyCompiled = await fs.existsSync(outDir);

if (isTSProject && !alreadyCompiled) {
await tsUtils.compile(appDir, {
watch: false,
configOptions: { options: { incremental: true } },
});
}

const distDir = isTSProject ? outDir : appDir;

const app = await strapi({ appDir, distDir }).load();

return app;
} catch (e) {
// Fallback for pre Strapi 4.2.
const app = await strapi().load();
return app;
}
};


// Initial program setup
program.storeOptionsAsProperties(false).allowUnknownOption(true);

Expand All @@ -29,7 +59,7 @@ program
.command('generate')
.description('Generate the sitemap XML')
.action(async () => {
const app = await strapi().load();
const app = await getStrapiApp();

try {
app.plugin('sitemap').service('core').createSitemap();
Expand Down

0 comments on commit a37f91a

Please sign in to comment.