Skip to content

Commit fa640b1

Browse files
author
Tim Schipper
committed
feat: fix cli commando for sitemap
1 parent e9d8c8d commit fa640b1

File tree

1 file changed

+30
-1
lines changed
  • packages/addons/sitemap/server

1 file changed

+30
-1
lines changed

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)