Skip to content

Commit c32aee9

Browse files
authored
Merge pull request #201 from pluginpal/fix/strapi-plugin-sitemap-cli-commando-fix
feat: fix cli commando for sitemap
2 parents e9d8c8d + e606992 commit c32aee9

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

.changeset/hip-moons-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@pluginpal/webtools-addon-sitemap": minor
3+
---
4+
5+
Fix strapi-plugin-sitemap cli commando

packages/addons/sitemap/server/cli.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,41 @@
22

33
const { Command } = require('commander');
44
const chalk = require('chalk');
5+
const fs = require('fs');
56
const strapi = require('@strapi/strapi'); // eslint-disable-line
67

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

910
const program = new Command();
1011

12+
const getStrapiApp = async () => {
13+
try {
14+
const tsUtils = require('@strapi/typescript-utils'); // eslint-disable-line
15+
16+
const appDir = process.cwd();
17+
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
18+
const outDir = await tsUtils.resolveOutDir(appDir);
19+
const alreadyCompiled = await fs.existsSync(outDir);
20+
21+
if (isTSProject && !alreadyCompiled) {
22+
await tsUtils.compile(appDir, {
23+
watch: false,
24+
configOptions: { options: { incremental: true } },
25+
});
26+
}
27+
28+
const distDir = isTSProject ? outDir : appDir;
29+
30+
const app = await strapi({ appDir, distDir }).load();
31+
32+
return app;
33+
} catch (e) {
34+
// Fallback for pre Strapi 4.2.
35+
const app = await strapi().load();
36+
return app;
37+
}
38+
};
39+
1140
// Initial program setup
1241
program.storeOptionsAsProperties(false).allowUnknownOption(true);
1342

@@ -29,7 +58,7 @@ program
2958
.command('generate')
3059
.description('Generate the sitemap XML')
3160
.action(async () => {
32-
const app = await strapi().load();
61+
const app = await getStrapiApp();
3362

3463
try {
3564
app.plugin('sitemap').service('core').createSitemap();

0 commit comments

Comments
 (0)