Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix cli commando for sitemap #201

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading