Skip to content

Commit

Permalink
Merge pull request #201 from pluginpal/fix/strapi-plugin-sitemap-cli-…
Browse files Browse the repository at this point in the history
…commando-fix

feat: fix cli commando for sitemap
  • Loading branch information
boazpoolman authored Oct 20, 2024
2 parents e9d8c8d + e606992 commit c32aee9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/hip-moons-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pluginpal/webtools-addon-sitemap": minor
---

Fix strapi-plugin-sitemap cli commando
31 changes: 30 additions & 1 deletion packages/addons/sitemap/server/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,41 @@

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 +58,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 c32aee9

Please sign in to comment.